【a】可视化剧本编辑器 10.StoryEditor
This commit is contained in:
66
Assets/10.StoryEditor/RunTime/Player/Node/FlowNodePlayer.cs
Normal file
66
Assets/10.StoryEditor/RunTime/Player/Node/FlowNodePlayer.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user