84 lines
2.3 KiB
C#
84 lines
2.3 KiB
C#
using BigSpace.XRCore.RunningScene;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
namespace BigSpace.XRCore.Timeline
|
|
{
|
|
public class TimeLineControll : MonoBehaviour
|
|
{
|
|
private PlayableDirector _playableDirector;
|
|
private bool _isPlaying;
|
|
|
|
public TimeLineData timeLineData = new TimeLineData();
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
InitPlayableDirector();
|
|
|
|
RunningSceneMgr.Instance.timelineCtr = this;
|
|
}
|
|
|
|
private void InitPlayableDirector()
|
|
{
|
|
_playableDirector ??= GetComponent<PlayableDirector>();
|
|
if (_playableDirector == null) return;
|
|
timeLineData.name = _playableDirector.playableAsset.name;
|
|
_playableDirector.Stop();
|
|
_playableDirector.played += ((o) => { _isPlaying = true; });
|
|
_playableDirector.stopped += ((o) => { _isPlaying = false; });
|
|
_playableDirector.paused += ((o) => { _isPlaying = false; });
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
timeLineData.time = (float)_playableDirector.time;
|
|
}
|
|
|
|
private void Play(float time = 0f)
|
|
{
|
|
if (_playableDirector == null) return;
|
|
|
|
Debug.Log("´«À´:" + time + " ×¶àÉÙ:" + _playableDirector.playableAsset.duration);
|
|
if (time >= _playableDirector.playableAsset.duration)
|
|
{
|
|
time = (float)(_playableDirector.playableAsset.duration - 1);
|
|
}
|
|
|
|
_playableDirector.time = time;
|
|
_playableDirector.Play();
|
|
}
|
|
|
|
public void NormalPlay()
|
|
{
|
|
if (_playableDirector.playOnAwake)
|
|
Play();
|
|
}
|
|
|
|
public void RecoveryPlay(float time)
|
|
{
|
|
Play(time);
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
if (_playableDirector == null) return;
|
|
|
|
_playableDirector.Stop();
|
|
}
|
|
|
|
public void ChangePlaySpeed(bool isSpeedUp)
|
|
{
|
|
if (_isPlaying)
|
|
_playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(isSpeedUp ? 8 : 1);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (RunningSceneMgr.Instance != null)
|
|
RunningSceneMgr.Instance.timelineCtr = null;
|
|
}
|
|
}
|
|
} |