コード例 #1
0
ファイル: FSMSystem.cs プロジェクト: hulor/VikingProject
 public void SetState(eStateId stateId)
 {
     if (this._stateStack.Count != 0)
         this.OnStatFinished(this._states[this._stateStack[0]]);
     this._stateStack.Add(stateId);
     this._states[stateId].OnStateEnter();
 }
コード例 #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
ファイル: FSMState.cs プロジェクト: hulor/VikingProject
 protected FSMState(List<TransitionInfo> transitions, Dictionary<eTransition, TransitionInfo.eTransitionType> transitionType, FSMSystem fsm, eStateId stat)
 {
     this.stateId = stat;
     this._transition = transitions;
     this._transType = transitionType;
     this._fsm = fsm;
 }
コード例 #4
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);
 }
コード例 #5
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;
 }
コード例 #6
0
 public void StartChildStateControl(eStateId defaultStateId)
 {
     _childControl = gameObject.GetComponent <StateControl>();
     if (_childControl == null)
     {
         _childControl = gameObject.AddComponent <StateControl>();
     }
     _childControl.enabled        = true;
     _childControl.IsChildControl = true;
     _childControl.SetCurState(defaultStateId);
 }
コード例 #7
0
 /// <summary>
 /// 开启子状态控制器
 /// </summary>
 /// <param name="defaultStateId">子状态的默认状态</param>
 /// <param name="returnData">子状态接受的来自父状态的信息</param>
 /// <param name="receiveData">子状态发送到父状态的委托</param>
 public void StartChildStateControl(eStateId defaultStateId, object receiveData, Action <object> returnData)
 {
     _childControl = gameObject.GetComponent <StateControl>();
     if (_childControl == null)
     {
         _childControl = gameObject.AddComponent <StateControl>();
     }
     _childControl.enabled        = true;
     _childControl.IsChildControl = true;
     _childControl.SendAction     = returnData;
     _childControl.ReceiveData    = receiveData;
     _childControl.SetCurState(defaultStateId);
 }
コード例 #8
0
    public void SetCurState(eStateId eStateId)
    {
        if (eStateId == eStateId.NullId)
        {
            Debug.Log("You couldn't set a stateId to Null");
            throw new UnityException();
        }

        foreach (var state in _stateList)
        {
            if (state.StateId != eStateId)
            {
                continue;
            }
            if (CurState == null)
            {
                CurState   = state;
                CurStateId = state.StateId;
                OnStateChangedEvent?.Invoke(CurStateId);
                CurState.OnEnter();
                CurState.OnAction();
                return;
            }
            else
            {
                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>SetCurState </color> You don't found a state " + eStateId + " from _stateList");
    }
コード例 #9
0
ファイル: FSMSystem.cs プロジェクト: hulor/VikingProject
 public void StatTransitTo(FSMState state, eStateId destState, TransitionData tData)
 {
     this.OnStatFinished(state);
     if (this._stateStack.Count != 0)
         this.StatAddChild(this._states[this._stateStack[this._stateStack.Count - 1]], destState, tData);
 }
コード例 #10
0
ファイル: FSMSystem.cs プロジェクト: hulor/VikingProject
        public void StatAddChild(FSMState parent, eStateId childType, TransitionData tData)
        {
            int idParent = this.FindStat(parent);

            if (idParent == -1)
            {
                Debug.LogWarning("StatAddChild : parent not found");
                return;
            }
            if (idParent != this._stateStack.Count)
            {
                this.ParentKillChildren(idParent);
            }
            this._stateStack.Add(childType);
            this._states[childType].OnStateEnter();
        }
コード例 #11
0
 private void ABC(eStateId eStateId)
 {
     Debug.Log("StateListenerTest ABC---> " + eStateId);
     Debug.Log("StateListenerTest ABC control.GetCurStateId--->" + control.GetCurStateId());
     System.Diagnostics.Trace.WriteLine("StateListenerTest---> " + eStateId);
 }
コード例 #12
0
 /// <summary>
 /// 强制切换到某一状态
 /// </summary>
 public void SetCurState(eStateId eStateId)
 {
     _system?.SetCurState(eStateId);
 }