SeekBarCtrl.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using UnityEngine.Events;
  5. using UnityEngine.EventSystems;
  6. #if !UNITY_WEBGL
  7. public class SeekBarCtrl : MonoBehaviour ,IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler{
  8. public MediaPlayerCtrl m_srcVideo;
  9. public Slider m_srcSlider;
  10. public float m_fDragTime = 0.2f;
  11. bool m_bActiveDrag = true;
  12. bool m_bUpdate = true;
  13. float m_fDeltaTime = 0.0f;
  14. float m_fLastValue = 0.0f;
  15. float m_fLastSetValue = 0.0f;
  16. // Use this for initialization
  17. void Start () {
  18. }
  19. // Update is called once per frame
  20. void Update () {
  21. if (m_bActiveDrag == false) {
  22. m_fDeltaTime += Time.deltaTime;
  23. if (m_fDeltaTime > m_fDragTime) {
  24. m_bActiveDrag = true;
  25. m_fDeltaTime = 0.0f;
  26. //if(m_fLastSetValue != m_fLastValue)
  27. // m_srcVideo.SetSeekBarValue (m_fLastValue);
  28. }
  29. }
  30. if (m_bUpdate == false)
  31. return;
  32. if (m_srcVideo != null) {
  33. if (m_srcSlider != null) {
  34. m_srcSlider.value = m_srcVideo.GetSeekBarValue();
  35. }
  36. }
  37. }
  38. public void OnPointerEnter(PointerEventData eventData)
  39. {
  40. Debug.Log("OnPointerEnter:");
  41. m_bUpdate = false;
  42. }
  43. public void OnPointerExit(PointerEventData eventData)
  44. {
  45. Debug.Log("OnPointerExit:");
  46. m_bUpdate = true;
  47. }
  48. public void OnPointerDown(PointerEventData eventData)
  49. {
  50. }
  51. public void OnPointerUp(PointerEventData eventData)
  52. {
  53. m_srcVideo.SetSeekBarValue (m_srcSlider.value);
  54. }
  55. public void OnDrag(PointerEventData eventData)
  56. {
  57. Debug.Log("OnDrag:"+ eventData);
  58. if (m_bActiveDrag == false)
  59. {
  60. m_fLastValue = m_srcSlider.value;
  61. return;
  62. }
  63. //m_srcVideo.SetSeekBarValue (m_srcSlider.value);
  64. m_fLastSetValue = m_srcSlider.value;
  65. m_bActiveDrag = false;
  66. }
  67. }
  68. #endif