/// <summary> /// 添加切换条件 对应的 下一个状态 /// </summary> /// <param name="transition">Transition.</param> /// <param name="stateId">State identifier.</param> public void AddTransition(FSMTransition transition, FSMStateId stateId) { if (transition != FSMTransition.Empty && stateId != FSMStateId.Empty) { map.Add(transition, stateId); } }
/// <summary> /// 移除一个状态 /// </summary> /// <param name="stateId">State identifier.</param> public void RemoveState(FSMStateId stateId) { if (stateDict.ContainsKey(stateId)) { stateDict.Remove(stateId); } }
public void PerformTransition(FSMTransition trans) { if (trans == FSMTransition.NullTransition) { return; } FSMStateId id = currentState.GetOutputStateId(trans); if (id == FSMStateId.NullState) { return; } currentStateId = id; foreach (FSMState state in stateList) { if (state.StateID == id) { currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } }
public void AddState(FSMState state) { if (state == null) { Debug.LogError("FSM ERROR: Null State reference"); return; } if (stateList.Count == 0) { stateList.Add(state); currentState = state; currentStateId = state.StateID; return; } foreach (FSMState tempState in stateList) { if (state.StateID == tempState.StateID) { Debug.LogError("state [" + state.StateID.ToString() + "] already added."); return; } } stateList.Add(state); }
public void AddState(FSMState state) { if (state == null) { Debug.LogError("FSM ERROR: Null State reference"); return; } if (stateList.Count == 0) { stateList.Add(state); currentState = state; currentStateId = state.StateID; return; } foreach (FSMState tempState in stateList) { if (state.StateID == tempState.StateID) { Debug.LogError("state [" + state.StateID.ToString() + "] already added."); return; } } stateList.Add(state); }
public void AddFSMState(FSMState fsmState) { if(fsmState != null) { if(fsmStates.Count == 0) { fsmStates.Add(fsmState); currentState = fsmState; currentStateId = fsmState.ID; } else { foreach(FSMState state in fsmStates) { if(state.ID == fsmState.ID) { Debug.LogWarning("The FSM State was already in the list"); return; } } fsmStates.Add(fsmState); } } else { Debug.LogError("The FSM State is null"); } }
/// <summary> /// Add a state transition to the FSM /// </summary> /// <param name="state">The state</param> /// <param name="eventId">The transition event</param> public void AddTransition(FSMStateId fromState, FSMEventId eventId, IState <TContext> state) { var transitionKey = new KeyValuePair <FSMStateId, FSMEventId>(fromState, eventId); Debug.Assert(!transitions.ContainsKey(transitionKey), string.Format("Overwriting gesture {0}", eventId.ToString())); state.Controller = this; this.transitions[transitionKey] = state; }
/// <summary> /// 默认执行的状态 /// </summary> /// <param name="stateId">State identifier.</param> public void Start(FSMStateId stateId) { FSMState state; if (stateDict.TryGetValue(stateId, out state)) { state.DoBeforeEnter(); currentState = state; } }
public void TestConstructor() { // arrange & act FSMStateId testState = FSMStateId.Recording; var mockedState = new Mock <StateBase>(testState) { CallBase = true }; // assert Assert.AreEqual(testState, mockedState.Object.Id, "identifier set"); }
/// <summary> /// 执行切换下一个状态 /// </summary> /// <param name="transition">Transition.</param> public void PerformTransition(FSMTransition transition) { if (transition != null && currentState != null) { FSMStateId nextStateId = currentState.GetStateId(transition); if (nextStateId != FSMStateId.Empty) { FSMState state; stateDict.TryGetValue(nextStateId, out state); currentState.DoBeforeLeave(); currentState = state; state.DoBeforeEnter(); } } }
public void DeleteState(FSMStateId fsmState) { if(fsmState == FSMStateId.None) { return; } foreach(FSMState state in fsmStates) { if(state.ID == fsmState) { fsmStates.Remove(state); return; } } Debug.LogWarning ("The state id was not in the list"); }
public void AddTransition(FSMTransition trans, FSMStateId id) { if (trans == FSMTransition.NullTransition) { return; } if (id == FSMStateId.NullState) { return; } if (map.ContainsKey(trans)) { return; } map.Add(trans, id); }
public void AddTransition(FSMTransition trans, FSMStateId id) { if (trans == FSMTransition.NullTransition) { return; } if (id == FSMStateId.NullState) { return; } if (map.ContainsKey(trans)) { return; } map.Add(trans, id); }
public void DeleteState(FSMStateId id) { if (id == FSMStateId.NullState) { return; } foreach (FSMState state in stateList) { if (state.StateID == id) { stateList.Remove(state); return; } } Debug.LogError("State [" + id + "] is not found"); }
public void AddTransition(Transition transition, FSMStateId id) { //make sure there are actual values passed in if( transition == Transition.None || id == FSMStateId.None) { Debug.LogWarning("No null FSM State or Transaction"); return; } if(map.ContainsKey(transition)) { Debug.LogWarning("transition is already used"); return; } map.Add (transition, id); }
public void DeleteState(FSMStateId id) { if (id == FSMStateId.NullState) { return; } foreach (FSMState state in stateList) { if (state.StateID == id) { stateList.Remove(state); return; } } Debug.LogError("State [" + id + "] is not found"); }
/// <summary> /// 执行切换下一个状态 /// </summary> /// <param name="transition">Transition.</param> public void PerformTransition(FSMTransition transition, params object[] pars) { if (transition != null && currentState != null) { FSMStateId nextStateId = currentState.GetStateId(transition); if (nextStateId != FSMStateId.Empty) { FSMState state; stateDict.TryGetValue(nextStateId, out state); currentState.DoBeforeLeave(); currentState = state; state.DoBeforeEnter(pars); if (playerType == PlayerType.Self) { SyncTransitionRequest.Instance.SendSyncTransitionRequest(transition, pars); } } } }
/// <summary> /// Performs a state transition for a gesture /// </summary> /// <param name="eventId">The gesture for which to change state</param> public virtual void PerformTransition(FSMEventId eventId) { FSMStateId oldStateId = this.currentState != null ? this.currentState.Id : FSMStateId.Unknown; var transitionKey = this.GetTransitionKey(eventId); IState <TContext> oldState = this.currentState; if (!transitions.ContainsKey(transitionKey)) { throw new ApplicationException(string.Format("No transition for event {0} found", eventId.ToString())); } currentState = transitions[transitionKey]; if (currentState == null) { throw new ApplicationException(string.Format("Invalid state for event {0}", eventId.ToString())); } // we only enter/exit states if anything really changed if (currentState.Id != transitionKey.Key) { if (oldState != null) { oldState.StateExited(); } currentState.StateEntered(this.sharedContext); if (this.StateChanged != null) { this.StateChanged(this, new StateChangedEventArgs() { OldState = oldStateId, NewState = currentState.Id }); } } }
/// <summary> /// Loads the states transitions /// </summary> /// <param name="config">The configuration node</param> private void LoadStateTransitions(XmlDocument config) { config.ProcessXmlNodes("//configuration/statetransitions/transition", transition => { FSMStateId fromStateId = (FSMStateId)int.Parse(transition.Attributes["fromState"].Value); FSMStateId toStateId = (FSMStateId)int.Parse(transition.Attributes["moveToState"].Value); FSMEventId eventId = (FSMEventId)int.Parse(transition.Attributes["onEvent"].Value); if (!this.States.ContainsKey(fromStateId) && fromStateId != FSMStateId.Unknown) { throw new InvalidDataException(string.Format("State {0} is not specified in the states section of the config file", fromStateId.ToString())); } if (!this.States.ContainsKey(toStateId)) { throw new InvalidDataException(string.Format("State {0} is not specified in the states section of the config file", toStateId.ToString())); } this.StateTransitions[new KeyValuePair <FSMStateId, FSMEventId>(fromStateId, eventId)] = toStateId; }); }
/// <summary> /// Loads the gesture to eventid mapping /// </summary> /// <param name="config">The configuration node</param> private void LoadGestureTransitions(XmlDocument config) { config.ProcessXmlNodes("//configuration/gesturetransitions/gesturetransition", transition => { FSMStateId fromStateId = (FSMStateId)int.Parse(transition.Attributes["fromState"].Value); GestureId gestureId = (GestureId)int.Parse(transition.Attributes["onGesture"].Value); FSMEventId eventId = (FSMEventId)int.Parse(transition.Attributes["raiseStateEvent"].Value); if (!this.Gestures.ContainsKey(gestureId)) { throw new InvalidDataException(string.Format("Gesture {0} is not specified in the gestures section of the config file", gestureId.ToString())); } if (!this.States.ContainsKey(fromStateId)) { throw new InvalidDataException(string.Format("State {0} is not specified in the states section of the config file", fromStateId.ToString())); } this.GestureTransitions[new KeyValuePair <FSMStateId, GestureId>(fromStateId, gestureId)] = eventId; }); }
public void PerformTransition(Transition transition) { if(transition == Transition.None) { Debug.LogWarning("The transition can not be null"); return; } FSMStateId id = currentState.GetOutputState (transition); if(id == FSMStateId.None) { Debug.LogWarning("Current state does not have a target state"); return; } currentStateId = id; foreach(FSMState state in fsmStates) { if(state.ID == currentStateId) { currentState = state; break; } } }
public void PerformTransition(FSMTransition trans) { if (trans == FSMTransition.NullTransition) { return; } FSMStateId id = currentState.GetOutputStateId(trans); if (id == FSMStateId.NullState) { return; } currentStateId = id; foreach(FSMState state in stateList) { if(state.StateID == id) { currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } }
/// <summary> /// default ctor /// </summary> protected StateBase(FSMStateId id) { this.Id = id; }
/// <summary> /// Default ctor /// </summary> /// <param name="id">The state id</param> public StateTrackingBase(FSMStateId id) : base(id) { }