コード例 #1
0
 /// <summary>
 /// Agrega un estado.
 /// </summary>
 /// <param name="s">El estado a agregar.</param>
 protected void AddState(IStateMono s)
 {
     _states.Add(s);
     if (_currentState == null)
     {
         _currentState = s;
     }
 }
コード例 #2
0
 /// <summary>
 /// Cambia de estado.
 /// </summary>
 public void SetState <T>() where T : IStateMono
 {
     for (int i = 0; i < _states.Count; i++)
     {
         if (_states[i].GetType() == typeof(T))
         {
             _currentState.StateSleep();
             _currentState = _states[i];
             _currentState.StateAwake();
         }
     }
 }
コード例 #3
0
 public void SetStateByName(string name)
 {
     for (int i = 0; i < _states.Count; i++)
     {
         if (_states[i].GetStateName() == name)
         {
             _currentState.StateSleep();
             _currentState = _states[i];
             _currentState.StateAwake();
         }
     }
 }
コード例 #4
0
    protected virtual void Awake()
    {
        IStateMono[] allStates = GetComponents <IStateMono>();
        for (int i = 0; i < allStates.Length; i++)
        {
            AddState(allStates[i]);
        }
        if (_states.Count == 0)
        {
            Debug.LogError("RECUERDE AGREGAR AL OBJETO AL MENOS UN ESTADO");
            Debug.LogError("#####");
            Debug.LogError("REMEMBER AT LEAST ATTACH ONE STATE TO THE OBJECT");
            throw new MissingComponentException();
        }

        _currentState = FindStateByName(defaultState);
        if (_currentState == null)
        {
            _currentState = _states[0];
        }
    }