33 lines
859 B
C#
33 lines
859 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class AiSelector : AiComposite {
|
|
|
|
private int _currentId = 0;
|
|
|
|
protected override void OnBegin(AiBlackboard blackboard) {
|
|
_currentId = 0;
|
|
}
|
|
|
|
protected override void OnEnd(AiBlackboard blackboard) {
|
|
|
|
}
|
|
|
|
protected override BehaviorStatus OnExecute(AiBlackboard blackboard) {
|
|
if (children == null || children.Length == 0) {
|
|
Debug.LogError("Broken behavior! No children!");
|
|
return BehaviorStatus.Invalid;
|
|
}
|
|
|
|
while(_currentId < children.Length) {
|
|
var current = children[_currentId];
|
|
var result = current.Tick(blackboard);
|
|
if (result != BehaviorStatus.Fail) {
|
|
return result;
|
|
}
|
|
_currentId++;
|
|
}
|
|
return BehaviorStatus.Fail;
|
|
}
|
|
}
|