using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Playables; public class OfficeTimelineControl : MonoBehaviour { private PlayableDirector mPlayableDirector; //过场动画所用的玩家模型 private GameObject playerModel; public GameObject playerController; public GameObject aniCamera; // Start is called before the first frame update void Start() { mPlayableDirector = GetComponent(); if (!GameManager.RunModelMgr.isOnceOfficeAni) { playerController.SetActive(false); mPlayableDirector.Stop(); //mPlayableDirector.stopped += OnPlayableDirectorStopped; playerModel = transform.GetChild(0).gameObject; StartTimeline(); //TODO 这里先掉一下,后续应该流程控制的时候触发调用 GameManager.RunModelMgr.isOnceOfficeAni = true; } else { mPlayableDirector.Stop(); DestroyPlayer(); } } private void Update() { if (Input.GetKeyDown("p")) { mPlayableDirector.Stop(); DestroyPlayer(); } } public void StartTimeline() { mPlayableDirector.Play(); } public void OnPlayableDirectorStopped() { GameManager.EventMgr.EventTrigger(Enum_EventType.OfficeTimeLineOver); Invoke("DestroyPlayer", 1f); } private void DestroyPlayer() { Destroy(playerModel); Destroy(aniCamera); playerController.SetActive(true); GameManager.EventMgr.EventTrigger(Enum_EventType.InitializationUI); } void OnDestroy() { //mPlayableDirector.stopped -= OnPlayableDirectorStopped; } }