Ejemplo n.º 1
0
        protected override EnumResult OnUpdate()
        {
            if (_contenNodeList.Count == 0)
            {
                return(EnumResult.Success);
            }
            //Run
            for (int i = 0; i < _contenNodeList.Count; i++)
            {
                if (i >= _contenNodeList.Count)
                {
                    break;
                }
                EnumResult result = _contenNodeList[i].Tick(this);

                if (result != EnumResult.Running)
                {
                    if (i >= _contenNodeList.Count)
                    {
                        break;
                    }
                    NodeModifier node = _contenNodeList[i];

                    if (result == EnumResult.Failed)
                    {
                        switch (node.RunMode)
                        {
                        case EnumRunMode.UntilSuccess:
                            continue;

                        case EnumRunMode.ReturnParentNode:
                            _toRemoveNode.Add(node);
                            _toAddNode.Add(node.Parent);
                            continue;

                        case EnumRunMode.StopNodeList:
                            _toRemoveNode.Add(node);
                            continue;
                        }
                    }

                    _toRemoveNode.Add(node);

                    //单独处理Decorator节点运行
                    //仅运行非单节点
                    //if (node is Decorator)
                    //{
                    //    NodeModifier child = System.Array.Find<NodeModifier>(node.NextNodes, (n) => n.Parent == node);
                    //    if (child != null)
                    //        _toAddNode.Add(child);
                    //}
                    //else
                    node.GetNextNodes(_toAddNode);
                }
            }
            //UnityEngine.Profiler.EndSample();

            ProcessNode();

            return(EnumResult.Running);
        }