VideoSlider.cs 1.2 KB

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