-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSequence.cs
40 lines (35 loc) · 1.15 KB
/
Sequence.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using UnityEngine;
namespace StartFramework.GamePlay.BehaviourTree
{
/// <summary>
/// 序列
/// 一个接一个的执行子节点,迭代完成之后再从头开始。
/// 如果子节点返回:
/// ● 成功:序列在下一帧执行下一个子节点
/// ● 失败:返回失败(可用于中断树的迭代。例如多于500元钱时静止)
/// ● 运行:序列在下一帧再次执行该节点
/// </summary>
public class Sequence : Node
{
public Sequence(string name)
{
this.name = $"[序列]{name}";
}
public override Status Process()
{
Status childStatus = children[currentChildren].Process();
if (childStatus == Status.RUNNING)
{
return Status.RUNNING;
}
if (childStatus == Status.FAILURE) return childStatus;
currentChildren++;
if (currentChildren >= children.Count)
{
currentChildren = 0;
return Status.SUCCESS;
}
return Status.RUNNING;
}
}
}