예제 #1
0
        /// <summary>
        /// 并行节点同时执行所有节点,直到一个节点返回 Fail 或者全部节点都返回 Success
        /// 才向父节点返回 Fail 或者 Success,并终止执行其他节点
        /// 其他情况向父节点返回 Running
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            int successCount = 0;

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

                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);
        }
예제 #2
0
        /// <summary>
        /// 选择节点依次遍历所有子节点,如果都返回 Fail,则向父节点返回 Fail
        /// 直到一个节点返回 Success 或者 Running,停止后续节点的执行,向父节点
        /// 返回 Success 或者 Running
        /// 注意:如果节点返回 Running 需要记住这个节点,下次直接从此节点开始执行
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            int index = 0;

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

            ResultType resultType = ResultType.Fail;

            for (int i = index; i < nodeChildList.Count; ++i)
            {
                NodeRoot nodeRoot = nodeChildList[i];
                resultType = nodeRoot.Run();
                if (resultType == ResultType.Fail)
                {
                    continue;
                }

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

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

            return(resultType);
        }
예제 #3
0
        /// <summary>
        /// 修饰节点只有一个子节点,执行子节点直到 执行结果 = untilResultType,将 结果返回给父节点
        /// 如果执行结果 != untilResultType 则返回 Running
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            NodeRoot   nodeRoot   = nodeChildList[0];
            ResultType resultType = nodeRoot.Run();

            if (resultType != untilResultType)
            {
                return(ResultType.Running);
            }

            return(resultType);
        }