コード例 #1
0
        public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance)
        {
            var state = behaviourTreeInstance.NodeAndState[this];

            if (state == BehaviourTreeInstance.NodeState.STATE_EXECUTING)
            {
                return(new ExecutionResult(true));
            }

            if (state == BehaviourTreeInstance.NodeState.STATE_COMPUTE_RESULT)
            {
                BehaviourTreeNode picked = ChooseByRandom(actionArrayAndLikelihood);

                behaviourTreeInstance.NodeAndState[this]   = BehaviourTreeInstance.NodeState.STATE_WAITING;
                behaviourTreeInstance.NodeAndState[picked] = BehaviourTreeInstance.NodeState.STATE_TO_BE_STARTED;

                foreach (var item in actionArrayAndLikelihood)
                {
                    if (item.Key != picked)
                    {
                        behaviourTreeInstance.NodeAndState[item.Key] = BehaviourTreeInstance.NodeState.STATE_DISCARDED;
                    }
                }
            }
            return(new ExecutionResult(true));
        }
コード例 #2
0
        public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance)
        {
            var state = behaviourTreeInstance.NodeAndState[this];

            if (state == BehaviourTreeInstance.NodeState.STATE_EXECUTING)
            {
                return(new ExecutionResult(true));
            }

            int resultInt = conditionFunction(behaviourTreeInstance).IntegerResult;

            if (state == BehaviourTreeInstance.NodeState.STATE_EXECUTING)
            {
                return(new ExecutionResult(true));
            }

            for (var j = 0; j < actionArray.Count(); j++)
            {
                if (j == resultInt)
                {
                    behaviourTreeInstance.NodeAndState[actionArray[j]] = BehaviourTreeInstance.NodeState.STATE_TO_BE_STARTED;
                }
                else
                {
                    behaviourTreeInstance.NodeAndState[actionArray[j]] = BehaviourTreeInstance.NodeState.STATE_DISCARDED;
                }
            }

            return(new ExecutionResult(resultInt));
        }
コード例 #3
0
        public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance)
        {
            var state = behaviourTreeInstance.NodeAndState[this];

            if (state == BehaviourTreeInstance.NodeState.STATE_EXECUTING)
            {
                return(new ExecutionResult(true));
            }

            ExecutionResult result = conditionFunction(behaviourTreeInstance);

            if (state == BehaviourTreeInstance.NodeState.STATE_EXECUTING)
            {
                return(new ExecutionResult(true));
            }

            if (result.BooleanResult)
            {
                behaviourTreeInstance.NodeAndState[actionIfTrue]  = BehaviourTreeInstance.NodeState.STATE_TO_BE_STARTED;
                behaviourTreeInstance.NodeAndState[actionIfFalse] = BehaviourTreeInstance.NodeState.STATE_DISCARDED;
            }
            else
            {
                behaviourTreeInstance.NodeAndState[actionIfTrue]  = BehaviourTreeInstance.NodeState.STATE_DISCARDED;
                behaviourTreeInstance.NodeAndState[actionIfFalse] = BehaviourTreeInstance.NodeState.STATE_TO_BE_STARTED;
            }

            return(result);
        }
コード例 #4
0
 public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance)
 {
     return(action(behaviourTreeInstance));
 }
コード例 #5
0
 public ExecutionResult Execute(BehaviourTreeInstance behaviourTreeInstance)
 {
     behaviourTreeInstance.NodeAndState[this]           = BehaviourTreeInstance.NodeState.STATE_WAITING;
     behaviourTreeInstance.NodeAndState[actionArray[0]] = BehaviourTreeInstance.NodeState.STATE_TO_BE_STARTED;
     return(new ExecutionResult(true));
 }