コード例 #1
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            int runningState = BehaviourTreeRunningStatus.FINISHED;

            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex);
                runningState = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningState))
                {
                    thisContext.lastSelectedIndex = -1;
                }
            }
            return(runningState);
        }
コード例 #2
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            initListTo <bool>(thisContext.evaluationStatus, false);
            bool finalResult = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                bool            ret  = node.Evaluate(wData);
                //early break
                if (_evaluationRelationship == ECHILDREN_RELATIONSHIP.AND && ret == false)
                {
                    finalResult = false;
                    break;
                }
                if (ret == true)
                {
                    finalResult = true;
                }
                thisContext.evaluationStatus[i] = ret;
            }
            return(finalResult);
        }
コード例 #3
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int             runningStatus        = BehaviourTreeRunningStatus.FINISHED;
            BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);

            runningStatus = node.Update(wData);
            if (_continueIfErrorOccors == false && BehaviourTreeRunningStatus.IsError(runningStatus))
            {
                thisContext.currentSelectedIndex = -1;
                return(runningStatus);
            }
            if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
            {
                thisContext.currentSelectedIndex++;
                if (IsIndexValid(thisContext.currentSelectedIndex))
                {
                    runningStatus = BehaviourTreeRunningStatus.EXECUTING;
                }
                else
                {
                    thisContext.currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
コード例 #4
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);
            BehaviourAction node = GetChild <BehaviourAction>(thisContext.lastSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.lastSelectedIndex = -1;
        }
コード例 #5
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);

            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                node.Transition(wData);
            }
            thisContext.currentCount = 0;
        }
コード例 #6
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            BehaviourAction          node        = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);

            if (node != null)
            {
                node.Transition(wData);
            }
            thisContext.currentSelectedIndex = -1;
        }
コード例 #7
0
        protected override void onTransition(BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            for (int i = 0; i < GetChildCount(); ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                node.Transition(wData);
            }
            //clear running status
            initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
        }
コード例 #8
0
 protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
 {
     BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext thisContext =
         getContext <BehaviourActionPrioritizedSelector.TBTActionPrioritizedSelectorContext>(wData);
     //check last node first
     if (IsIndexValid(thisContext.currentSelectedIndex))
     {
         BehaviourAction node = GetChild <BehaviourAction>(thisContext.currentSelectedIndex);
         if (node.Evaluate(wData))
         {
             return(true);
         }
     }
     return(base.onEvaluate(wData));
 }
コード例 #9
0
        //-------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            bool checkLoopCount = (_loopCount == INFINITY || thisContext.currentCount < _loopCount);

            if (checkLoopCount == false)
            {
                return(false);
            }
            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                return(node.Evaluate(wData));
            }
            return(false);
        }
コード例 #10
0
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionPrioritizedSelectorContext thisContext = getContext <TBTActionPrioritizedSelectorContext>(wData);

            thisContext.currentSelectedIndex = -1;
            int childCount = GetChildCount();

            for (int i = 0; i < childCount; ++i)
            {
                BehaviourAction node = GetChild <BehaviourAction>(i);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }
コード例 #11
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionParallelContext thisContext = getContext <TBTActionParallelContext>(wData);

            //first time initialization
            if (thisContext.runningStatus.Count != GetChildCount())
            {
                initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
            }
            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                if (thisContext.evaluationStatus[i] == false)
                {
                    continue;
                }
                if (BehaviourTreeRunningStatus.IsFinished(thisContext.runningStatus[i]))
                {
                    hasFinished = true;
                    continue;
                }
                BehaviourAction node          = GetChild <BehaviourAction>(i);
                int             runningStatus = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }
                thisContext.runningStatus[i] = runningStatus;
            }
            if (_runningStatusRelationship == ECHILDREN_RELATIONSHIP.OR && hasFinished || _runningStatusRelationship == ECHILDREN_RELATIONSHIP.AND && hasExecuting == false)
            {
                initListTo <int>(thisContext.runningStatus, BehaviourTreeRunningStatus.EXECUTING);
                return(BehaviourTreeRunningStatus.FINISHED);
            }
            return(BehaviourTreeRunningStatus.EXECUTING);
        }
コード例 #12
0
        protected override int onUpdate(BehaviourTreeData wData)
        {
            TBTActionLoopContext thisContext = getContext <TBTActionLoopContext>(wData);
            int runningStatus = BehaviourTreeRunningStatus.FINISHED;

            if (IsIndexValid(0))
            {
                BehaviourAction node = GetChild <BehaviourAction>(0);
                runningStatus = node.Update(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningStatus))
                {
                    thisContext.currentCount++;
                    if (thisContext.currentCount < _loopCount || _loopCount == INFINITY)
                    {
                        runningStatus = BehaviourTreeRunningStatus.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }
コード例 #13
0
        //------------------------------------------------------
        protected override bool onEvaluate(/*in*/ BehaviourTreeData wData)
        {
            TBTActionSequenceContext thisContext = getContext <TBTActionSequenceContext>(wData);
            int checkedNodeIndex = -1;

            if (IsIndexValid(thisContext.currentSelectedIndex))
            {
                checkedNodeIndex = thisContext.currentSelectedIndex;
            }
            else
            {
                checkedNodeIndex = 0;
            }
            if (IsIndexValid(checkedNodeIndex))
            {
                BehaviourAction node = GetChild <BehaviourAction>(checkedNodeIndex);
                if (node.Evaluate(wData))
                {
                    thisContext.currentSelectedIndex = checkedNodeIndex;
                    return(true);
                }
            }
            return(false);
        }
コード例 #14
0
ファイル: BehaviourAction.cs プロジェクト: zyun22/QFramework
 //-------------------------------------------------------------
 public BehaviourAction(int maxChildCount)
     : base(maxChildCount)
 {
     _uniqueKey = BehaviourAction.genUniqueKey();
 }