示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        protected sealed override int onUpdate(BehaviourTreeData wData)
        {
            int runningState = BehaviourTreeRunningStatus.FINISHED;
            TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData);

            if (thisContext.status == ACTION_READY)
            {
                onEnter(wData);
                thisContext.needExit = true;
                thisContext.status   = ACTION_RUNNING;
            }
            if (thisContext.status == ACTION_RUNNING)
            {
                runningState = onExecute(wData);
                if (BehaviourTreeRunningStatus.IsFinished(runningState))
                {
                    thisContext.status = ACTION_FINISHED;
                }
            }
            if (thisContext.status == ACTION_FINISHED)
            {
                if (thisContext.needExit)
                {
                    onExit(wData, runningState);
                }
                thisContext.status   = ACTION_READY;
                thisContext.needExit = false;
            }
            return(runningState);
        }
示例#4
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);
        }
示例#5
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;
        }
示例#6
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;
        }
示例#7
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;
        }
示例#8
0
        protected sealed override void onTransition(BehaviourTreeData wData)
        {
            TBTActionLeafContext thisContext = getContext <TBTActionLeafContext>(wData);

            if (thisContext.needExit)
            {
                onExit(wData, BehaviourTreeRunningStatus.TRANSITION);
            }
            thisContext.status   = ACTION_READY;
            thisContext.needExit = false;
        }
示例#9
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);
        }
 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));
 }
示例#11
0
        protected T getContext <T>(BehaviourTreeData wData) where T : TBTActionContext, new()
        {
            int uniqueKey = GetHashCode();
            T   thisContext;

            if (wData.context.ContainsKey(uniqueKey) == false)
            {
                thisContext = new T();
                wData.context.Add(uniqueKey, thisContext);
            }
            else
            {
                thisContext = (T)wData.context[uniqueKey];
            }
            return(thisContext);
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
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);
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
0
 public void Transition(BehaviourTreeData wData)
 {
     onTransition(wData);
 }
示例#18
0
 //-------------------------------------------------------------
 public bool Evaluate(/*in*/ BehaviourTreeData wData)
 {
     return((_precondition == null || _precondition.IsTrue(wData)) && onEvaluate(wData));
 }
示例#19
0
 public int Update(BehaviourTreeData wData)
 {
     return(onUpdate(wData));
 }
示例#20
0
 protected virtual int onUpdate(BehaviourTreeData wData)
 {
     return(BehaviourTreeRunningStatus.FINISHED);
 }
示例#21
0
 protected virtual void onTransition(BehaviourTreeData wData)
 {
 }
示例#22
0
 public abstract bool IsTrue(/*in*/ BehaviourTreeData wData);
示例#23
0
 public override bool IsTrue(/*in*/ BehaviourTreeData wData)
 {
     return(false);
 }
示例#24
0
 public override bool IsTrue(/*in*/ BehaviourTreeData wData)
 {
     return(GetChild <BehaviourPrecondition>(0).IsTrue(wData) ||
            GetChild <BehaviourPrecondition>(1).IsTrue(wData));
 }
示例#25
0
 //--------------------------------------------------------
 // inherented by children-
 protected virtual void onEnter(/*in*/ BehaviourTreeData wData)
 {
 }
示例#26
0
 protected virtual void onExit(BehaviourTreeData wData, int runningStatus)
 {
 }
示例#27
0
 //--------------------------------------------------------
 // inherented by children
 protected virtual bool onEvaluate(/*in*/ BehaviourTreeData wData)
 {
     return(true);
 }
示例#28
0
 protected T getUserContexData <T>(BehaviourTreeData wData) where T : class, new()
 {
     return(getContext <TBTActionLeafContext>(wData).getUserData <T>());
 }