public void RemoveTransition(eTransition _trans) { if (StateDic.ContainsKey(_trans)) { StateDic.Remove(_trans); } }
public void PerformTransition(eTransition trans) { eStateId id = CurState.GetStateIdByTrans(trans); //处理状态转换错误 if (id == eStateId.NullId) { Debug.LogError("CurState -> " + "<color=red>" + CurStateId + "</color>" + " no found the eTransition -> " + "<color=green>" + trans + "</color>"); throw new UnityException(); } foreach (var state in _stateList) { if (state.StateId != id) { continue; } CurState.OnExit(); CurState.OnExit(out object data); CurState = state; CurStateId = state.StateId; OnStateChangedEvent?.Invoke(CurStateId); CurState.OnEnter(); CurState.OnEnter(in data); CurState.OnAction(); return; } Debug.LogError("<color=red>PerformTransition </color> You don't found a state " + id + " from _stateList"); }
/// <summary> /// Transitions into a sibiling node of the tree /// </summary> /// <param name="state"></param> /// <param name="depth"></param> /// <returns></returns> private async Task SiblingTransition(State state, int depth) { _eTransitionState = eTransition.StartNewState; Log($"StateMachine {_eTransitionState} in state {state.GetType().Name}"); await state.OnEnter(); if (_currentDepth > -1) { _eTransitionState = eTransition.EndingOldState; for (int i = _currentDepth; i >= depth; --i) { var oldState = _states[i]; Log($"StateMachine {_eTransitionState} in state {oldState.GetType().Name}"); await oldState.OnExit(); _states[i] = null; } } var ownerIndex = depth - 1; state.Init(ownerIndex > 0 ? _states[ownerIndex] : null); _states[depth] = state; _currentDepth = depth; _eTransitionState = eTransition.CurrentState; Log($"StateMachine {_eTransitionState} in state {state.GetType().Name}"); }
public void RemoveTransition(eTransition trans) { if (!_stateDic.ContainsKey(trans)) { return; } _stateDic.Remove(trans); }
/// <summary> /// 添加转换条件 /// </summary> /// <param name="trans">转换条件</param> /// <param name="id">目标状态Id</param> public void AddTransition(eTransition trans, eStateId id) { if (_stateDic.ContainsKey(trans)) { return; } _stateDic.Add(trans, id); }
public void AddTransition(eTransition _trans, eStateID _id) { if (StateDic.ContainsKey(_trans)) { return; } StateDic.Add(_trans, _id); }
public eStateId GetStateIdByTrans(eTransition trans) { if (_stateDic.ContainsKey(trans)) { return(_stateDic[trans]); } Debug.Log("<color=red>GetStateIdByTrans Null </color>" + trans + " no found in StateId"); return(eStateId.NullId); }
public eStateID GetStateIDByTrans(eTransition trans) { if (StateDic.ContainsKey(trans)) { return(StateDic[trans]); } Debug.LogFormat("GetStateIDByTrans---> {0} {1}", StateID, trans); return(eStateID.Null); }
public TransitionInfo(eTransitionType type, eStateId dest, eTransition transition, TransitionData tData) { this.transitionType = type; this.idDest = dest; this.transition = transition; this.data = tData; this._transitions = new TransitionHandler[(int)eTransitionType.NoneTransition]; this._transitions[(int)eTransitionType.AddChild] = this.AddTransition; this._transitions[(int)eTransitionType.SimpleTransition] = this.SwitchStateTransition; }
/// <summary> /// This transitions into the child stack /// </summary> /// <param name="state">State you are going to</param> /// <returns>Returns nothing</returns> private async Task InnerTransition(State state) { _eTransitionState = eTransition.StartNewState; state.Init(_states[_currentDepth]); await state.OnEnter(); _currentDepth += 1; _states[_currentDepth] = state; _eTransitionState = eTransition.CurrentState; }
/// <summary> /// 执行转换条件 /// </summary> /// <param name="trans">转换条件</param> /// <param name="returnData">子状态返回给父状态的数据</param> public void PerformTransition(eTransition trans, object returnData) { if (returnData == null) { _system.PerformTransition(trans); } else { SendAction(returnData); } }
/// <summary> /// First transition when the state machine starts /// </summary> /// <param name="state">State of the which it starts with</param> /// <returns></returns> private async Task FirstTransition(State state) { _eTransitionState = eTransition.StartNewState; Log($"StateMachine {_eTransitionState} in state {state.GetType().Name}"); await state.OnEnter(); state.Init(null); _currentDepth = 0; _states[_currentDepth] = state; _eTransitionState = eTransition.CurrentState; Log($"StateMachine {_eTransitionState} in state {state.GetType().Name}"); }
public virtual void PerformTransition(eTransition trans) { Debug.Log("CurState " + CurState.name); eStateID id = CurState.GetStateIDByTrans(trans); if (id == eStateID.Null) { Debug.LogError("ERROR: CurrentState " + CurStateID + " TargetState " + id + " Transition " + trans); return; } CurStateID = id; foreach (var state in stateList) { if (state.StateID == CurStateID) { CurState.OnExit(); CurState.OnExit(out object dataNext); CurState = state; CurState.OnEnter(); CurState.OnEnter(in dataNext); CurState.OnAction(); } } }
public TransitionData(eTransition trans, Object data) { this.transition = trans; this.data = data; }
/// <summary> /// 执行状态转换条件 /// </summary> /// <param name="trans">转换条件</param> public virtual void PerformTransition(eTransition trans) { StateSystem.PerformTransition(trans); onStateChangedEvent.Invoke(StateSystem.CurStateID); }
public void PerformTransition(eTransition trans) { _system.PerformTransition(trans); }