Esempio n. 1
0
 public void Activate(object eventData)
 {
     if (mStartState != null)
     {
         mActiveState = mStartState;
     }
     else if(mStates.Count > 0)
     {
         mActiveState = mStates[0];
     }
     if (mActiveState != null)
     {
         mActiveState.Activate(eventData);
     }
 }
Esempio n. 2
0
        public void Activity(float dt)
        {
            if(mActiveState == null)
            {
                return;
            }

            while (mEventQueue.Count > 0)
            {
                StateEvent stateEvent = mEventQueue.Dequeue();

                // can we transition
                if (mTransitionTable[mActiveState].ContainsKey(stateEvent.mEventID))
                {
                    mActiveState.Deactivate();

                    mActiveState = mTransitionTable[mActiveState][stateEvent.mEventID];

                    // dequeue any remaining events, invalid
                    mEventQueue.Clear();

                    mActiveState.Activate(stateEvent.mEventData);

                    // activation may enque new events allowing double transition
                    // do not simply break
                }
                else
                {
                    Debug.WriteLine("WTF, event not handled");
                }
            }

            if (mActiveState != null)
            {
                mActiveState.Update(dt);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="eventID"></param>
 /// <param name="fromState"></param>
 /// <param name="toState"></param>
 public void AddTransition(int eventID, State fromState, State toState)
 {
     mTransitionTable[fromState].Add(eventID, toState);
 }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        public void AddState(State state)
        {
            mStates.Add(state);

            mTransitionTable.Add(state, new Dictionary<int, State>());
        }