using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; public class TimeLineChange : MonoBehaviour { public PlayableDirector mDirector; public GameObject mGame2; public TimelinePauseByTime mGamePauseObj; private bool StopAndFirstFream = false; public void Start() { mDirector.gameObject.SetActive(false); mGame2.SetActive(false); mGamePauseObj = mGame2.GetComponent(); } public void CloseAllTimeLine() { TimeLineStop(); mDirector.gameObject.SetActive(false); mGame2.SetActive(false); } public void SwitchDirector(TimeLineControlType ControlType) { if (ControlType == TimeLineControlType.E_Explain) { mDirector.gameObject.SetActive(true); TimeLinePlay(); StopAndFirstFream = true; //Invoke("TimeLinePause", 0.1f); mGame2.SetActive(false); } else { mDirector.gameObject.SetActive(false); TimeLinePlay(); StopAndFirstFream = true; //Invoke("TimeLinePause", 0.1f); mGame2.SetActive(true); if (mGamePauseObj != null) { mGamePauseObj.InitTaskCanvas(); } } } public double GetLength() { return mDirector.duration; } public double GetCurrentTime() { return mDirector.time; } void _play() { if (!mDirector.gameObject.activeSelf) { mDirector.gameObject.SetActive(true); } mDirector.Play(); } public void TimeLineRePlay() { mDirector.Stop(); mDirector.time = 0; _play(); } public void TimeLinePlay() { _play(); } public void TimeLinePause() { mDirector.Pause(); } public void TimeLineStop() { mDirector.Stop(); } public void SetTime(float ratio) { mDirector.Pause(); mDirector.time = mDirector.duration * ratio; _play(); } public void Update() { if (StopAndFirstFream) { if (mDirector.time > 0.0f) { TimeLinePause(); StopAndFirstFream = false; } } if (mDirector.time >= mDirector.duration) { if (mDirector.gameObject.activeSelf) { mDirector.gameObject.SetActive(false); } } } }