Example #1
0
 public void ChangeState(State <T> newState)
 {
     _previousState = _currentState;
     _currentState?.Exit(_owner);
     _currentState = newState;
     _currentState?.Enter(_owner);
 }
 public void ChangeState(State newState)
 {
     lastState = currentState;
     currentState.Exit(this.gameObject);
     newState.Enter(this.gameObject);
     currentState = newState;
 }
Example #3
0
 public void ChangeState(State <T> pNewState)
 {
     m_pPreviousState = m_pCurrentState;
     m_pCurrentState?.Exit(m_pOwner);
     m_pCurrentState = pNewState;
     m_pCurrentState?.Enter(m_pOwner);
 }
Example #4
0
 public void ChangeState(State newState)
 {
     if (newState == null)
         return;
     mPreviousState = mCurrentState;
     mCurrentState.Exit (mOwner);
     mCurrentState = newState;
     mCurrentState.Enter (mOwner);
 }
Example #5
0
 public void SetState(StateID stateID)
 {
     if(!states.ContainsKey(stateID))
         return;
     if(currentState != null)
         currentState.Leave();
     currentState = states[stateID];
     currentState.Enter();
 }
Example #6
0
 public void ChangeGlobalState(State newState)
 {
     if (globalState != null)
     {
         globalState.Exit(owner);
     }
     globalState = newState;
     globalState.Enter(owner);
 }
 public void MoveTo(State _state)
 {
     if(state != null) state.Exit();
     state = _state;
     if(state != null) {
         state.sm = this;
         state.Enter();
     }
 }
Example #8
0
 public virtual void SetState(State state)
 {
     if(_currentState != null)
     {
         _currentState.Exit();
     }
     _currentState = state;
     _currentState.StateMachine = this;
     _currentState.Enter();
 }
 public void Update(GameObject gameObject)
 {
     State newState = mCurrState.Update(gameObject);
     if (newState != null)
     {
         mCurrState.Exit();
         mCurrState = newState;
         mCurrState.Enter();
     }
 }
Example #10
0
 public void ChangeState(State newState)
 {
     if (currentState != null)
     {
         previousState = currentState;
         currentState.Exit(owner);
     }
     currentState = newState;
     currentState.Enter(owner);
 }
Example #11
0
 public void Push(State state)
 {
     State old = Peek();
     if (old != null)
     {
         old.Exit();
     }
     states.Push(state);
     state.Enter();
 }
Example #12
0
    void Start()
    {
        _anim = GetComponent<Animator>();
        _fighterRef = this.gameObject.GetComponent<Fighter>();
        _myRigidbody = GetComponent<Rigidbody2D>();
        _currentState = new EnemyPatrolState(this);
        _currentState.Enter();

        GameController.Instance().GetEnemyList.Add(this.gameObject);
    }
    public void ChangeState(State nextState) // is this how the history stack would be implemented?
    {
        State poppedState = historyStates.Pop();

        currentState?.Exit();
        currentState = nextState;
        currentState?.Enter();

        historyStates.Push(currentState);
    }
Example #14
0
    void Transition(State newState)
    {
        InTransition = true;

        // switches state, first calling closing code on current then changing
        _currentState?.Exit();
        _currentState = newState;
        _currentState?.Enter();

        InTransition = false;
    }
Example #15
0
 public void Transition(State fromState,State toState)
 {
     if (SwapState(fromState,toState))
     {
         toState.Enter();
     }
     else
     {
         throw new IllegalStateException("Illegal transition attempted from: " + fromState + " to " + toState);
     }
 }
Example #16
0
 public void Transition(State newState)
 {
     //start transition
     InTransition = true;
     //transitioning
     _currentState?.Exit();
     _currentState = newState;
     _currentState?.Enter();
     //end transition
     InTransition = false;
 }
        /// <summary>
        /// Change the Miner State.
        /// </summary>
        /// <param name="newState">Miner State to change to.</param>
        public void ChangeState(State<Miner> newState)
        {
            //exit current state and change to new state.
            currentState.Exit(this, Location);

            //change the state.
            Location = newState.GetLocation();
            currentState = newState;

            //enter new state.
            currentState.Enter(this);
        }
    public void ChangeState(State newState)
    {
        if (currentState != null)
        {
            currentState.Exit();
        }

        currentState = newState;
        if (newState != null)
        {
            currentState.Enter();
        }
    }
    public void SwitchState( State newState )
    {
        if (currentState != null) {
            currentState.Exit();
        }

        currentState = newState;

        if (currentState != null) {

            currentState.Enter();
        }

        Debug.Log ("Switching to state for: " + newState.entity.name);
    }
Example #20
0
 public StateMachine(Object machineOwner, State[] states)
 {
     owner = machineOwner;
     for (int i = 0; i < states.Length; i++)
     {
         State instance = Object.Instantiate(states[i]);
         instance.stateMachine = this;
         instance.RegisterListeners();
         stateDictionary.Add(instance.GetType(), instance);
         if (currentState == null)
         {
             currentState = instance;
         }
     }
     currentState?.Enter();
 }
Example #21
0
	/// <summary>
	/// Method om de state te wijzigen
	/// </summary>
	public void SetState(StateID stateID) {

		/** als we de stateID niet kennen als state: stop deze functie dan */
		if(!states.ContainsKey(stateID))
			return;

		/** als we ons al in een state bevinden: geef de state de mogelijkheid zich op te ruimen */
		if(currentState != null)
			currentState.Leave();

		/** we stellen de nieuwe currentState in */
		currentState = states[stateID];

		/** we geven de nieuwe state de mogelijkheid om zich zelf in te stellen */
		currentState.Enter();
	}
Example #22
0
    public StateMachine(object controller, State[] states)
    {
        foreach (State state in states)
        {
            State instance = UnityEngine.Object.Instantiate(state);
            instance.owner        = controller;
            instance.stateMachine = this;
            stateDictionary.Add(instance.GetType(), instance);

            // TODO(Fors): Kolla de här, fungerar förmodligen inte
            if (currentState == null)
            {
                currentState = instance;
            }
        }
        currentState?.Enter();
    }
Example #23
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            updateSpriteDirection();

            rabbitVisible = sight.canSee();

            curState.Execute(this);

            if (rabbitVisible && stateEnum != (int)stateType.Chasing)
            {
                curState = new ChaseState();
                stateEnum = (int)stateType.Chasing;
                lastSpotted = EntityManager.Instance.GetPlayer().Position;

                if (FollowingPath)
                    FollowingPath = false;

                curState.Enter(this);
                //curState.Execute(this);
            }
            else if (stateEnum == (int)stateType.Chasing && !rabbitVisible &&
                        Position != lastSpotted)
            {

            }
            else if (stateEnum == (int)stateType.Chasing && !rabbitVisible &&
                        AStarGame.ApproximatelyEqual(Position, lastSpotted))
            {
                curState = new SearchState();
                stateEnum = (int)stateType.Searching;
                doneSearching = false;
                curState.Enter(this);
                //curState.Execute(this);
            }
            else if (stateEnum == (int)stateType.Searching && doneSearching)
            {
                FollowingPath = false;
                curState = new PatrolState();
                stateEnum = (int)stateType.Patrolling;
                curState.Enter(this);
                //curState.Execute(this);
            }
        }
Example #24
0
 //public void AddOnEnter<T>(Action enterAction) where T : State
 //{
 //    States[typeof(T)].OnEnter += enterAction;
 //}
 //public void AddOnLeave<T>(Action leaveAction) where T : State
 //{
 //    States[typeof(T)].OnLeave += leaveAction;
 //}
 public void SwitchGameState <T>() where T : State
 {
     CurrentState.Leave();
     CurrentState = GetState <T>();
     CurrentState.Enter();
 }
Example #25
0
 override public void AttachedTo(Entity entity)
 {
     base.AttachedTo(entity);
     State.Enter(entity);
 }
Example #26
0
 public State TransitionTo(State next)
 {
     Exit();
     next?.Enter();
     return(next);
 }
Example #27
0
 public void Initialize(State startState)
 {
     currentState = startState;
     currentState.Enter();
 }
Example #28
0
 public void ResetOnDie()
 {
     _currentState.Exit();
     _currentState = _firstState;
     _currentState.Enter(_target, _speed);
 }
Example #29
0
 //Initialize a state and set the FSM's current to that state
 public void ChangeState(State newState, Player owner)
 {
     CurrentForm = newState.Enter(owner);
 }
Example #30
0
    public void ChangeState(string TransitionID)
    {
        if (TransitionID.Length == 0)
        {
            Debug.LogError("Empty string!");
            return;
        }

        Transition _tmp = currentS.GetTransition(TransitionID);

        if (_tmp.Destination == null)
        {
            Debug.LogError("Can't find suitable transition!");
        }
        else
        {
            foreach (KeyValuePair<string, State> e in stateList)
            {
                if (e.Value == _tmp.Destination)
                {
                    currentS.Exit(this.gameObject);

                    currentS = _tmp.Destination;

                    currentS.Enter(this.gameObject);

                    break;
                }
            }
        }
    }
Example #31
0
 public void ChangeState(State newState)
 {
     currentState.Exit();
     currentState = newState;
     currentState.Enter();
 }
Example #32
0
 public void ChangeState(T key)
 {
     mCurrentState?.Exit();
     mCurrentState = mStateDictionary?[key];
     mCurrentState?.Enter();
 }
Example #33
0
 //add new state, don't pop current state
 public void AddState(State newState)
 {
     states.Add(newState);
     newState.Enter();
 }
Example #34
0
 public void Initialize(State startingState)
 {
     CurrentState = startingState;
     startingState.Enter();
 }
Example #35
0
            public override void InitializeStates(out BaseState defaultState)
            {
                defaultState = NotOperational;

                root
                .EventTransition(GameHashes.OperationalChanged, NotOperational, smi => !smi.IsOperational);

                NotOperational
                .QueueAnim("off")
                .EventTransition(GameHashes.OperationalChanged, NoLight, smi => smi.IsOperational);

                NoLight
                .QueueAnim("off")
                .Enter(smi => smi.master.operational.SetActive(false))
                .Update("NoLight", (smi, dt) => { if (smi.HasLight() && smi.HasEnoughMass(GameTags.Fertilizer))
                                                  {
                                                      smi.GoTo(GotFert);
                                                  }
                        }, UpdateRate.SIM_1000ms);

                GotFert
                .PlayAnim("on_pre")
                .OnAnimQueueComplete(NoWater);

                LostFert
                .PlayAnim("on_pst")
                .OnAnimQueueComplete(NoFert);

                NoFert
                .QueueAnim("off")
                .EventTransition(GameHashes.OnStorageChange, GotFert, smi => smi.HasEnoughMass(GameTags.Fertilizer))
                .Enter(smi => smi.master.operational.SetActive(false));

                NoWater
                .QueueAnim("on")
                .Enter(smi => smi.master.GetComponent <PassiveElementConsumer>().EnableConsumption(true))
                .EventTransition(GameHashes.OnStorageChange, LostFert, smi => !smi.HasEnoughMass(GameTags.Fertilizer))
                .EventTransition(GameHashes.OnStorageChange, GotWater, smi => smi.HasEnoughMass(GameTags.Fertilizer) && smi.HasEnoughMass(GameTags.Water));

                GotWater
                .PlayAnim("working_pre")
                .OnAnimQueueComplete(GeneratingOxygen);

                GeneratingOxygen
                .Enter(smi => smi.master.operational.SetActive(true))
                .Exit(smi => smi.master.operational.SetActive(false))
                .QueueAnim("working_loop", true)
                .EventTransition(GameHashes.OnStorageChange, StoppedGeneratingOxygen,
                                 smi => !smi.HasEnoughMass(GameTags.Water) || !smi.HasEnoughMass(GameTags.Fertilizer))
                .Update("GeneratingOxygen", (smi, dt) => { if (!smi.HasLight())
                                                           {
                                                               smi.GoTo(StoppedGeneratingOxygen);
                                                           }
                        }, UpdateRate.SIM_1000ms);

                StoppedGeneratingOxygen
                .PlayAnim("working_pst")
                .OnAnimQueueComplete(StoppedGeneratingOxygenTransition);

                StoppedGeneratingOxygenTransition
                .Update("StoppedGeneratingOxygenTransition", (smi, dt) => { if (!smi.HasLight())
                                                                            {
                                                                                smi.GoTo(NoLight);
                                                                            }
                        }, UpdateRate.SIM_200ms)
                .EventTransition(GameHashes.OnStorageChange, NoWater, smi => !smi.HasEnoughMass(GameTags.Water) && smi.HasLight())
                .EventTransition(GameHashes.OnStorageChange, LostFert, smi => !smi.HasEnoughMass(GameTags.Fertilizer) && smi.HasLight())
                .EventTransition(GameHashes.OnStorageChange, GotWater, smi => smi.HasEnoughMass(GameTags.Water) && smi.HasLight() &&
                                 smi.HasEnoughMass(GameTags.Fertilizer));
            }
Example #36
0
    public void ChangeState()
    {
        previous_state = current_state;

        if (owner.Objectives.Queue.Count != 0)
        {
            Goal g = owner.Objectives.Queue[0];
            switch (g.Type)
            {
            case Goal.Objective_T.TRAP:

                current_state.Exit();
                current_state = new HandleTraps(owner.gameObject);

                break;

            case Goal.Objective_T.MONSTER:

                current_state.Exit();
                current_state = new AttackEnnemy(owner.gameObject);
                break;

            case Goal.Objective_T.RELIC:

                if (previous_state is GoToObj)
                {
                    (current_state as GoToObj).UpdateDestination();
                }
                else
                {
                    current_state.Exit();
                    current_state = new GoToObj(owner.gameObject);
                }
                break;

            case Goal.Objective_T.KEY:
                if (previous_state is GoToObj)
                {
                    (current_state as GoToObj).UpdateDestination();
                }
                else
                {
                    current_state.Exit();
                    current_state = new GoToObj(owner.gameObject);
                }

                break;

            case Goal.Objective_T.PANEL:
                current_state.Exit();
                current_state = new HandlePanel(owner.gameObject);
                break;

            default:
                if (current_state != previous_state)
                {
                    previous_state.Exit();
                }
                break;
            }
        }
        else
        {
            previous_state = current_state;
            current_state.Exit();
            current_state = new GoHome(owner.gameObject);
            current_state.Enter();
        }
    }
Example #37
0
 public void ChangeState( State nextState )
 {
     currentState.Exit(_context);
     currentState = nextState;
     currentState.Enter(_context);
 }
Example #38
0
 public void Init(State initState, Directions moveDir, Directions weaponDir)
 {
     CurrentState = states.Find(s => s.state == initState.state);
     CurrentState.Enter(moveDir, weaponDir);
 }
Example #39
0
 public void SetState(State state)
 {
     CurrentState = state;
     CurrentState.Enter(this);
 }
Example #40
0
 public void initialize(State startingState)
 {
     currentState = startingState;
     currentState.Enter(); //initialize
 }
Example #41
0
 public void ChangeState(State newState)
 {
     _currentState.Exit();
     _currentState = newState;
     _currentState.Enter();
 }
Example #42
0
    public override IEnumerator Run(Brain controller)
    {
        if(!triggersBuilt) {
            foreach(TriggerManager manager in controlledTriggers) {
                manager.BuildTrigger(controller);
            }
            triggersBuilt = true;
        }
        yield return StartCoroutine(currentState.Run(controller));

        foreach(TriggerManager manager in currentState.GetTriggers()) {
            if(manager.ShouldTrigger()) {
                nextState = manager.target;
                Debug.Log("Triggered Transition: " + nextState.GetType().Name);
            }
        }
        if(nextState != null) {
            yield return StartCoroutine(currentState.Exit());
            currentState = nextState;
            nextState = null;
            yield return StartCoroutine(currentState.Enter(this, controller));
        }
    }
 public void SetState(State state)
 {
     activState?.Exit();
     activState = state;
     activState?.Enter();
 }
 public void SetState(string identifier)
 {
     activState?.Exit();
     activState = findState(identifier);
     activState?.Enter();
 }
Example #45
0
 public void SetCurrentState(State s)
 {
     m_CurrentState = s;
     m_CurrentState.Enter(m_Owner);
 }
Example #46
0
 public void TransitionTo <T>(RaycastHit2D hit)
 {
     CurrentState.Exit();
     CurrentState = GetState <T>() as State;
     CurrentState.Enter(hit);
 }
Example #47
0
 /// <summary>
 /// 改变状态
 /// </summary>
 /// <param name="p"></param>
 public void ChangeState(State state)
 {
     m_pCurrentState.Exit(this);
     m_pCurrentState = state;
     m_pCurrentState.Enter(this);
 }
Example #48
0
 void StateChange(State newState)
 {
     if (currState != null)
     {
         currState.Exit();
     }
     currState = newState;
     if (currState != null)
     {
         currState.Enter();
     }
 }
Example #49
0
 public Machine(State _curState)
 {
     curState  = _curState;
     lastState = new State("init");
     curState.Enter(lastState, _curState);
 }
Example #50
0
 private void Start()
 {
     e_CurrentState = new CleanTheHouse();
     e_GlobalState  = new GlobalState_Elsa();
     e_CurrentState.Enter(owner.GetComponent <Elsa>());
 }
Example #51
0
 public void TransitionTo <T>()
 {
     CurrentState.Exit();
     CurrentState = GetState <T>() as State;
     CurrentState.Enter();
 }
Example #52
0
 public void SetCurrentState( string name )
 {
     currentState = states[name];
     currentState.Enter(_context);
 }