using System; using System.Collections.Generic; using DragonSoul.Shared; using Mono.Event; using Sirenix.OdinInspector; using Sirenix.Serialization; using UnityEngine; using UnityEngine.Playables; namespace UnityTest.ZXL { public abstract class ProcessBase : SerializedMonoBehaviour { public abstract ProcessType processType { get; } // public GameObject go; [OdinSerialize] protected List playableDirectors; private PlayableDirector currentPlayableDirector; #region Task protected ETTask currentTask; protected ETCancellationToken currentToken; protected void TokenCancel() { currentTask?.SetResult(false); currentToken.Remove(TokenCancel); } #endregion public PlayableDirector CurrentPlayableDirector { set { if (currentPlayableDirector != null && currentPlayableDirector == value) return; currentPlayableDirector = value; } get { if (currentPlayableDirector == null) { currentPlayableDirector = playableDirectors[0]; } return currentPlayableDirector; } } protected int index; #if UNITY_EDITOR [Button] void Add(GameObject go) { var list = go.GetComponentAllChild(); playableDirectors = new List(list); } #endif protected virtual void OnInit() { EventManager.Instance.Subscribe(ConstEventArgs.EventId, ConstEventLogic); EventManager.Instance.Subscribe(ClickObjectEventArgs.EventId, ClickObjectEvent); EventManager.Instance.Subscribe(PlayableStoppedEventArgs.EventId, PlayableStoppedEvent); // var list = go.GetComponentAllChild(); // playableDirectors = list; this.index = 0; } protected virtual void OnUpdate() { } protected virtual void OnLevel() { EventManager.Instance.Unsubscribe(ConstEventArgs.EventId, ConstEventLogic); EventManager.Instance.Unsubscribe(ClickObjectEventArgs.EventId, ClickObjectEvent); EventManager.Instance.Unsubscribe(PlayableStoppedEventArgs.EventId, PlayableStoppedEvent); } protected virtual void Next() { foreach (var playableDirector in playableDirectors) { playableDirector.gameObject.SetActive(false); } index++; AnimatorManager.Instance().HideAll(); } // protected abstract void ProcessLogic(); public virtual void ConstEventLogic(object sender, GameEventArgs e) { var args = e as ConstEventArgs; Debug.Log($"接收到抛出的事件{args.constDataType}"); } public virtual void PlayableStoppedEvent(object sender, GameEventArgs e) { var args = e as PlayableStoppedEventArgs; Next(); } public virtual void ClickObjectEvent(object sender, GameEventArgs e) { } private void OnEnable() { ETTask.ExceptionHandler -= ExceptionHandler; ETTask.ExceptionHandler += ExceptionHandler; OnInit(); } private void ExceptionHandler(Exception obj) { UnityEngine.Debug.LogError(obj.ToString()); } private void Update() { OnUpdate(); } private void OnDisable() { OnLevel(); } /// /// 打开高亮物体并等待点击后恢复timeline播放 /// /// /// protected async ETTask WaitOperateFinish_ClickHighlight(HighlightObjectType highlightObjectType, bool isAutoResume = true) { currentTask = ETTask.Create(); currentToken = new ETCancellationToken(); currentToken.Add(TokenCancel); ObjectDataComponent.Instance().GetObject(highlightObjectType).HighlightOpen(); await currentTask; if (isAutoResume) this.SetPlayDirector(CurrentPlayableDirector, PlayTimelineMode.Resume); } /// /// 等待点击后恢复timeline播放 /// /// protected async ETTask WaitOperateFinish_Click(bool isAutoResume = true) { currentTask = ETTask.Create(); currentToken = new ETCancellationToken(); currentToken.Add(TokenCancel); await currentTask; if (isAutoResume) this.SetPlayDirector(CurrentPlayableDirector, PlayTimelineMode.Resume); } /// /// 打开UI并等待点击后恢复timeline播放 /// /// /// protected async ETTask WaitOperateFinish_ClickUI(UIType uiType, bool isAutoResume = true) { currentTask = ETTask.Create(); currentToken = new ETCancellationToken(); currentToken.Add(TokenCancel); UIManager.Instance().ShowUI(uiType); await currentTask; UIManager.Instance().HideUI(uiType); if (isAutoResume) this.SetPlayDirector(CurrentPlayableDirector, PlayTimelineMode.Resume); } } public enum ProcessType { 一_爆炸发生场景, 二_汇报程序, 三_准备场景, 四_现场处置场景, } }