Exemple #1
0
        public int AddAction(IAction action, int groupId, ActionObject actionObject = null)
        {
            if (action == null)
            {
                this.LogError("action can't be null");
            }

            m_hashElement element;

            if (!m_targets.TryGetValue(groupId, out element))
            {
                element = new m_hashElement
                {
                    paused   = false,
                    groupId  = groupId,
                    target   = actionObject,
                    safeMode = actionObject != null,
                };
                m_targets.Add(groupId, element);
            }
            action.GroupID = groupId;
            action.StartWithTarget();
            element.actions.Add(action);
            return(groupId);
        }
        private void OnUpdate(float dt)
        {
            m_deletes.Clear();
            foreach (var item in m_targets)
            {
                if (item.Key.Equals(null))
                {
                    m_targets.Remove(item.Key);
                    continue;
                }
                m_currentTarget         = item.Value;
                m_currentTargetSalvaged = false;
                if (!m_currentTarget.paused)
                {
                    m_currentTarget.actionIndex = 0;
                    while (m_currentTarget.actionIndex < m_currentTarget.actions.Count)
                    {
                        m_currentTarget.currentAction = m_currentTarget.actions[m_currentTarget.actionIndex];
                        if (m_currentTarget.currentAction == null)
                        {
                            continue;
                        }
                        // The 'actions' MutableArray may change while inside this loop
                        m_currentTarget.currentActionSalvaged = false;

                        m_currentTarget.currentAction.Step(dt);

                        if (m_currentTarget.currentActionSalvaged)
                        {
                            // The currentAction told the node to remove it. To prevent the action from
                            // accidentally deallocating itself before finishing its step, we retained
                            // it. Now that step is done, it's safe to release it.
                            m_currentTarget.currentAction = null;
                        }
                        else if (m_currentTarget.currentAction.IsDone())
                        {
                            m_currentTarget.currentAction.Stop();
                            var action = m_currentTarget.currentAction;
                            // Make currentAction nil to prevent removeAction from salvaging it.
                            m_currentTarget.currentAction = null;
                            // 删除已经做是否在循环的判断,无须m_currentTarget.actionIndex--
                            RemoveAction(action);
                        }
                        m_currentTarget.currentAction = null;
                        m_currentTarget.actionIndex++;
                    }
                }
                if (m_currentTargetSalvaged && m_currentTarget.actions.Count == 0)
                {
                    m_deletes.Add(item.Key);
                }
            }

            foreach (var target in m_deletes)
            {
                m_targets.Remove(target);
            }
        }
        public void AddAction(CCAction action, Transform target, bool paused = false)
        {
            if (action == null)
            {
                this.LogError("action can't be null");
            }
            if (target == null)
            {
                this.LogError("target can't be null");
            }
            m_hashElement element;

            if (!m_targets.TryGetValue(target, out element))
            {
                element = new m_hashElement
                {
                    paused = paused,
                    target = target
                };
                m_targets.Add(target, element);
            }
            action.StartWithTarget(target);
            element.actions.Add(action);
        }