using Cysharp.Threading.Tasks; using PMaker.Await; using PMaker.DependencyInjection; using PMaker.Set; using System.Collections.Generic; using System.Linq; using System.Threading; using UnityEngine; using UnityEngine.Playables; public class TimelineController : SingletonMonobehaviour { [SerializeField] private AwaitTimeline[] _allTimelines; [SerializeField] private Dictionary _mapper; protected override void Awake() { base.Awake(); _mapper = new Dictionary(); _mapper = _allTimelines.ToDictionary(_ => _.name); } private void Reset() { _allTimelines = this.GetComponentsInChildren(true); } public async UniTask WaitStep(string name, CancellationToken cancellationToken) { await _mapper[name].WaitStep(cancellationToken); } public AwaitTimeline GetDirector(string name) { return _mapper[name]; } } public static class BaseBehaviourExtension { public static async UniTask WaitTimeline(this BaseBehaviour baseBehaviour, string name, CancellationToken cancellationToken) { if (IoC.TryGetSingleton(out var controller)) { await controller.WaitStep(name, cancellationToken); } else { Debug.Log("timeline error!"); } await UniTask.Yield(cancellationToken); } public static AwaitTimeline GetTimeline(this BaseBehaviour baseBehaviour, string name) { if (IoC.TryGetSingleton(out var controller)) { var timeline = controller.GetDirector(name); return timeline; } return null; } }