using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; 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 private async void Start() { await Task.Delay(1); mPlayableDirector = GetComponent(); if (!GameManager.RunModelMgr.isOnceOfficeAni) { //mPlayableDirector.stopped += OnPlayableDirectorStopped; playerModel = transform.GetChild(0).gameObject; StartTimeline(); GameManager.RunModelMgr.isOnceOfficeAni = true; } else { mPlayableDirector.Stop(); DestroyPlayer(); } } private void Update() { if (Input.GetKeyDown("p")) { mPlayableDirector.Stop(); DestroyPlayer(); } } public void StartTimeline() { mPlayableDirector.Play(); } /// /// 外挂到场景中得timeline /// public void OnPlayableDirectorStopped() { GameManager.EventMgr.EventTrigger(Enum_EventType.OfficeTimeLineOver); Invoke("DestroyPlayer", 1f); } private void DestroyPlayer() { GameManager.EventMgr.EventTrigger(Enum_EventType.InitializationUI); Destroy(playerModel); Destroy(aniCamera); //playerController.SetActive(true); } void OnDestroy() { //mPlayableDirector.stopped -= OnPlayableDirectorStopped; } }