Esempio n. 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));
        }
Esempio n. 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);
Esempio n. 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);
            }

            var     chosenIndex = 0;
            uint    maxNumber   = 0;
            ref var random      = ref blackboard.GetDataRef <BehaviorTreeRandom>().Value;