Пример #1
0
 //重写执行
 protected override sealed int OnExcute(NodeData wData)
 {
     int runningState = NodeState.FINISHED;
     //获取环境数据
     NodeActionContext context = GetContext<NodeActionContext>(wData);
     //准备进入
     if (context.status == ACTION_READY)
     {
         OnEnter(wData);
         context.needExit = true;
         context.status = ACTION_RUNNING;
     }
     //运行执行
     if (context.status == ACTION_RUNNING)
     {
         runningState = OnRunning(wData);
         if (NodeState.IsFinished(runningState))
         {
             context.status = ACTION_FINISHED;
         }
     }
     //完成退出
     if (context.status == ACTION_FINISHED)
     {
         if (context.needExit)
         {
             OnExit(wData, runningState);
         }
         context.status = ACTION_READY;
         context.needExit = false;
     }
     return runningState;
 }
Пример #2
0
        protected override int OnExcute(NodeData wData)
        {
            NodeControlRandomSelectorContext thisContext = GetContext <NodeControlRandomSelectorContext>(wData);
            int runningState = NodeState.FINISHED;

            //当前选择的不是上次选择的 (执行下上次的切换方法)
            if (thisContext.currentSelectedIndex != thisContext.lastSelectedIndex)
            {
                if (IsIndexValid(thisContext.lastSelectedIndex))
                {
                    Node node = GetChild <Node>(thisContext.lastSelectedIndex);
                    node.Transition(wData);
                }
                thisContext.lastSelectedIndex = thisContext.currentSelectedIndex;
            }

            //执行下选择的子节点
            if (IsIndexValid(thisContext.lastSelectedIndex))
            {
                Node node = GetChild <Node>(thisContext.lastSelectedIndex);
                runningState = node.Execute(wData);
                if (NodeState.IsFinished(runningState))
                {
                    thisContext.lastSelectedIndex = -1;
                    //重新随机
                    thisContext.currentSelectedIndex = -1;
                }
            }
            return(runningState);
        }
Пример #3
0
        protected override int OnExcute(NodeData wData)
        {
            NodeControlSequenceContext thisContext = GetContext <NodeControlSequenceContext>(wData);
            int runningStatus = NodeState.FINISHED;

            //执行一下选择节点
            Node node = GetChild <Node>(thisContext.currentSelectedIndex);

            runningStatus = node.Execute(wData);

            //错误判断
            if (NodeState.IsError(runningStatus))
            {
                thisContext.currentSelectedIndex = -1;
                return(runningStatus);
            }

            //完成判断
            if (NodeState.IsFinished(runningStatus))
            {
                //下移索引
                thisContext.currentSelectedIndex++;
                if (IsIndexValid(thisContext.currentSelectedIndex))
                {
                    runningStatus = NodeState.EXECUTING;
                }
                else
                {
                    thisContext.currentSelectedIndex = -1;
                }
            }
            return(runningStatus);
        }
Пример #4
0
        protected override int OnExcute(NodeData wData)
        {
            NodeControlParallelContext thisContext = GetContext <NodeControlParallelContext>(wData);

            //初始化状态
            if (thisContext.runningStatus.Count != GetChildCount())
            {
                InitListTo(thisContext.runningStatus, NodeState.EXECUTING);
            }

            //执行并刷新状态数据
            bool hasFinished  = false;
            bool hasExecuting = false;

            for (int i = 0; i < GetChildCount(); ++i)
            {
                //此节点评估未通过,返回
                if (thisContext.evaluationStatus[i] == false)
                {
                    continue;
                }
                //已经完成了
                if (NodeState.IsFinished(thisContext.runningStatus[i]))
                {
                    hasFinished = true;
                    continue;
                }
                //执行
                Node node          = GetChild <Node>(i);
                int  runningStatus = node.Execute(wData);
                if (NodeState.IsFinished(runningStatus))
                {
                    hasFinished = true;
                }
                else
                {
                    hasExecuting = true;
                }
                thisContext.runningStatus[i] = runningStatus;
            }

            //1,或条件 有已经完成了就是完成  2,并条件 都完成的就是完成
            if (excuteType == NodeParallelType.OR && hasFinished || excuteType == NodeParallelType.AND && hasExecuting == false)
            {
                InitListTo(thisContext.runningStatus, NodeState.EXECUTING);
                return(NodeState.FINISHED);
            }
            return(NodeState.EXECUTING);
        }
Пример #5
0
        //执行
        protected override int OnExcute(NodeData wData)
        {
            NodeControlLoopContext thisContext = GetContext <NodeControlLoopContext>(wData);
            int runningStatus = NodeState.FINISHED;

            if (IsIndexValid(0))
            {
                Node node = GetChild <Node>(0);
                runningStatus = node.Execute(wData);
                if (NodeState.IsFinished(runningStatus))
                {
                    thisContext.currentCount++;
                    if (thisContext.currentCount < loopCount || loopCount == -1)
                    {
                        runningStatus = NodeState.EXECUTING;
                    }
                }
            }
            return(runningStatus);
        }