using System; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class SliderEvent : MonoBehaviour, IEndDragHandler, IBeginDragHandler { public VideoPlayerEx vpEx; private Slider _slider; void Start() { _slider = GetComponent(); InvokeRepeating("UpdateSlider", 0, 0.1f); } // Update is called once per frame void UpdateSlider() { if ( vpEx.isPlaying && !vpEx.isDrag) { _slider.value = vpEx.VideoProgress; } } public void OnEndDrag(PointerEventData eventData) { vpEx.SetTime(_slider.value * vpEx.VideoTime); Invoke("SetDrag", 0.5f); // 延时实现进度条的同步 } void SetDrag() { vpEx.isDrag = false; } public void OnBeginDrag(PointerEventData eventData) { vpEx.isDrag = true; vpEx.Pause(); } }