forked from zxl/LaboratoryProtection
69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
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<string, AwaitTimeline> _mapper;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
_mapper = new Dictionary<string, AwaitTimeline>();
|
|
_mapper = _allTimelines.ToDictionary(_ => _.name);
|
|
}
|
|
|
|
private void Reset()
|
|
{
|
|
_allTimelines = this.GetComponentsInChildren<AwaitTimeline>(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<TimelineController>(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<TimelineController>(out var controller))
|
|
{
|
|
var timeline = controller.GetDirector(name);
|
|
return timeline;
|
|
}
|
|
return null;
|
|
}
|
|
} |