Ejemplo n.º 1
0
        protected override int OnUpdate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);
            int runningState = BtRunningStatus.FINISHED;

            if (thisContext._currentSelectedIndex != thisContext._lastSelectedIndex)
            {
                if (IsIndexValid(thisContext._lastSelectedIndex))
                {
                    BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);
                    node.Transition(workData);
                }
                thisContext._lastSelectedIndex = thisContext._currentSelectedIndex;
            }

            if (IsIndexValid(thisContext._lastSelectedIndex))
            {
                BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);
                runningState = node.Update(workData);
                if (BtRunningStatus.IsFinished(runningState))
                {
                    thisContext._lastSelectedIndex = -1;
                }
            }

            return(runningState);
        }
Ejemplo n.º 2
0
        protected override void OnTransition(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);
            BtAction node = GetChild <BtAction>(thisContext._lastSelectedIndex);

            if (node != null)
            {
                node.Transition(workData);
            }
            thisContext._lastSelectedIndex = -1;
        }
Ejemplo n.º 3
0
        protected override bool OnEvaluate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext =
                GetContext <BtActionPrioritizedSelectorContext>(workData);

            //check last node first
            if (IsIndexValid(thisContext._currentSelectedIndex))
            {
                BtAction node = GetChild <BtAction>(thisContext._currentSelectedIndex);
                if (node.Evaluate(workData))
                {
                    return(true);
                }
            }
            return(base.OnEvaluate(workData));
        }
Ejemplo n.º 4
0
        protected override bool OnEvaluate(BtWorkingData workData)
        {
            BtActionPrioritizedSelectorContext thisContext = GetContext <BtActionPrioritizedSelectorContext>(workData);

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

            for (int i = 0; i < childCount; i++)
            {
                BtAction node = GetChild <BtAction>(i);
                if (node.Evaluate(workData))
                {
                    thisContext._currentSelectedIndex = i;
                    return(true);
                }
            }
            return(false);
        }