public NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard) { if (blob.GetState(index) == NodeState.Running) { var childIndex = blob.FirstOrDefaultChildIndex(index, state => state == NodeState.Running); return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0); } var weightIndex = 0; var currentMaxWeight = int.MinValue; var maxChildIndex = 0; foreach (var childIndex in blob.GetChildrenIndices(index)) { var weight = Weights[weightIndex]; if (weight > currentMaxWeight) { maxChildIndex = childIndex; currentMaxWeight = weight; } weightIndex++; } return(VirtualMachine.Tick(maxChildIndex, blob, blackboard)); }
public static NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard) { if (blob.GetState(index) == NodeState.Running) { var childIndex = blob.GetChildrenIndices(index, state => state == NodeState.Running).FirstOrDefault(); return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0); } ref var data = ref blob.GetNodeData <PrioritySelectorNode>(index);
public static NodeState Tick(int index, INodeBlob blob, IBlackboard blackboard) { if (blob.GetState(index) == NodeState.Running) { var childIndex = blob.GetChildrenIndices(index, state => state == NodeState.Running).FirstOrDefault(); return(childIndex != default ? VirtualMachine.Tick(childIndex, blob, blackboard) : 0); } var chosenIndex = 0; uint maxNumber = 0; ref var random = ref blackboard.GetDataRef <BehaviorTreeRandom>().Value;
public static IEnumerable <NodeState> TickChildren( this INodeBlob blob , int index , IBlackboard bb , Predicate <NodeState> breakCheck , Predicate <NodeState> tickCheck ) { foreach (var childIndex in blob.GetChildrenIndices(index)) { var prevState = blob.GetState(childIndex); var currentState = tickCheck(prevState) ? VirtualMachine.Tick(childIndex, blob, bb) : 0; yield return(currentState); if (breakCheck(currentState == 0 ? prevState : currentState)) { yield break; } } }
public static IEnumerable <int> GetChildrenIndices(this INodeBlob blob, int parentIndex, Predicate <NodeState> predicate) { return(blob.GetChildrenIndices(parentIndex).Where(childIndex => predicate(blob.GetState(childIndex)))); }