using UnityEngine; using System.Collections; using Games.Events; using Games.Scene; using UnityEngine.Playables; public class SceneMovie : MonoBehaviour { public PlayableDirector _PlayableDirector; public double DurTime = -1; public float DelayDestroy = 0; public void AddDurTime(float Time) { if (_PlayableDirector != null) { DurTime = Time + _PlayableDirector.duration; } else DurTime = Time; DurTime += DelayDestroy; } private void Start() { if(_PlayableDirector!=null) { if(DurTime<=0) { DurTime = _PlayableDirector.duration; } if (_PlayableDirector.playOnAwake == false) { _PlayableDirector.Pause(); } else { _PlayableDirector.Play(); } } InitMove(); if (Games.LogicObj.WorldUIRoot.Instance != null) Games.LogicObj.WorldUIRoot.Instance.SetShow(false); SceneMovieManager.Instance._PlayingMovie = true; // 强制关闭雾效果 CameraController.ForceNoFog(true, 0); EventDispatcher.Instance.Dispatch(Games.Events.EventId.SceneMovie, true); } private void Update() { if (DurTime <= 0) { MovieEnd(); return; } DurTime -= Time.deltaTime; } private void OnDisable() { if (!GameManager.applicationQuit) { if (Games.LogicObj.WorldUIRoot.Instance != null) Games.LogicObj.WorldUIRoot.Instance.SetShow(true); SceneMovieManager.Instance._PlayingMovie = false; // 恢复当前雾效果 CameraController.ForceNoFog(false, 0); EventDispatcher.Instance.Dispatch(Games.Events.EventId.SceneMovie, false); } } public void InitMove() { var mainChar = transform.Find("Actors/MainChar"); if (mainChar == null) return; gameObject.SetActive(false); var charModel = mainChar.GetChild(0); if (charModel != null) GameObject.Destroy(charModel.gameObject); var chatAnim = Singleton.Instance.MainPlayer.gameObject.GetComponentInChildren(); var copyChar = GameObject.Instantiate(chatAnim.gameObject); copyChar.transform.SetParent(mainChar); copyChar.transform.localPosition = Vector3.zero; copyChar.transform.localRotation = Quaternion.Euler(Vector3.zero); var rends = copyChar.GetComponentsInChildren(); for (int i = 0; i < rends.Length; ++i) { rends[i].gameObject.layer = mainChar.gameObject.layer; } gameObject.SetActive(true); } public void MovieEnd() { SceneMovieManager.Instance.PlayMovieOver(this); } }