当前位置:   article > 正文

在unity当中为VedioPlayer(视频播放组件)添加进度条,并且可以进行拖动_unity videoplayer 进度条

unity videoplayer 进度条
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Video;
  4. using UnityEngine.EventSystems;
  5. /// <summary>
  6. /// 将此脚本挂载在Slider上,可以实现视频滑动条效果
  7. /// </summary>
  8. public class VideoController : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
  9. {
  10. public VideoPlayer m_player;
  11. public Slider m_slider;
  12. public bool m_bMouseUp = true;
  13. void Start()
  14. {
  15. m_slider.onValueChanged.AddListener((float value) =>
  16. {
  17. if (!m_bMouseUp)
  18. {
  19. SliderEvent(value);
  20. }
  21. });
  22. }
  23. // 如果启用 MonoBehaviour,则每个固定帧速率的帧都将调用此函数
  24. private void FixedUpdate()
  25. {
  26. if (m_bMouseUp)
  27. {
  28. m_slider.value = m_player.frame / (m_player.frameCount * 1.0f);
  29. }
  30. }
  31. public void PointerDown()
  32. {
  33. m_player.Pause();
  34. m_bMouseUp = false;
  35. }
  36. public void PointerUp()
  37. {
  38. m_player.Play();
  39. m_bMouseUp = true;
  40. }
  41. public void SliderEvent(float value)
  42. {
  43. m_player.frame = long.Parse((value * m_player.frameCount).ToString("0."));
  44. }
  45. public void OnPointerUp(PointerEventData eventData)
  46. {
  47. PointerUp();
  48. }
  49. public void OnPointerDown(PointerEventData eventData)
  50. {
  51. PointerDown();
  52. }
  53. }

把此脚本挂载到Slider

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/114070
推荐阅读
相关标签
  

闽ICP备14008679号