Exemplo n.º 1
0
        public void GoToState(FiniteState newFiniteState)
        {
            if (currentFiniteState != null)
            {
                currentFiniteState.Exit();
            }

            if (newFiniteState != null)
            {
                newFiniteState.Enter();
            }

            currentFiniteState = newFiniteState;
        }
Exemplo n.º 2
0
        // as long as this is not called multiple times a frame, this tradeoff of efficiency for flexibility has proven to be worth it (ted)
        public void GoToState(string stateName)
        {
            stateName = stateName.ToLower();
            FiniteState targetState = null;

            foreach (FiniteState finiteState in finiteStates)
            {
                if (finiteState.GetType().ToString().ToLower().Equals(stateName))
                {
                    targetState = finiteState;
                    break;
                }
            }

            if (targetState != null)
            {
                GoToState(targetState);
            }
            else
            {
                Debug.LogError("FiniteStateController could not find state named '" + stateName + "'");
            }
        }