Beispiel #1
0
        private void AddState()
        {
            GameObject newGo = new GameObject("New State");

            newGo.transform.SetParent(transform);

            StateMachineState state = newGo.AddComponent <StateMachineState>();

            States.Add(state);
            if (!StartingState)
            {
                StartingState = state;
            }
        }
Beispiel #2
0
        public void TransitionToState(StateMachineState newState)
        {
            UnityEngine.Debug.Assert(StateMachineStates.ContainsValue(newState),
                                     "The state is not present in the state machine, this surely will cause issues", this);

            if (newState == null)
            {
                newState = StartingState;
            }

            if (LogDebug)
            {
                UnityEngine.Debug.LogFormat(this, "Transition from state {0} to state {1}", CurrentState ? CurrentState.name : "None",
                                            newState.name);
            }

            if (CurrentState)
            {
                CurrentState.NotifyStateExit();
            }
            newState.NotifyStateEnter();
            CurrentState = newState;
        }
Beispiel #3
0
 public bool IsCurrentState(StateMachineState state)
 {
     return(CurrentState == state);
 }