Exemplo n.º 1
0
        public bool?SetState(BasicState nextState, bool forced = false)
        {
            if (nextState == currentState)
            {
                return(null);
            }

            if (forced || nextState.CanEnter())
            {
                failedState   = null;
                previousState = currentState;
                currentState  = nextState;

                if (previousState.OnExit != null)
                {
                    previousState.OnExit();
                }
                if (OnChange != null)
                {
                    OnChange(previousState.idx);
                }
                if (nextState.OnEnter != null)
                {
                    nextState.OnEnter();
                }
                return(true);
            }
            failedState = nextState;
            return(false);
        }
Exemplo n.º 2
0
        public virtual void Initialize(System.Type eType)
        {
            enumType = eType;
            System.Array eVals = System.Enum.GetValues(enumType);
            int          count = eVals.Length;

            stateList = new List <BasicState>(count);

            for (int i = 0; i < count; ++i)
            {
                object enumValue = eVals.GetValue(i);
                stateList.Add(new BasicState(i, enumValue, System.Enum.GetName(enumType, enumValue)));
            }
            previousState = stateList[0];
            currentState  = stateList[0];
            failedState   = null;
            isInitialized = true;
        }
Exemplo n.º 3
0
 public void ClearPreviousState()
 {
     previousState = stateList[0];
 }