/// <summary> /// 添加切换的状态. /// </summary> /// <param name="trans">Trans.</param> /// <param name="stateID">State I.</param> public void AddTransition(EBehaviourTransition trans, EBehaviourStateID stateID) { // 不要传空的进来哦. if (trans == EBehaviourTransition.None) { Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (stateID == EBehaviourStateID.None) { Debug.LogError("FSMState ERROR: NullStateID is not allowed for a real ID"); return; } // Since this is a Deterministic FSM, // check if the current transition was already inside the map if (TransitionMap.ContainsKey(trans)) { Debug.LogError("FSMState ERROR: State " + stateID.ToString() + " already has transition " + trans.ToString() + "Impossible to assign to another state"); return; } TransitionMap.Add(trans, stateID); }
/// <summary> /// This method delete a state from the FSM List if it exists, /// or prints an ERROR message if the state was not on the List. /// </summary> public void DeleteState(EBehaviourStateID id) { // Check for NullState before deleting if (id == EBehaviourStateID.None) { Debug.LogError("FSM ERROR: NullStateID is not allowed for a real state"); return; } // Search the List and delete the state if it's inside it foreach (BehaviourState state in _States) { if (state.ID == id) { _States.Remove(state); return; } } Debug.LogError("FSM ERROR: Impossible to delete state " + id.ToString() + ". It was not on the list of states"); }
/// <summary> /// 删除转换. /// </summary> /// <param name="trans">Trans.</param> public void DeleteTransition(EBehaviourTransition trans) { // 不要传空的进来哦. if (trans == EBehaviourTransition.None) { Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real transition"); return; } // Check if the pair is inside the map before deleting if (TransitionMap.ContainsKey(trans)) { TransitionMap.Remove(trans); return; } Debug.LogError("FSMState ERROR: Transition " + trans.ToString() + " passed to " + _StateID.ToString() + " was not on the state's transition list"); }