Example #1
0
 // here we define the structure of the state machine's first layer
 public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
 {
     // default is an OR-type state
     // the first child added will be the inital state
     children.Add(typeof(PlayerState_Alive));
     children.Add(typeof(PlayerState_Dead));
 }
Example #2
0
    /// <summary>
    /// 改变状态
    /// </summary>
    /// <param name="type"></param>
    public void ChangeState(FSMStateType type, params System.Object[] args)
    {
        if (CurrentType == FSMStateType.Dead)
        {
            return;
        }

        if (!map.ContainsKey(type))
        {
            Debuger.LogError("不包含此状态" + type);
        }

        FSMState state = null;

        map.TryGetValue(type, out state);
        if (state == null)
        {
            Debuger.LogError("获取到的状态为空:" + type);
            return;
        }

        if (state == currentState)
        {
            return;
        }
        if (currentState != null)
        {
            currentState.Exit();
        }
        currentState = state;
        currentType  = type;
        currentState.Enter(args);
    }
Example #3
0
        /// <summary>
        /// 获取指定名称的状态
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>状态</returns>
        public FSMState GetState(FSMStateType type)
        {
            FSMState state;

            this._states.TryGetValue(type, out state);
            return(state);
        }
 // here we define the structure of the state machine's first layer
 public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
 {
     // default is an OR-type state
     // the first child added will be the inital state
     children.Add(typeof(PlayerState_Alive));
     children.Add(typeof(PlayerState_Dead));
 }
Example #5
0
 public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
 {
     // three children states
     stateType = FSMStateType.Type_OR;
     children.Add(typeof(PlayerState_Alive_AnimationManager_Idle));
     children.Add(typeof(PlayerState_Alive_AnimationManager_Walk));
     children.Add(typeof(PlayerState_Alive_AnimationManager_Jump));
 }
Example #6
0
    private void TransitionToState(FSMStateType StateName)
    {
        CurrentState.OnExit();
        CurrentState = GetState(StateName);
        CurrentState.OnEnter();

        Debug.Log("Transitioned to " + CurrentState.StateName);
    }
 public void EnterState(FSMStateType stateType)
 {
     if (_fsmStates.ContainsKey(stateType))
     {
         AbstractFSMState nextState = _fsmStates[stateType];
         EnterState(nextState);
     }
 }
 public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
 {
     // here we have nested states within a state
     // This is a AND type of state, which means both the animation manager and the combat manager will be running in parallel
     stateType = FSMStateType.Type_AND;
     children.Add(typeof(PlayerState_Alive_AnimationManager));
     children.Add(typeof(PlayerState_Alive_CombatManager));
 }
Example #9
0
 public FSMStateMachineLogic(FSMStateType stateType, List <Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     this.m_StateClass    = null;
     this.m_StateType     = stateType;
     this.m_ChildrenTypes = childrenTypes;
     this.m_Parent        = parent;
     this.m_OwnerSM       = ownerSM;
 }
Example #10
0
 /// <summary>
 /// 删除状态
 /// </summary>
 /// <param name="type"></param>
 public void DeleteFSMState(FSMStateType type)
 {
     if (!map.ContainsKey(type))
     {
         Debuger.LogError("当前列表中不存在这个状态:" + type);
     }
     map.Remove(type);
 }
Example #11
0
 public FSMStateMachineLogic(FSMStateType stateType, List <System.Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_StateClass    = null;
     m_StateType     = stateType;
     m_ChildrenTypes = childrenTypes;
     m_Parent        = parent;
     m_OwnerSM       = ownerSM;
 }
 public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
 {
     // here we have nested states within a state
     // This is a AND type of state, which means both the animation manager and the combat manager will be running in parallel
     stateType = FSMStateType.Type_AND;
     children.Add(typeof(PlayerState_Alive_AnimationManager));
     children.Add(typeof(PlayerState_Alive_CombatManager));
 }
 public FSMStateMachineLogic(FSMStateType stateType, List<System.Type> childrenTypes, FSMStateMachine ownerSM, FSMStateMachineLogic parent)
 {
     m_StateClass = null;
     m_StateType = stateType;
     m_ChildrenTypes = childrenTypes;
     m_Parent = parent;
     m_OwnerSM = ownerSM;
 }
 public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
 {
     // three children states
     stateType = FSMStateType.Type_OR;
     children.Add(typeof(PlayerState_Alive_AnimationManager_Idle));
     children.Add(typeof(PlayerState_Alive_AnimationManager_Walk));
     children.Add(typeof(PlayerState_Alive_AnimationManager_Jump));
 }
Example #15
0
 public void enterState(FSMStateType stateType) //Checks that listed state is valid, then calls previous funtion according to entry
 {
     if (fsmStates.ContainsKey(stateType))
     {
         abstractFSMState nextState = fsmStates[stateType];
         enterState(nextState);
     }
 }
Example #16
0
        public virtual void StartSM()
        {
            FSMStateType fSMStateType = FSMStateType.Type_OR;
            List <Type>  types        = new List <Type>();

            this.SetupDefinition(ref fSMStateType, ref types);
            this.m_Logic = new FSMStateMachineLogic(fSMStateType, types, this, null);
            this.m_Logic.Enter(null);
        }
Example #17
0
 public void AddTransition(FSMTransitionType transition, FSMStateType id)
 {
     if (map.ContainsKey(transition))
     {
         Debug.LogWarning("ERROR: transition is already inside the map");
         return;
     }
     map.Add(transition, id);
     Debug.Log("Added : " + transition + " with ID : " + id);
 }
        /// <summary>
        /// Calling this will enter the state machine's initial state(s)
        /// </summary>
        public virtual void StartSM()
        {
            FSMStateType       stateType = FSMStateType.Type_OR;
            List <System.Type> children  = new List <System.Type>();

            SetupDefinition(ref stateType, ref children);

            m_Logic = new FSMStateMachineLogic(stateType, children, this, null);
            m_Logic.Enter(null);
        }
        /// <summary>
        /// 状态转换
        /// </summary>
        /// <param name="type">指定需要转换的状态</param>
        /// <param name="force">是否强制转换(即需要转换的状态是当前状态的情况下仍然转换)</param>
        /// <param name="param">参数</param>
        public bool ChangeState(FSMStateType type, bool force = false, params object[] param)
        {
            this._states.TryGetValue(type, out FSMState state);
            if (state != null)
            {
                return(this.InternalChangeState(state, force, param));
            }

            Logger.Warn($"State '{type}' not exist.");
            return(false);
        }
 public void Push(FSMStateType type, object[] param = null)
 {
     if (!this._states.ContainsKey(type))
     {
         Logger.Log($"State '{type}' not found.");
     }
     else
     {
         this.Push(this._states[type], param);
     }
 }
Example #21
0
        public void EnterState(FSMStateType stateType)
        {
            if (_fsmStates.ContainsKey(stateType))
            {
                NewBehaviourScript nextState = _fsmStates[stateType];

                _currentState.ExitState();

                EnterState(nextState);
            }
        }
Example #22
0
    void Update()
    {
        CurrentState.DoAction();

        FSMStateType TransitionState = CurrentState.ShouldTransitionToState();

        if (TransitionState != CurrentState.StateName)
        {
            TransitionToState(TransitionState);
        }
    }
Example #23
0
        public static void ChangeState(string targetId, FSMStateType type, bool force = false, params object[] param)
        {
            SyncEvent e = SyncEvent.Get();

            e.type        = SyncEventType.ENTITY_STATE_CHANGED;
            e.targetId    = targetId;
            e.stateType   = type;
            e.forceChange = force;
            e.stateParam  = param;
            e.BeginInvoke();
        }
    // here we define the structure of the state machine's first layer
    public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
    {
        // default is an OR-type state
        // the first child added will be the inital state
        children.Add(typeof(SimonSaysState_WaitingToPlay));

        children.Add(typeof(SimonSaysState_IncreasingSequence));
        children.Add(typeof(SimonSaysState_PlayingSequence));
        children.Add(typeof(SimonSaysState_UserInputFAIL));
        children.Add(typeof(SimonSaysState_UserInputOK));
        children.Add(typeof(SimonSaysState_WaitingUserInput));
    }
Example #25
0
        public void EnterState(FSMStateType stateType)
        {
            if (_fsmStates.ContainsKey(stateType))
            {
                //get value in the dictionary that corresponds to that key
                AbstractFSMState nextState = _fsmStates[stateType];

                //_currentState.ExitState();

                EnterState(nextState);
            }
        }
	// here we define the structure of the state machine's first layer
	public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
	{
		// default is an OR-type state
		// the first child added will be the inital state
		children.Add(typeof(SimonSaysState_WaitingToPlay));
		
		children.Add(typeof(SimonSaysState_IncreasingSequence));
		children.Add(typeof(SimonSaysState_PlayingSequence));
		children.Add(typeof(SimonSaysState_UserInputFAIL));
		children.Add(typeof(SimonSaysState_UserInputOK));
		children.Add(typeof(SimonSaysState_WaitingUserInput));
	}
Example #27
0
 /// <summary>
 /// 从状态列表中删除一个状态
 /// </summary>
 /// <param name="fsmState"></param>
 public void DeleteState(FSMStateType fsmState)
 {
     foreach (FSMState state in fsmStates)
     {
         if (state.ID == fsmState)
         {
             fsmStates.Remove(state);
             return;
         }
     }
     Debug.LogError("FSM ERROR: The state passed was not on the list. Impossible to delete it");
 }
Example #28
0
    IFSMState GetState(FSMStateType StateName)
    {
        foreach (var state in StatePool)
        {
            if (state.StateName == StateName)
            {
                return(state);
            }
        }

        return(EmptyAction);
    }
Example #29
0
		public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
		{
				// default is an OR-type state
				// the first child added will be the inital state
				stateType = FSMStateType.Type_OR;
				children.Add(typeof(FitState_AM_Idle));
				children.Add(typeof(FitState_AM_Fall));
				children.Add(typeof(FitState_AM_WalkSlow));
				children.Add(typeof(FitState_AM_WalkFast));
				children.Add(typeof(FitState_AM_InitDash));
				children.Add(typeof(FitState_AM_Run));
				children.Add(typeof(FitState_AM_RunBrake));
				children.Add(typeof(FitState_AM_RunTurn));
				children.Add(typeof(FitState_AM_Pivot));
				children.Add(typeof(FitState_AM_GroundAttack));
				children.Add(typeof(FitState_AM_GroundSpecial));
				children.Add(typeof(FitState_AM_AirSpecial));
				children.Add(typeof(FitState_AM_Jump));
				children.Add(typeof(FitState_AM_JumpBackward));
				children.Add(typeof(FitState_AM_JumpSquat));
				children.Add(typeof(FitState_AM_AirJump));
				children.Add(typeof(FitState_AM_AirHopBack));
				children.Add(typeof(FitState_AM_CrouchSquat));
				children.Add(typeof(FitState_AM_Crouch));
				children.Add(typeof(FitState_AM_Land));
				children.Add(typeof(FitState_AM_Wavedash));
				children.Add(typeof(FitState_AM_WavedashLand));
				children.Add(typeof(FitState_AM_Ukemi));
				children.Add(typeof(FitState_AM_Grab));
				children.Add(typeof(FitState_AM_Caught));
				children.Add(typeof(FitState_AM_Holding));
				children.Add(typeof(FitState_AM_Thrown));
				children.Add(typeof(FitState_AM_Throwing));
				children.Add(typeof(FitState_AM_LedgeCatch));
				children.Add(typeof(FitState_AM_AirAction));
				children.Add(typeof(FitState_AM_AirAttack));
				children.Add(typeof(FitState_AM_AirBullet));
				children.Add(typeof(FitState_AM_Pass));
				children.Add(typeof(FitState_AM_HitStop));
				children.Add(typeof(FitState_AM_HitStun));
				children.Add(typeof(FitState_AM_HitStunFly));
				children.Add(typeof(FitState_AM_Tumble));
//				children.Add(typeof(FitState_AM_GDamage2));
//				children.Add(typeof(FitState_AM_ADamage1));
//				children.Add(typeof(FitState_AM_ADamage2));
				children.Add(typeof(FitState_AM_ShieldEnter));
				children.Add(typeof(FitState_AM_Shield));
				children.Add(typeof(FitState_AM_ShieldOff));
				children.Add(typeof(FitState_AM_ShieldStop));
				children.Add(typeof(FitState_AM_ShieldStun));

		}
Example #30
0
        /// <summary>
        /// 创建状态
        /// </summary>
        /// <param name="type">类型</param>
        /// <returns>被创建的状态</returns>
        public FSMState CreateState(FSMStateType type)
        {
            if (this._states.ContainsKey(type))
            {
                throw new Exception($"Specified name '{type}' of component already exists");
            }

            FSMState state = new FSMState(type, this);

            this._states.Add(type, state);

            return(state);
        }
Example #31
0
    public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
    {
        // default is an OR-type state
        // the first child added will be the inital state
        stateType = FSMStateType.Type_OR;
        children.Add(typeof(FitState_AM_Idle));
        children.Add(typeof(FitState_AM_Fall));
        children.Add(typeof(FitState_AM_WalkSlow));
        children.Add(typeof(FitState_AM_WalkFast));
        children.Add(typeof(FitState_AM_InitDash));
        children.Add(typeof(FitState_AM_Run));
        children.Add(typeof(FitState_AM_RunBrake));
        children.Add(typeof(FitState_AM_RunTurn));
        children.Add(typeof(FitState_AM_Pivot));
        children.Add(typeof(FitState_AM_GroundAttack));
        children.Add(typeof(FitState_AM_GroundSpecial));
        children.Add(typeof(FitState_AM_AirSpecial));
        children.Add(typeof(FitState_AM_Jump));
        children.Add(typeof(FitState_AM_JumpBackward));
        children.Add(typeof(FitState_AM_JumpSquat));
        children.Add(typeof(FitState_AM_AirJump));
        children.Add(typeof(FitState_AM_AirHopBack));
        children.Add(typeof(FitState_AM_CrouchSquat));
        children.Add(typeof(FitState_AM_Crouch));
        children.Add(typeof(FitState_AM_Land));
        children.Add(typeof(FitState_AM_Wavedash));
        children.Add(typeof(FitState_AM_WavedashLand));
        children.Add(typeof(FitState_AM_Ukemi));
        children.Add(typeof(FitState_AM_Grab));
        children.Add(typeof(FitState_AM_Caught));
        children.Add(typeof(FitState_AM_Holding));
        children.Add(typeof(FitState_AM_Thrown));
        children.Add(typeof(FitState_AM_Throwing));
        children.Add(typeof(FitState_AM_LedgeCatch));
        children.Add(typeof(FitState_AM_AirAction));
        children.Add(typeof(FitState_AM_AirAttack));
        children.Add(typeof(FitState_AM_AirBullet));
        children.Add(typeof(FitState_AM_Pass));
        children.Add(typeof(FitState_AM_HitStop));
        children.Add(typeof(FitState_AM_HitStun));
        children.Add(typeof(FitState_AM_HitStunFly));
        children.Add(typeof(FitState_AM_Tumble));
//				children.Add(typeof(FitState_AM_GDamage2));
//				children.Add(typeof(FitState_AM_ADamage1));
//				children.Add(typeof(FitState_AM_ADamage2));
        children.Add(typeof(FitState_AM_ShieldEnter));
        children.Add(typeof(FitState_AM_Shield));
        children.Add(typeof(FitState_AM_ShieldOff));
        children.Add(typeof(FitState_AM_ShieldStop));
        children.Add(typeof(FitState_AM_ShieldStun));
    }
 // here we define the structure of the state machine's first layer
 public override void SetupDefinition(ref FSMStateType stateType, ref List <System.Type> children)
 {
     // default is an ORtype state
     // the first child added will be the inital state
     children.Add(typeof(State_WaitToPlay));
     children.Add(typeof(State_AssignAndShow));
     children.Add(typeof(State_CheckTokens));
     children.Add(typeof(State_ClueLife));
     children.Add(typeof(State_CorrectTokens));
     children.Add(typeof(State_FailTokens));
     children.Add(typeof(State_GameFinished));
     children.Add(typeof(State_WaitToken1));
     children.Add(typeof(State_WaitToken2));
 }
Example #33
0
 /// <summary>
 /// 添加状态
 /// </summary>
 /// <param name="type"></param>
 /// <param name="fsmState"></param>
 public void AddFSMState(FSMStateType type, FSMState fsmState)
 {
     if (map.Count == 0)
     {
         map.Add(type, fsmState);
         ChangeState(type);
         return;
     }
     if (map.ContainsKey(type))
     {
         Debuger.LogError("添加的状态已经存在:" + type);
         return;
     }
     map.Add(type, fsmState);
 }
Example #34
0
        /// <summary>
        /// 转换状态
        /// </summary>
        /// <param name="trans"></param>
        public void PerformTransition(FSMTransitionType trans)
        {
            FSMStateType id = currentState.GetOutputState(trans);

            currentStateID = id;

            foreach (FSMState state in fsmStates)
            {
                if (state.ID == currentStateID)
                {
                    Debug.Log(currentStateID);
                    currentState = state;
                    break;
                }
            }
        }
Example #35
0
        public void Push(FSMStateType type, object[] param = null)
        {
            if (this.enableDebug)
            {
                LLogger.Log("Change state:{0}", type);
            }

            if (!this._states.ContainsKey(type))
            {
                LLogger.Log("State '{0}' not found.", type);
            }
            else
            {
                this.Push(this._states[type], param);
            }
        }
 public override void SetupDefinition(ref FSMStateType stateType, ref List <Type> children)
 {
     children.Add(typeof(PlayerState_Riding));
     children.Add(typeof(PlayerState_OnBoard));
     children.Add(typeof(PlayerState_Impact));
     children.Add(typeof(PlayerState_Manualling));
     children.Add(typeof(PlayerState_Setup));
     children.Add(typeof(PlayerState_BeginPop));
     children.Add(typeof(PlayerState_Pop));
     children.Add(typeof(PlayerState_Released));
     children.Add(typeof(PlayerState_InAir));
     children.Add(typeof(PlayerState_Grinding));
     children.Add(typeof(PlayerState_OffBoard));
     children.Add(typeof(PlayerState_Bailed));
     children.Add(typeof(PlayerState_Pushing));
     children.Add(typeof(PlayerState_Braking));
 }
 public override void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
 {
     stateType = FSMStateType.Type_OR;
     children.Add(typeof(PlayerState_Alive_CombatManager_Idle));
     children.Add(typeof(PlayerState_Alive_CombatManager_UnderAttack));
 }
        /// <summary>
        /// Sets up the first layer of the state machine. Determines if it has children, and if the state is an OR vs AND state.
        /// </summary>
        /// <param name="stateType"> States of type OR means that only one of its children is active at any one time. Type AND means all its children states are active</param>
        /// <param name="children"> The list of child states for this state. If the state type is OR, the first child in this list will be the initial active state. </param>
        public virtual void SetupDefinition(ref FSMStateType stateType, ref List<System.Type> children)
        {

        }