public void AddTransition(RoleTransition trans, RoleStateID id) { //验证每个参数是否合法 if (trans == RoleTransition.NullTransition) { Debug.LogError("FSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (id == RoleStateID.NullStateID) { Debug.LogError("FSMState ERROR: NullStateID is not allowed for a real ID"); return; } //要知道这是一个确定的有限状态机(每个状态后对应一种状态,而不能产生分支) //检查当前的过渡是否已经在字典中了 if (map.ContainsKey(trans)) { Debug.LogError("FSMState ERROR: State " + stateID.ToString() + " already has transition " + trans.ToString() + "Impossible to assign to another state"); return; } map.Add(trans, id); }
public async Task <RoleTransition> Update(RoleTransition roleTransition) { _context.Entry(roleTransition); await _context.SaveChangesAsync(); return(roleTransition); }
public async Task <RoleTransition> Add(RoleTransition roleTransition) { _context.Transitions.Add(roleTransition); await _context.SaveChangesAsync(); return(roleTransition); }
//该方法用来改变有限状态机的状体,有限状态机基于当前的状态和通过的过渡状态。如果当前的状态没有用来通过的过度状态,则会抛出错误 public void SetTransition(RoleTransition t, Entity entity) { if (null != Fsm) { Fsm.SwitchTransition(t, entity); } }
/// <summary> /// 该方法在该状态接收到一个过渡时返回状态机需要成为的新状态 /// </summary> public RoleStateID GetOutputState(RoleTransition trans) { if (map.ContainsKey(trans)) { return(map[trans]); } return(RoleStateID.NullStateID); }
/// <summary> /// 这个方法用来在状态字典中删除transition-state对儿 /// 如果过渡并不存在于状态字典中,那么将会打印出一个错误 /// </summary> public void DeleteTransition(RoleTransition trans) { if (trans == RoleTransition.NullTransition) { Debug.LogError("FSMState ERROR: NullTransition is not allowed"); return; } //再删除之前确认该键值对是否存在于状态字典中(键值对集合) if (map.ContainsKey(trans)) { map.Remove(trans); return; } Debug.LogError("FSMState ERROR: Transition " + trans.ToString() + " passed to " + stateID.ToString() + " was not on the state's transition list"); }
/// <summary> /// 状态改变 /// </summary> public void SwitchTransition(RoleTransition trans, Entity entity) { //在改变当前状态前检测NullTransition if (trans == RoleTransition.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } //在改变当前状态前检测当前状态是否可作为过渡的参数 RoleStateID id = CurrentState.GetOutputState(trans); if (id == RoleStateID.NullStateID) { Debug.LogError("FSM ERROR: State " + CurrentStateID.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } if (id == CurrentStateID) { //Debug.LogError("FSM ERROR:Current State is same state " + CurrentStateID.ToString()); return; } //更新当前的状态个和状态编号 CurrentStateID = id; for (int i = 0; i < states.Count; i++) { if (states[i].ID == CurrentStateID) { //离开旧状态执行方法 CurrentState.OnExit(entity); CurrentState = states[i]; //进入新的状态 CurrentState.OnEnter(entity); break; } } }