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); }
protected override bool OnEvaluate(NodeData wData) { NodeControlSequenceContext thisContext = GetContext <NodeControlSequenceContext>(wData); //获取当前选择的索引 int checkedNodeIndex = -1; if (IsIndexValid(thisContext.currentSelectedIndex)) { checkedNodeIndex = thisContext.currentSelectedIndex; } else { checkedNodeIndex = 0; } if (IsIndexValid(checkedNodeIndex)) { Node node = GetChild <Node>(checkedNodeIndex); if (node.Evaluate(wData)) { thisContext.currentSelectedIndex = checkedNodeIndex; return(true); } } return(false); }
protected override void OnTransition(NodeData wData) { NodeControlSequenceContext thisContext = GetContext <NodeControlSequenceContext>(wData); Node node = GetChild <Node>(thisContext.currentSelectedIndex); if (node != null) { node.Transition(wData); } thisContext.currentSelectedIndex = -1; }