VideoSlider.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 NavigatorPro
  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. slider.value = float.Parse(vidoPlayer.frame.ToString()) / float.Parse(vidoPlayer.frameCount.ToString());
  23. }
  24. }
  25. void sliderChanged(float per) {
  26. if(slider && vidoPlayer) {
  27. float targetFrame = vidoPlayer.frameCount * per;
  28. vidoPlayer.frame = (long) targetFrame;
  29. }
  30. }
  31. public override void OnPointerDown(PointerEventData eventData) {
  32. base.OnPointerDown(eventData);
  33. isDown = true;
  34. }
  35. public override void OnPointerUp(PointerEventData eventData) {
  36. base.OnPointerUp(eventData);
  37. sliderChanged(slider.value);
  38. isDown = false;
  39. }
  40. }
  41. }