コード例 #1
0
 public void RemoveTransition(eTransition _trans)
 {
     if (StateDic.ContainsKey(_trans))
     {
         StateDic.Remove(_trans);
     }
 }
コード例 #2
0
    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");
    }
コード例 #3
0
        /// <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}");
        }
コード例 #4
0
 public void RemoveTransition(eTransition trans)
 {
     if (!_stateDic.ContainsKey(trans))
     {
         return;
     }
     _stateDic.Remove(trans);
 }
コード例 #5
0
 /// <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);
 }
コード例 #6
0
 public void AddTransition(eTransition _trans, eStateID _id)
 {
     if (StateDic.ContainsKey(_trans))
     {
         return;
     }
     StateDic.Add(_trans, _id);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 public eStateID GetStateIDByTrans(eTransition trans)
 {
     if (StateDic.ContainsKey(trans))
     {
         return(StateDic[trans]);
     }
     Debug.LogFormat("GetStateIDByTrans---> {0} {1}", StateID, trans);
     return(eStateID.Null);
 }
コード例 #9
0
ファイル: Transition.cs プロジェクト: hulor/VikingProject
 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;
 }
コード例 #10
0
        /// <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;
        }
コード例 #11
0
 /// <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);
     }
 }
コード例 #12
0
        /// <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}");
        }
コード例 #13
0
ファイル: StateSystem.cs プロジェクト: Hengle/HFSMTemplate
    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();
            }
        }
    }
コード例 #14
0
ファイル: Transition.cs プロジェクト: hulor/VikingProject
 public TransitionData(eTransition trans, Object data)
 {
     this.transition = trans;
     this.data = data;
 }
コード例 #15
0
ファイル: StateControl.cs プロジェクト: Hengle/HFSMTemplate
 /// <summary>
 /// 执行状态转换条件
 /// </summary>
 /// <param name="trans">转换条件</param>
 public virtual void PerformTransition(eTransition trans)
 {
     StateSystem.PerformTransition(trans);
     onStateChangedEvent.Invoke(StateSystem.CurStateID);
 }
コード例 #16
0
 public void PerformTransition(eTransition trans)
 {
     _system.PerformTransition(trans);
 }