using System.Collections.Generic; using System.Linq; using Cysharp.Threading.Tasks; namespace Stary.Evo.StoryEditor { public class FlowNodePlayer : NodePlayer { public new FlowNodeData Data; public List Pre = new(); public List Next = new(); /// /// 后续连接执行类型 /// public NodeExecuteType ExecuteType; public FlowNodePlayer(GraphPlayer graph, FlowNodeData data) : base(graph, data) { Data = data; ExecuteType = data.executeType; } public override bool Connect() { if(!base.Connect()) return false; Data.pre.ForEach(index => Pre.Add(Graph.Nodes[index])); Data.next.ForEach(index => Next.Add(Graph.Nodes[index])); Next.ForEach(node => node.Connect()); return true; } /// /// 开始执行 /// public override async UniTask Execute() { await base.Execute(); await MoveNext(); } /// /// 向下继续执行 /// public override async UniTask MoveNext() { // 异步执行(并行) if (ExecuteType == NodeExecuteType.Async) { Next.ForEach(node => node?.Execute()); } // 同步执行(串行) else { foreach (var node in Next.Where(node => node != null)) { await node.Execute(); } } } } }