Files
MetalGear2D.Unity/Assets/Scripts/AI/BehaviorTree/AiSequence.cs
T
2025-05-13 05:19:58 +03:00

32 lines
840 B
C#

using UnityEngine;
using System.Collections;
public class AiSequence : AiComposite {
private int _currentId = 0;
protected override void OnBegin(AiBlackboard blackboard) {
_currentId = 0;
}
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
if (children == null || children.Length == 0) {
Debug.LogError("Broken behavior! No children!");
return BehaviorStatus.Invalid;
}
//Debug.Log("Sequence: " + behaviorName);
while(_currentId < children.Length) {
var current = children[_currentId];
var result = current.Tick(blackboard);
if (result != BehaviorStatus.Success) {
return result;
}
_currentId++;
}
return BehaviorStatus.Success;
}
}