Ejemplo n.º 1
0
 public void Execute()
 {
     if (null != _rootNode)
     {
         _rootNode.Execute();
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public override ResultType Execute()
        {
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);

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

            return(_constResult);
        }
 public void Execute()
 {
     if (null != _rootNode)
     {
         _rootNode.Preposition();
         ResultType resultType = _rootNode.Execute();
         _rootNode.Postposition(resultType);
     }
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void Execute()
        {
            if (BehaviorManager.Instance.PlayType == BehaviorPlayType.STOP)
            {
                return;
            }

            if (BehaviorManager.Instance.PlayType == BehaviorPlayType.PAUSE)
            {
                return;
            }

            if (null != _rootNode)
            {
                _rootNode.Execute();
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }