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));
        }
Beispiel #2
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);
        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     chosenIndex = 0;
            uint    maxNumber   = 0;
            ref var random      = ref blackboard.GetDataRef <BehaviorTreeRandom>().Value;