/// <summary> /// This method places new states inside the FSM, /// or prints an ERROR message if the state was already inside the List. /// First state added is also the initial state. /// </summary> public void AddState(EnemyFSMState s) { // Check for Null reference before deleting if (s == null) { Debug.LogError("EnemyFSM ERROR: Null reference is not allowed"); } // First State inserted is also the Initial state, // the state the machine is in when the simulation begins if (states.Count == 0) { states.Add(s); currentState = s; currentStateID = s.ID; return; } // Add the state to the List if it's not inside it foreach (EnemyFSMState state in states) { if (state.ID == s.ID) { Debug.LogError("EnemyFSM ERROR: Impossible to add state " + s.ID.ToString() + " because state has already been added"); return; } } states.Add(s); }
/// <summary> /// 执行转换状态 /// </summary> /// <param name="trans"></param> public void PerformTranstion(EnemyTransition trans) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("要执行的转换条件为空!"); return; } EnemyStateID nextStateID = mCurrentState.GetOutPutStateID(trans); //得到该转换条件下的下个状态ID if (nextStateID == EnemyStateID.NullStateID) { Debug.LogError("在转换条件:" + "[" + trans + "]" + "没有对应的转换状态!"); return; } mCurrentStateID = nextStateID;//更新当前状态ID foreach (IEnemyState s in mStates) { if (s.stateID == nextStateID) { mCurrentState.DoBeforeLeaving(); mCurrentState = s; //更新当前状态 mCurrentState.DoBeforeEntering(); break; } } }
public void PerformnTransition(EnemyTransition trans) { if (trans == EnemyTransition.NullTransition) { Debug.Log("PerformnTransition 无法执行 NullTransition "); return; } EnemyStateID id = CurrentEnemyState.GetIDByTransition(trans); if (id == EnemyStateID.NullState) { Debug.Log("PerformnTransition 无法执行 NullState "); return; } foreach (AbsEnemyState s in statesList) { if (s.StateID == id) { CurrentEnemyState.DoBeforeLeaving(); CurrentEnemyState = s; CurrentEnemyState.DoBeforeEntering(); } } }
public void PerformTransition(EnemyTransition trans) { if (trans == EnemyTransition.NullTansition) { Debug.LogError("要执行的转换条件不能为Null"); return; } EnemyStateID nextStateID = mCurrentState.GetOutputState(trans); if (nextStateID == EnemyStateID.NullState) { Debug.LogError("在转换条件 [" + trans + " ]下,没有对应的转换状态"); return; } foreach (IEnemyState s in mStates) { if (s.stateID == nextStateID) { mCurrentState.DoBeforeEntering(); mCurrentState = s; mCurrentState.DoBeforeEntering(); return; } } }
/// <summary> /// 添加状态,并设置第一个添加的为初始状态 /// </summary> /// <param name="state"></param> public void AddState(IEnemyState state) { if (state == null) { Debug.LogError("添加的状态为空!"); return; } if (mStates.Count == 0) { mStates.Add(state); mCurrentState = state; mCurrentStateID = state.stateID; mCurrentState.DoBeforeEntering(); return; } foreach (IEnemyState s in mStates) { if (s.stateID == state.stateID) { Debug.LogError("要添加的状态ID:" + "[" + s.stateID.ToString() + "]" + "已经添加了"); return; } } mStates.Add(state); }
public void PerformTrnsition(EnemyTransition trans) { if (trans == EnemyTransition.NullTansition) { Debug.LogError(GetType() + "/PerformTrnsition()/ trans is NullTansition "); return; } EnemyStateID nextStateId = mCurState.GetOutputState(trans); if (nextStateId == EnemyStateID.NullState) { Debug.LogError(GetType() + "/PerformTrnsition()/ stateId is NullState "); return; } foreach (IEnemyState s in mStateLst) { if (s.StateID == nextStateId) { mCurState.DoBeforeLeaving(); mCurState = s; mCurState.DoBeforeEntering(); } } }
// Add New State into the list public void AddFSMState(FSMState fsmState) { // Check for Null reference before deleting if (fsmState == null) { Debug.LogError("FSM ERROR: Null reference is not allowed"); } // First State inserted is also the Initial state // the state the machine is in when the simulation begins if (fsmStatelist.Count == 0) { fsmStatelist.Add(fsmState); currentState = fsmState; currentStateID = fsmState.ID; return; } // Add the state to the List if it´s not inside it foreach (FSMState state in fsmStatelist) { if (state.ID == fsmState.ID) { Debug.LogError("FSM ERROR: Trying to add a state that was already inside the list"); return; } } //If no state in the current then add the state to the list fsmStatelist.Add(fsmState); }
public void performTransition(EnemyTransition trans) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("trans is null"); return; } EnemyStateID nextId = mCurrState.getOutPutState(trans); if (nextId == EnemyStateID.NullState) { Debug.LogError("no state with trans"); return; } foreach (IEnemyState s in mStates) { if (s.StateID == nextId) { mCurrState.doBeforeLeaving(); mCurrState = s; mCurrState.doBeforeEntering(); return; } } }
public void PerformTransition(EnemyTransition trans) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("要执行的转换条件为空"); return; } //获取要转换为的状态 EnemyStateID nextStateID = mCurrentState.GetOutPutState(trans); if (nextStateID == EnemyStateID.NullState) { Debug.Log("要转换的状态ID[" + nextStateID + "]为空"); return; } foreach (IEnemyState state in mStates) { //如果在集合中找到转换为的状态 if (state.StateID == nextStateID) { //执行退出当前状态之前的操作 mCurrentState.DoBeforeLeaving(); //将当前状态变为将转换的状态 mCurrentState = state; //执行进入当前状态之前的操作 mCurrentState.DoBeforeEntering(); break; } } }
//执行状态转换 public void PerformTransition(EnemyTransition trans) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("转换条件不能为空"); return; } EnemyStateID nextId = currentState.GetOutputState(trans); if (nextId == EnemyStateID.NullStateID) { Debug.LogError("转换的状态不能为空"); return; } foreach (EnemyState state in states) { if (state.ID != nextId) { continue; } currentState.DoBeforeLeaving(); //转换前执行现有状态的DoBeforeLeaving方法 currentState = state; currentState.DoBeforeEntering(); //转换完成,执行转换后状态的DoBeforeEntering方法 return; } }
public void PerformTransition(Transition trans) { // Check for NullTransition before changing the current state if (trans == Transition.None) { Debug.LogError("FSM ERROR: Null transition is not allowed"); return; } // Check if the currentState has the transition passed as argument EnemyStateID id = currentState.GetOutputState(trans); if (id == EnemyStateID.None) { Debug.LogError("FSM ERROR: Current State does not have a target state for this transition"); return; } // Update the currentStateID and currentState currentStateID = id; foreach (FSMState state in fsmStatelist) { if (state.ID == currentStateID) { currentState = state; break; } } }
public void AddTransition(EnemyTransition trans, EnemyStateID id) { // Check if anyone of the args is invalid if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyFSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (id == EnemyStateID.NullStateID) { Debug.LogError("EnemyFSMState 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 (map.ContainsKey(trans)) { Debug.LogError("EnemyFSMState ERROR: State " + stateID.ToString() + " already has transition " + trans.ToString() + "Impossible to assign to another state"); return; } map.Add(trans, id); }
public void DeleteTransition(EnemyTransition trans, EnemyStateID id) { if (!mMap.ContainsKey(trans)) { Debug.LogError("删除转换条件的时候,转换条件: " + trans + " 不存在"); return; } mMap.Remove(trans); }
public void DeleteTransition(EnemyTransition trans, EnemyStateID id) { if (!map.ContainsKey(trans)) { Debug.Log("EnemyState StateID:" + StateID + " Error :" + trans + "不存在,无法删除"); return; } map.Remove(trans); }
public EnemyStateID GetIDByTransition(EnemyTransition trans) { EnemyStateID id = EnemyStateID.NullState; if (!map.TryGetValue(trans, out id)) { Debug.Log("EnemyState StateID:" + StateID + " Error :" + trans + "不存在,无法查找"); } return(id); }
public EnemyStateID GetOutputState(EnemyTransition trans) { EnemyStateID id = EnemyStateID.NullState; if (mMap.ContainsKey(trans)) { //mMap.TryGetValue(trans, out id); id = mMap[trans]; } return(id); }
//从系统中删除状态 public void DeleteState(EnemyStateID id) { foreach (EnemyState state in states) { if (state.ID != id) { continue; } states.Remove(state); return; } Debug.LogError("删除的状态不存在" + id); }
public void DeleteState(EnemyStateID stateID) { if (stateID == EnemyStateID.NullState) { Debug.LogError("要删除的状态ID为空" + stateID); return; } foreach (IEnemyState s in mStates) { if (s.stateID == stateID) { mStates.Remove(s); return; } } Debug.LogError("要删除的StateID不存在集合中:" + stateID); }
public void DeleteState(EnemyStateID stateID) { if (stateID == EnemyStateID.NullState) { Debug.LogError("EnemyFSMSystem Error: 要删除的状态为空"); return; } foreach (IEnemyState s in mStates) { if (s.StateID == stateID) { mStates.Remove(s); return; } } Debug.LogError("EnemyFSMSystem Error: 要删除的状态" + stateID + "不存在"); return; }
public void DeleteState(EnemyStateID stateID) { if (stateID == EnemyStateID.NullState) { return; } foreach (IEnemyState s in mStates) { if (s.stateID == stateID) { mStates.Remove(s); return; } } }
public void AddTransition(EnemyTransition trans, EnemyStateID stateID) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyStateID Error : trans����Ϊ��"); } if (stateID == EnemyStateID.NullState) { Debug.LogError("EnemyStateID Error:id״̬Id����Ϊ��"); } if (map.ContainsKey(trans)) { Debug.LogError("EnemyStateID Error " + trans + "�Ѿ������"); } map.Add(trans, stateID); }
public void AddTransition(EnemyTransition trans, EnemyStateID id) { if (trans == EnemyTransition.NullTansition) { Debug.LogError("EnemyState Error: trans不能为空"); return; } if (id == EnemyStateID.NullState) { Debug.LogError("EnemyState Error: 状态ID不能为空"); return; } if (mMap.ContainsKey(trans)) { Debug.LogError("EnemyState Error: " + trans + " 已经添加上了"); return; } mMap.Add(trans, id); }
public void DeleteState(EnemyStateID stateID) { if (stateID == EnemyStateID.NullState) { Debug.LogError("Ҫɾ����״̬IDΪ��" + stateID); } foreach (IEnemyState enemyState in mStates) { if (enemyState.StateID == stateID) { mStates.Remove(enemyState); return; } } Debug.LogError("Ҫɾ����stateID�������ڼ�����" + stateID); }
public void AddTransition(EnemyTransition trans, EnemyStateID id) { if (trans == EnemyTransition.NullTansition) { return; } if (id == EnemyStateID.NullState) { return; } if (mMap.ContainsKey(trans)) { return; } mMap.Add(trans, id); }
public void AddTransition(EnemyTransition trans, EnemyStateID stateID) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyState Error: trans 不能为空"); return; } if (stateID == EnemyStateID.NullState) { Debug.LogError("EnemyState Error: stateID 不能为空"); return; } if (m_Map.ContainsKey(trans)) { Debug.LogError("EnemyState Error: " + trans + " 已经添加上了"); return; } m_Map.Add(trans, stateID); }
public void deleteState(EnemyStateID id) { if (id == EnemyStateID.NullState) { Debug.LogError("id is null"); return; } foreach (IEnemyState s in mStates) { if (s.StateID == id) { mStates.Remove(s); return; } } Debug.LogError("id is not exist"); }
public void AddTransition(EnemyTransition trans, EnemyStateID id) { if (trans == EnemyTransition.NullTransition) { Debug.Log("EnemyState Error :trans 不能为空"); return; } if (id == EnemyStateID.NullState) { Debug.Log("EnemyState Error :id 不能为空"); return; } if (map.ContainsKey(trans)) { Debug.Log("EnemyState Error :" + trans + "已经存在,不能添加"); } map.Add(trans, id); }
/// <summary> /// 删除状态 /// </summary> /// <param name="stateID"></param> public void DeleteState(EnemyStateID stateID) { if (stateID == EnemyStateID.NullState) { Debug.LogError("状态为空,不删除 " + stateID); return; } foreach (var s in mLst_States) { if (s.StateID == stateID) { mLst_States.Remove(s); return; } } Debug.LogError("要删除的ID不存在于集合中 id = " + stateID); }
public void DeleteState(EnemyStateID id) { if (id == EnemyStateID.NullState) { Debug.Log("DeleteState 无法删除 NullState "); return; } for (int i = 0; i < statesList.Count; i++) { if (statesList[i].StateID == id) { statesList.RemoveAt(i); return; } } Debug.Log("DeleteState" + id + " 不存在 无法删除"); }
public void addTransition(EnemyTransition trans, EnemyStateID id) { if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyState Error:trans can't null"); return; } if (id == EnemyStateID.NullState) { Debug.LogError("EnemyState Error:id can't null"); return; } if (map.ContainsKey(trans)) { Debug.LogError("EnemyState Error" + trans + "is already add"); return; } map.Add(trans, id); }