Exemplo n.º 1
0
        public void ChangeState(TransitionEnum trans)
        {
            if (trans == TransitionEnum.Null)
            {
                Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition");
                return;
            }

            StateEnum nextState = currentState.GetOutputState(trans);

            if (nextState == StateEnum.Null)
            {
                Debug.LogError("FSM ERROR: State " + currentStateEnum.ToString() + " does not have a target state " +
                               " for transition " + trans.ToString());
                return;
            }

            currentStateEnum = nextState;

            if (!stateDic.ContainsKey(nextState))
            {
                Debug.LogError("FSM ERROR: State " + currentStateEnum.ToString() + " does not have a target state " +
                               " for transition " + trans.ToString());
                return;
            }

            currentState.OnLeaveState();

            //Debug.LogError("上一个状态已经离开 " + currentState.StateName.ToString());

            currentState = stateDic[nextState];

            //Debug.LogError("下一个状态即将进入 " + currentState.StateName.ToString());

            currentState.OnEnterState();
        }
Exemplo n.º 2
0
        public void RemoveTransition(TransitionEnum trans)
        {
            if (trans == TransitionEnum.Null)
            {
                Debug.LogError("FSMState ERROR: NullTransition is not allowed");
                return;
            }

            if (stateDic.ContainsKey(trans))
            {
                stateDic.Remove(trans);
            }
            else
            {
                Debug.LogError("FSMState ERROR: Transition " + trans.ToString() + " passed to " + stateName.ToString() + " was not on the state's transition list");
            }
        }
Exemplo n.º 3
0
        public void AddTransition(TransitionEnum trans, StateEnum stateName)
        {
            if (trans == TransitionEnum.Null)
            {
                Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real transition");
                return;
            }

            if (stateName == StateEnum.Null)
            {
                Debug.LogError("FSMState ERROR: NullStateID is not allowed for a real ID");
                return;
            }

            if (stateDic.ContainsKey(trans))
            {
                Debug.LogError("FSMState ERROR: State " + this.stateName.ToString() + " already has transition " + trans.ToString() +
                               "Impossible to assign to another state");
                return;
            }

            stateDic.Add(trans, stateName);
        }