43 lines
905 B
C#
43 lines
905 B
C#
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<Slider>();
|
|
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();
|
|
}
|
|
} |