コード例 #1
0
        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));
        }
コード例 #2
0
        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);
コード例 #3
0
        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);
            }

            ref var data             = ref blob.GetNodeData <WeightRandomSelectorNode>(index);
コード例 #4
0
        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;
コード例 #5
0
ファイル: INodeBlob.cs プロジェクト: Hengle/EntitiesBT
        public static int FirstOrDefaultChildIndex(this INodeBlob blob, int parentIndex, Predicate <NodeState> predicate)
        {
            var endIndex   = blob.GetEndIndex(parentIndex);
            var childIndex = parentIndex + 1;

            while (childIndex < endIndex)
            {
                if (predicate(blob.GetState(childIndex)))
                {
                    return(childIndex);
                }
                childIndex = blob.GetEndIndex(childIndex);
            }
            return(default);
コード例 #6
0
        public static NodeState Tick(int index, INodeBlob blob, IBlackboard bb)
        {
            var endIndex   = blob.GetEndIndex(index);
            var childIndex = index + 1;

            for (var i = childIndex + 1 /* always reset directly child */; i < endIndex; i++)
            {
                if (blob.GetState(i) == NodeState.Running)
                {
                    endIndex = i;
                    break;
                }
            }
            var count = endIndex - childIndex;

            // count will be 0 if there's no child
            blob.ResetStates(childIndex, count);
            return(blob.TickChildren(index, bb).FirstOrDefault());
        }
コード例 #7
0
        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;
                }
            }
        }
コード例 #8
0
ファイル: INodeBlob.cs プロジェクト: Hengle/EntitiesBT
 public static IEnumerable <int> GetChildrenIndices(this INodeBlob blob, int parentIndex, Predicate <NodeState> predicate)
 {
     return(blob.GetChildrenIndices(parentIndex).Where(childIndex => predicate(blob.GetState(childIndex))));
 }