Exemplo n.º 1
0
        public void OnEnd()
        {
            if (m_CurrentState != null)
            {
                m_CurrentState.OnEnd();
            }
#if DEBUG_AI && UNITY_EDITOR
            Debug.Log("End StateMachine: " + m_Name + " @ " + m_TickCount);
#endif
            m_TickCount        = 0;
            m_CurrentState     = null;
            m_PrevState        = null;
            m_CurrentStateName = null;
            m_CurrentTransitions.Clear();
            m_Active = false;
        }
Exemplo n.º 2
0
        void ChangeState(Transition trans)
        {
            string toState = trans.m_ToState;
            bool   push    = true;

            if (string.IsNullOrEmpty(toState))
            {
                if (m_StateStack.Count > 0)
                {
                    toState = m_StateStack[m_StateStack.Count - 1];
                    m_StateStack.RemoveAt(m_StateStack.Count - 1);
                    push = false;
                }
                else
                {
                    return;
                }
            }
            if (toState == m_CurrentStateName)
            {
                return;
            }
            m_PrevState        = m_CurrentState;
            m_CurrentState     = null;
            m_CurrentStateName = toState;
            if (m_PrevState != null)
            {
                m_PrevState.OnEnd();
                // 入栈
                if (m_StackSize > 0 && push && m_PrevState.KeepInStack() && StateStackPeek != m_PrevState.GetName())
                {
                    int del = m_StateStack.Count + 1 - m_StackSize;
                    if (del > 0)
                    {
                        m_StateStack.RemoveRange(0, del);
                    }
                    m_StateStack.Add(m_PrevState.GetName());
                }
            }
            UpdateTransitions();
        }