public bool ChangeState(FSMState <T> NewState, bool forceChange) { if (NewState == CurrentState && !forceChange) { return(false); } #if DEBUG_STATES_ALL MessengerDebug.print("FSM(" + typeof(T) + "):Change State " + CurrentState + " to " + NewState); #endif PreviousState = CurrentState; CurrentState = NewState; if (PreviousState != null) { PreviousState.Exit(Owner); } if (CurrentState != null) { CurrentState.Enter(Owner); } return(true); }
static public void Invoke(string eventType) { #if DEBUG_EVENTS_ALL MessengerDebug.print("Event: " + eventType + "\n" + Environment.StackTrace); #endif Delegate d; // Invoke the delegate only if the event type is in the dictionary. if (eventTable.TryGetValue(eventType, out d)) { // Take a local copy to prevent a race condition if another thread // were to unsubscribe from this event. Callback callback = (Callback)d; // Invoke the delegate if it's not null. if (callback != null) { callback(); } } }