public bool SwitchState(KalachingStates newState)
        {
            bool switchSuccess = false;

            if (states != null && states.ContainsKey(newState))
            {
                if (currentState == null)
                {
                    currentState = states [newState];
                    currentState.Start();
                    switchSuccess = true;
                }
                else if (currentState.AllowTransition(newState))
                {
                    currentState.End();
                    currentState = states [newState];
                    currentState.Start();
                    switchSuccess = true;
                }
                else
                {
                    Debug.Log(string.Format("{0} does not allow transition to {1}", currentState.State, newState));
                }
            }

            if (switchSuccess)
            {
                // Updating state history
                                #if UNITY_EDITOR
                if (prevGameState != null)
                {
                    prevGameState.Add(newState);
                    if (prevGameState.Count > 20)
                    {
                        prevGameState.RemoveAt(0);
                    }
                }
                                #endif

                if (this.OnStatePreSwitchEvent != null)
                {
                    this.OnStatePreSwitchEvent(newState);
                }
            }
            else
            {
                Debug.Log("States dictionary not ready for switching to " + newState);
            }

            return(switchSuccess);
        }
        public KalachingStateMachine(GameManager manager)
        {
            states = new Dictionary <KalachingStates, KalachingState_Base <KalachingStates> > ();

            Kalaching_Loading loading = new Kalaching_Loading(manager);
            Kalaching_InGame  inGame  = new Kalaching_InGame(manager);
            Kalaching_Exit    exit    = new Kalaching_Exit(manager);

            states.Add(loading.State, (KalachingState_Base <KalachingStates>)loading);
            states.Add(inGame.State, (KalachingState_Base <KalachingStates>)inGame);
            states.Add(exit.State, (KalachingState_Base <KalachingStates>)exit);

            currentState = loading;
            currentState.Start();

            prevGameState = new List <KalachingStates> ();
            prevGameState.Add(currentState.State);
        }