Exemple #1
0
        public override ResultType Execute()
        {
            ++_executeCount;

            ResultType resultType = ResultType.Fail;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                NodeBase nodeBase = nodeChildList[i];

                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);

                if (resultType == ResultType.Running)
                {
                    _runningNode |= (1 << i);
                }
            }

            if (_repeatCount == -1 || _executeCount < _repeatCount)
            {
                resultType = ResultType.Running;
            }
            else
            {
                resultType = ResultType.Success;
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, resultType, Time.realtimeSinceStartup);

            return(resultType);
        }
Exemple #2
0
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                NodeBase nodeBase = nodeChildList[i];
                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);

                if (resultType == ResultType.Running)
                {
                    _runningNode |= (1 << i);
                }

                if (resultType == _desiredResult)
                {
                    return(ResultType.Success);
                }
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, ResultType.Running, Time.realtimeSinceStartup);
            return(ResultType.Running);
        }
Exemple #3
0
        public override ResultType Execute()
        {
            ResultType resultType = _iCondition.Condition();

            NodeNotify.NotifyExecute(EntityId, NodeId, resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #4
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            NodeBase   nodeRoot   = nodeChildList[0];
            ResultType resultType = nodeRoot.Execute();

            return(_constResult);
        }
Exemple #5
0
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            int successCount = 0;
            int failCount    = 0;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                NodeBase nodeBase = nodeChildList[i];

                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);

                if (resultType == ResultType.Fail)
                {
                    ++failCount;
                    continue;
                }

                if (resultType == ResultType.Success)
                {
                    ++successCount;
                    continue;
                }

                if (resultType == ResultType.Running)
                {
                    _runningNode |= (1 << i);
                    continue;
                }
            }

            if (successCount >= nodeChildList.Count)
            {
                resultType = ResultType.Success;
            }
            else if (failCount >= nodeChildList.Count)
            {
                resultType = ResultType.Fail;
            }
            else
            {
                resultType = ResultType.Running;
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, (int)resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #6
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            NodeBase   nodeRoot   = nodeChildList[0];
            ResultType resultType = nodeRoot.Execute();

            if (resultType == _desiredResult)
            {
                return(ResultType.Fail);
            }

            Update();

            return(ResultType.Running);
        }
Exemple #7
0
        public override ResultType Execute()
        {
            _randomCount = 0;

            int index = -1;

            if (lastRunningNode != null)
            {
                index = lastRunningNode.NodeIndex;
            }
            lastRunningNode = null;

            ResultType resultType = ResultType.Fail;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                if (index < 0)
                {
                    index = GetRandom();
                }
                NodeBase nodeBase = nodeChildList[index];
                index = -1;

                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);

                if (resultType == ResultType.Fail)
                {
                    break;
                }

                if (resultType == ResultType.Success)
                {
                    continue;
                }

                if (resultType == ResultType.Running)
                {
                    lastRunningNode = nodeBase;
                    break;
                }
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #8
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            List <int> randomList = GetRandom(nodeChildList.Count);

            int index = -1;

            if (lastRunningNode != null)
            {
                index = lastRunningNode.NodeIndex;
            }
            lastRunningNode = null;

            ResultType resultType = ResultType.Fail;

            while ((randomList.Count > 0))
            {
                if (index < 0)
                {
                    index = randomList[randomList.Count - 1];
                    randomList.RemoveAt(randomList.Count - 1);
                }
                NodeBase nodeRoot = nodeChildList[index];
                index = -1;

                resultType = nodeRoot.Execute();

                if (resultType == ResultType.Fail)
                {
                    continue;
                }

                if (resultType == ResultType.Success)
                {
                    break;
                }

                if (resultType == ResultType.Running)
                {
                    lastRunningNode = nodeRoot;
                    break;
                }
            }

            return(resultType);
        }
Exemple #9
0
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            if (!Application.isPlaying)
            {
                // 编辑器下预览用
                resultType = ResultType.Running;
            }
            else
            {
                resultType = iAction.DoAction();
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #10
0
        private ResultType ExecuteNode(NodeBase nodeBase)
        {
            ResultType resultType = ResultType.Fail;

            if (null != nodeBase)
            {
                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);
            }

            if (resultType == ResultType.Running)
            {
                lastRunningNode = nodeBase;
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
        protected ResultType ExecuteNode(NodeBase nodeBase, bool isFirstNode)
        {
            ResultType resultType = ResultType.Fail;

            if (null != nodeBase)
            {
                nodeBase.Preposition();
                resultType = nodeBase.Execute();
                nodeBase.Postposition(resultType);
            }

            if (!isFirstNode && resultType == ResultType.Running)
            {
                lastRunningNode = nodeBase;
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, (int)resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #12
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            NodeBase   nodeRoot   = nodeChildList[0];
            ResultType resultType = nodeRoot.Execute();

            ++_executeCount;

            if (_executeCount < _repeatCount)
            {
                resultType = ResultType.Running;
            }
            else
            {
                resultType = ResultType.Fail;
            }

            return(resultType);
        }
Exemple #13
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            ResultType resultType = ResultType.Fail;

            NodeBase   nodeRoot = nodeChildList[0];
            ResultType type     = nodeRoot.Execute();

            if (type == ResultType.Fail)
            {
                resultType = ResultType.Success;
            }
            else
            {
                resultType = ResultType.Fail;
            }

            return(resultType);
        }
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            if (nodeChildList.Count <= 0)
            {
                return(ResultType.Fail);
            }

            NodeBase nodeBase = nodeChildList[0];

            nodeBase.Preposition();
            resultType = nodeBase.Execute();
            nodeBase.Postposition(resultType);
            if (resultType == ResultType.Running)
            {
                lastRunningNode = nodeBase;
            }

            NodeNotify.NotifyExecute(EntityId, NodeId, (int)resultType, Time.realtimeSinceStartup);
            return(resultType);
        }
Exemple #15
0
        /// <summary>
        /// 顺序节点依次执行子节点,只要节点返回Success,就继续执行后续节点,直到一个节点
        /// 返回 Fail 或者 Running,停止执行后续节点,向父节点返回 Fail 或者 Running,如果
        /// 所有节点都返回 Success,则向父节点返回 Success
        /// 和选择节点一样,如果一个节点返回 Running,则需要记录该节点,下次执行时直接从该
        /// 节点开始执行
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            int index = 0;

            if (lastRunningNode != null)
            {
                index = lastRunningNode.NodeIndex;
            }
            lastRunningNode = null;

            ResultType resultType = ResultType.Fail;

            for (int i = index; i < nodeChildList.Count; ++i)
            {
                NodeBase nodeRoot = nodeChildList[i];
                resultType = nodeRoot.Execute();

                if (resultType == ResultType.Fail)
                {
                    break;
                }

                if (resultType == ResultType.Success)
                {
                    continue;
                }

                if (resultType == ResultType.Running)
                {
                    lastRunningNode = nodeRoot;
                    break;
                }
            }

            return(resultType);
        }
Exemple #16
0
        /// <summary>
        /// 并行节点同时执行所有节点,直到一个节点返回 Fail 或者全部节点都返回 Success
        /// 才向父节点返回 Fail 或者 Success,并终止执行其他节点
        /// 其他情况向父节点返回 Running
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

            ResultType resultType = ResultType.Fail;

            int successCount = 0;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                NodeBase nodeRoot = nodeChildList[i];
                resultType = nodeRoot.Execute();

                if (resultType == ResultType.Fail)
                {
                    break;
                }

                if (resultType == ResultType.Success)
                {
                    ++successCount;
                    continue;
                }

                if (resultType == ResultType.Running)
                {
                    continue;
                }
            }

            if (resultType != ResultType.Fail)
            {
                resultType = (successCount >= nodeChildList.Count) ? ResultType.Success : ResultType.Running;
            }

            return(resultType);
        }
Exemple #17
0
 public override ResultType Execute()
 {
     NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);
     return(iAction.DoAction());
 }