VideoSlider.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Video;
  5. using UnityEngine.UI;
  6. using UnityEngine.EventSystems;
  7. namespace SDK
  8. {
  9. public class VideoSlider : PointerHandler
  10. {
  11. public VideoPlayer vidoPlayer;
  12. public Slider slider;
  13. bool isDown = false;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. }
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. if (slider && vidoPlayer && isDown == false)
  22. {
  23. slider.value = float.Parse(vidoPlayer.frame.ToString()) / float.Parse(vidoPlayer.frameCount.ToString());
  24. }
  25. }
  26. void sliderChanged(float per)
  27. {
  28. if (slider && vidoPlayer)
  29. {
  30. float targetFrame = vidoPlayer.frameCount * per;
  31. vidoPlayer.frame = (long)targetFrame;
  32. }
  33. }
  34. public override void OnPointerDown(PointerEventData eventData)
  35. {
  36. base.OnPointerDown(eventData);
  37. isDown = true;
  38. }
  39. public override void OnPointerUp(PointerEventData eventData)
  40. {
  41. base.OnPointerUp(eventData);
  42. sliderChanged(slider.value);
  43. isDown = false;
  44. }
  45. }
  46. }