YanCheng_Metrology/Assets/Scripts/Wwz/OfficeScene/OfficeTimelineControl.cs

67 lines
1.7 KiB
C#

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<PlayableDirector>();
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();
}
/// <summary>
/// 外挂到场景中得timeline
/// </summary>
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;
}
}