Пример #1
0
    public void AddAction(MtAction action, Transform target, bool paused)
    {
        Debug.Assert(action != null, "action can't be null!");
        Debug.Assert(target != null, "target can't be null!");
        if (action == null || target == null)
        {
            return;
        }

        MtActionElement element = null;

        if (!m_dicActionElement.ContainsKey(target))
        {
            element         = new MtActionElement();
            element.paused  = paused;
            element.target  = target;
            element.actions = new ArrayList();
            LinkedListNode <MtActionElement> listNode = new LinkedListNode <MtActionElement>(element);
            m_dicActionElement.Add(target, listNode);
            m_targets.AddLast(listNode);
        }
        else
        {
            element = m_dicActionElement[target].Value;
        }
//		Debug.Assert(!element.actions.Contains(action), "Action already be added!");
        if (!element.actions.Contains(action))
        {
            element.actions.Add(action);
            action.StartWithTarget(target);
        }
    }
Пример #2
0
    public MtAction GetActionByTag(int tag, Transform target)
    {
        Debug.Assert(tag != MtAction.INVALID_TAG, "Invalid tag value!");
        Debug.Assert(target != null, "target can't be null!");
        if (target == null || !m_dicActionElement.ContainsKey(target))
        {
            return(null);
        }

        LinkedListNode <MtActionElement> element = m_dicActionElement[target];

        if (element != null)
        {
            int count = element.Value.actions.Count;
            for (int i = 0; i < count; i++)
            {
                MtAction action = element.Value.actions[i] as MtAction;
                if (action.Tag == tag && action.Target.Equals(target))
                {
                    return(action);
                }
            }
        }
        return(null);
    }
Пример #3
0
    public void RemoveAction(MtAction action)
    {
        if (action == null)
        {
            return;
        }
        Transform tf = action.Target;

        if (m_dicActionElement.ContainsKey(tf))
        {
            LinkedListNode <MtActionElement> element = m_dicActionElement[tf];
            int index = element.Value.actions.IndexOf(action);
            RemoveActionAtIndex(index, element);
        }
    }
Пример #4
0
    public void RemoveActionAtIndex(int index, LinkedListNode <MtActionElement> element)
    {
        MtAction action = element.Value.actions[index] as MtAction;

        action.Stop();
        element.Value.actions.RemoveAt(index);
        if (element.Value.actionIndex >= index)
        {
            element.Value.actionIndex--;
        }
        if (element.Value.actions.Count == 0)
        {
            m_dicActionElement.Remove(action.Target);
            LinkedListNode <MtActionElement> nodeTemp = element.Next;
            m_targets.Remove(element);
            m_currentTarget = nodeTemp;
        }
    }
Пример #5
0
    /** Main loop of ActionManager.
     * @param dt    In seconds.
     */
    public void Update(float deltaTime)
    {
        for (m_currentTarget = m_targets.First; m_currentTarget != null;)
        {
            if (!m_currentTarget.Value.paused)
            {
                // The 'actions' ArrayList may change while inside this loop.
                for (m_currentTarget.Value.actionIndex = 0; m_currentTarget.Value.actionIndex < m_currentTarget.Value.actions.Count; m_currentTarget.Value.actionIndex++)
                {
                    m_currentTarget.Value.currentAction = m_currentTarget.Value.actions[m_currentTarget.Value.actionIndex] as MtAction;
                    if (m_currentTarget.Value.currentAction == null)
                    {
                        continue;
                    }

                    m_currentTarget.Value.currentAction.Step(deltaTime);

                    if (m_currentTarget.Value.currentAction.IsDone())
                    {
                        m_currentTarget.Value.currentAction.Stop();
                        MtAction action = m_currentTarget.Value.currentAction;
                        //Make currentAction null to prevent removeAction from salvaging it.
                        m_currentTarget.Value.currentAction = null;
                        RemoveAction(action);
                    }
                    if (m_currentTarget != null)
                    {
                        m_currentTarget.Value.currentAction = null;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (m_currentTarget != null)
            {
                m_currentTarget = m_currentTarget.Next;
            }
        }
        m_currentTarget = null;
    }
Пример #6
0
 public static void RunAction(this Transform trans, MtAction action)
 {
     Debug.Assert(action != null, "MtAction must be non-nil");
     MtActionManager.Instance.AddAction(action, trans, false);
 }
Пример #7
0
 public static void StopAction(this Transform trans, MtAction action)
 {
     Debug.Assert(action != null, "MtAction must be non-nil");
     MtActionManager.Instance.StopAction(action);
 }
Пример #8
0
 public void StopAction(MtAction action)
 {
     RemoveAction(action);
 }