VideoSlider.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. public class VideoSlider : PointerHandler
  9. {
  10. public VideoPlayer vidoPlayer;
  11. public Slider slider;
  12. bool isDown = false;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. }
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. if (slider && vidoPlayer && isDown == false)
  21. {
  22. slider.value = float.Parse(vidoPlayer.frame.ToString()) / float.Parse(vidoPlayer.frameCount.ToString());
  23. }
  24. }
  25. void sliderChanged(float per)
  26. {
  27. if (slider && vidoPlayer)
  28. {
  29. float targetFrame = vidoPlayer.frameCount * per;
  30. vidoPlayer.frame = (long)targetFrame;
  31. }
  32. }
  33. public override void OnPointerDown(PointerEventData eventData)
  34. {
  35. base.OnPointerDown(eventData);
  36. isDown = true;
  37. }
  38. public override void OnPointerUp(PointerEventData eventData)
  39. {
  40. base.OnPointerUp(eventData);
  41. sliderChanged(slider.value);
  42. isDown = false;
  43. }
  44. }
  45. }