Ejemplo n.º 1
0
 /// <summary>
 /// Changes the state. Produces a warning if the state you are moving to does not comply with the mask of the current state, and then does nothing.
 /// </summary>
 /// <param name='stateName'>
 /// State name.
 /// </param>
 public void ChangeState(FiniteStateList stateName)
 {
     if (_currState != null)
     {
         FiniteState nextState = this[stateName.ToString()];
         if (_currState.CanTransitionToState(nextState) || _currState == nextState)
         {
             _currState.DeInit();
             _currState = this[stateName.ToString()];
             _currState.Init();
             history.Push(_currState);
             if (OnStateChangeEvent != null)
             {
                 OnStateChangeEvent();
             }
         }
         else
         {
             Debug.LogError("State \"" + _currState.name + "\" cannot transition to state \"" + nextState.name + "\". You should check your logic.");
         }
     }
     else
     {
         _currState = this[stateName.ToString()];
         _currState.Init();
         history.Push(_currState);
         history.Push(_currState);
         if (OnStateChangeEvent != null)
         {
             OnStateChangeEvent();
         }
     }
 }
Ejemplo n.º 2
0
	/// <summary>
	/// Unity method. 
	/// </summary>
	void Start()
	{
		InitializeStates();
		_currState = defaultState;
		if(_states.Count == 0)
		{
			Debug.LogError("No states!");
			return;
		}

		if(autoInit) 
			_currState.Init();
	}