/// <summary> /// 执行状态变换 /// </summary> public void PerformTransition(StateTriggerType trigger) { // Check for NullTransition before changing the current state if (trigger == StateTriggerType.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument var type = CurrentState.GetStateType(trigger); if (type == StateType.NullState) { Debug.LogErrorFormat("FSM ERROR: State {0} does not have a target state {1} for transition ", CurrentStateType.ToString(), trigger.ToString()); return; } #if UNITY_EDITOR Debug.LogFormat("<color=cyan> State translate {0} >>> {1} .</color>", CurrentStateType.ToString(), type.ToString()); #endif CurrentStateType = type; if (states.ContainsKey(CurrentStateType)) { var state = states[CurrentStateType]; CurrentState.BeforeLeaving(); CurrentState = state; CurrentState.BeforeEntering(); } }
public void AddTransition(StateTriggerType trans, StateType id) { // Check if anyone of the args is invalid if (trans == StateTriggerType.NullTransition) { Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (id == StateType.NullState) { Debug.LogError("FSMState ERROR: NullStateID is not allowed for a real ID"); return; } // check if the current transition was already inside the map if (map.ContainsKey(trans)) { Debug.LogErrorFormat("FSMState ERROR: State {0} already has transition {1} Impossible to assign to another state", StateType.ToString(), trans.ToString()); return; } map.Add(trans, id); }
public void DeleteTransition(StateTriggerType trans) { // Check for NullTransition if (trans == StateTriggerType.NullTransition) { Debug.LogError("FSMState ERROR: NullTransition is not allowed"); return; } // Check if the pair is inside the map before deleting if (map.ContainsKey(trans)) { map.Remove(trans); return; } Debug.LogErrorFormat("FSMState ERROR: Transition {0} passed to {1} was not on the state's transition list", trans.ToString(), StateType.ToString()); }