66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
|
|
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<NodePlayer> Pre = new();
|
||
|
|
public List<NodePlayer> Next = new();
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 后续连接执行类型
|
||
|
|
/// </summary>
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 开始执行
|
||
|
|
/// </summary>
|
||
|
|
public override async UniTask Execute()
|
||
|
|
{
|
||
|
|
await base.Execute();
|
||
|
|
await MoveNext();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 向下继续执行
|
||
|
|
/// </summary>
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|