Ejemplo n.º 1
0
        /// <summary>
        /// 停止整个技能中对应节点的运行
        /// </summary>
        /// <param name="nodeIdList"></param>
        public void StopNodes(List <int> nodeIdList)
        {
            if (nodeIdList == null || nodeIdList.Count == 0)
            {
                return;
            }

            if (runningNodeList.Count == 0)
            {
                return;
            }

            for (int i = runningNodeList.Count - 1; i >= 0; i--)
            {
                NodeBase node = runningNodeList[i];
                for (int j = 0; j < nodeIdList.Count; j++)
                {
                    int targetId = nodeIdList[j];
                    if (node.nodeId == targetId)
                    {
                        node.OnExit();
                        runningNodeList.RemoveAt(i);
                        break;
                    }
                }
            }

            for (int i = 0; i < runningChildSequenceList.Count; i++)
            {
                runningChildSequenceList[i].StopNodes(nodeIdList);
            }
        }
Ejemplo n.º 2
0
        public void Update(float deltaTime)
        {
            if (executeFinishNodeList.Count > 0)
            {
                for (int i = 0; i < executeFinishNodeList.Count; i++)
                {
                    NodeBase executeFinishNode = executeFinishNodeList[i];
                    executeFinishNode.OnExit();

                    if (runningNodeList.Contains(executeFinishNode))
                    {
                        runningNodeList.Remove(executeFinishNode);
                    }
                }

                executeFinishNodeList.Clear();
            }

            for (int i = 0; i < runningNodeList.Count; i++)
            {
                runningNodeList[i].OnUpdate(deltaTime);
            }

            if (runningChildSequenceList != null && runningChildSequenceList.Count > 0)
            {
                for (int i = runningChildSequenceList.Count - 1; i >= 0; i--)
                {
                    NodeSequence nodeSequence = runningChildSequenceList[i];
                    nodeSequence.Update(deltaTime);

                    if (nodeSequence.IsFinish)
                    {
                        nodeSequence.Reset();

                        if (childSequencePool == null)
                        {
                            childSequencePool = new Dictionary <int, Queue <NodeSequence> >();
                        }

                        //放回池中
                        if (childSequencePool.ContainsKey(nodeSequence.RootNode.nodeId))
                        {
                            Queue <NodeSequence> poolQueue = childSequencePool[nodeSequence.RootNode.nodeId];
                            if (poolQueue == null)
                            {
                                poolQueue = new Queue <NodeSequence>();
                            }

                            poolQueue.Enqueue(nodeSequence);
                        }
                        else
                        {
                            Queue <NodeSequence> poolQueue = new Queue <NodeSequence>();
                            poolQueue.Enqueue(nodeSequence);
                            childSequencePool.Add(nodeSequence.RootNode.nodeId, poolQueue);
                        }

                        runningChildSequenceList.RemoveAt(i);
                    }
                }
            }
        }