Example #1
0
    //Switches the current state to a state of the the given type
    public virtual bool SetState <StateType> () where StateType : State
    {
        bool Success = false;

        //Search through the list of available state for one which matches the given type
        foreach (State State in States)
        {
            //If we find a matching state then swap to that one
            if (State is StateType)
            {
                Success = SetState(State);
                return(Success);
            }
        }

        //If we couldnt find any matching state check if there is one on this gameObject
        State StateComponent = GetComponent <StateType>();

        if (StateComponent)
        {
            //Update to this state if it was found on the gameObject
            StateComponent.Initialize(this);
            States.Add(StateComponent);
            Success = SetState(StateComponent);
            return(Success);
        }

        //If we still couldnt find the state we were looking for then we need to initialize a new one to use
        State NewState = gameObject.AddComponent <StateType>();

        NewState.Initialize(this);
        States.Add(NewState);
        Success = SetState(NewState);
        return(Success);
    }
Example #2
0
            public static State Generate(SyntaxNode declaration, SemanticModel semanticModel, OptionSet optionSet, bool isVariableDeclarationContext, CancellationToken cancellationToken)
            {
                var state = new State(isVariableDeclarationContext);

                state.Initialize(declaration, semanticModel, optionSet, cancellationToken);
                return(state);
            }
    private IEnumerator Change(string _name, bool _animated, params object[] _data)
    {
        if (loadingView != null && _animated)
        {
            yield return(loadingView.StartAnimation());
        }

        var beforeState = currentState;

        if (beforeState != null)
        {
            beforeState.Release();
            Destroy(beforeState.gameObject);
        }

        if (states.ContainsKey(_name))
        {
            currentState = Instantiate(states[_name]);
        }
        else
        {
            Debug.LogFormat("state key is not contain : {0}", _name);
            currentState = beforeState;
        }

        yield return(currentState.Initialize(_data));

        if (loadingView != null && _animated)
        {
            //loadingView.SetActive(false);
            yield return(loadingView.FinishAnimation());
        }

        currentState.Begin();
    }
Example #4
0
        protected override void Initialize()
        {
            Content.RootDirectory = "Content";

            State.Initialize(this);
            base.Initialize();
        }
Example #5
0
    /// <summary>
    /// Switch the currentState to a State of a the given type.
    /// </summary>
    /// <typeparam name="StateType">
    /// The type of state to use for the currentState</typeparam>
    /// <returns>Whether the state was changed</returns>
    public virtual bool SetState <StateType>(object args = null) where StateType : State
    {
        bool success = false;

        //if the state can be found in the list of states
        //already created, switch to the existing version
        foreach (State state in statesList)
        {
            if (state is StateType)
            {
                success = SetState(state, args);
                return(success);
            }
        }
        //if the state is not found in the list,
        //see if it is on the gameobject.
        State stateComponent = GetComponent <StateType>();

        if (stateComponent)
        {
            stateComponent.Initialize(this);
            statesList.Add(stateComponent);
            success = SetState(stateComponent, args);
            return(success);
        }
        //if it is not on the gameobject,
        //make a new instance
        State newState = gameObject.AddComponent <StateType>();

        newState.Initialize(this);
        statesList.Add(newState);
        success = SetState(newState, args);

        return(success);
    }
Example #6
0
        protected override void OnExperimentStart()
        {
            // Initialize RL state
            Lots         = new Lot[LotGenerator.TargetWIP];
            Machines     = new Machine[WorkStations.Values.SelectMany(x => x.Machines).Count()];
            ProductTypes = new string[Sequences.Count()];
            MachineIndexes.Clear();
            ProductTypeIndexes.Clear();

            int machineIndex = 0;

            foreach (Machine machine in WorkStations.Values.SelectMany(x => x.Machines).OrderBy(x => x.Index))
            {
                Machines[machineIndex] = machine;
                MachineIndexes.Add(machine, machineIndex);
                machineIndex++;
            }

            int ptIndex = 0;

            foreach (string type in Sequences.Keys.OrderBy(x => x))
            {
                ProductTypes[ptIndex] = type;
                ProductTypeIndexes.Add(type, ptIndex);
                ptIndex++;
            }

            State.Initialize();

            // Initialize TargetCycleTimesPerStep in Sequences
            foreach (Sequence seq in Sequences.Values)
            {
                seq.CalculateTargetCycleTimesPerStep();
            }
        }
Example #7
0
        /// <summary>
        /// Switches the currentState to a State of a given type, checking if it already exists.
        /// </summary>
        /// <typeparam name="StateType">
        /// The type of the State to use for the currentState</typeparam>
        /// <returns>Whether the State was changed</returns>
        public virtual State SwitchState <StateType>() where StateType : State
        {
            // if the state can be found in the list of states.
            // already created, switch to the existing version.
            foreach (State state in statesList)
            {
                if (state is StateType)
                {
                    return(SetState(state));
                }
            }

            State stateComponent = GetComponent <StateType>();

            if (stateComponent)
            {
                stateComponent.Initialize(this);
                statesList.Add(stateComponent);
                return(SetState(stateComponent));
            }

            // if the state is not found in the list make a new instance.
            State newState = gameObject.AddComponent <StateType>();

            newState.Initialize(this);
            statesList.Add(newState);
            return(SetState(newState));
        }
Example #8
0
 public void SetState(State nextState)
 {
     if (!npcStats.IsDead)
     {
         nextState.Initialize();
         currentState = nextState;
     }
 }
Example #9
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            this.IsMouseVisible = true;

            InputManager.The.init();
            GlobalState.Initialize(null);
        }
    private StunManager stunManager;// The StunManager attached to the current player.

    void Start()
    {
        transitionQueue = new Queue <State>();
        currentState    = defaultState;
        currentState.Initialize();
        currentCostates = defaultCostates;

        stunManager = GetComponent <StunManager>();
    }
Example #11
0
        void ReplayGameHandler(object sender, EventArgs e)
        {
            UnhookHomeStateEvents();

            GlobalState = new GameState();
            GlobalState.Initialize(null);
            GlobalState.LoadContent(Content);

            HookGameStateEvents();
        }
        /// <summary>
        /// Activate grain (state and polling as ES and RC)
        /// </summary>
        public async override Task OnActivateAsync()
        {
            State.Initialize(WriteStateAsync);

            await OnActivatePersistAsync();

            await _es_service.Consume((int number) => IsPrime(number), InterfaceConst.PSPrime);

            await base.OnActivateAsync();
        }
 /// <summary>
 /// Transitions to the next State in the transition queue if there are any available.
 /// </summary>
 private void AdvanceTransitionQueue()
 {
     if (transitionQueue.Count != 0)
     {
         State transitionTo = transitionQueue.Dequeue();
         currentState.Deinitialize();
         previousState = currentState;
         currentState  = transitionTo;
         transitionTo.Initialize();
     }
 }
Example #14
0
        /// <summary>
        /// Remove all existing states and set it to the given new state.
        /// </summary>
        /// <param name="newState">State to set the game to.</param>
        public void ChangeState(State newState)
        {
            State oldState = currentState;

            currentState = newState;

            oldState.UnloadContent();
            oldState = null;

            currentState.Initialize();
            currentState.LoadContent();
        }
Example #15
0
 private void Update()
 {
     while (true)
     {
         if (!State.IsFinished())
         {
             return;
         }
         State = State.NextState();
         State.Initialize();
     }
 }
Example #16
0
 public StateMachine(object Controller, State[] States, State EntryState = null)
 {
     CurrentState = EntryState;
     foreach (State State in States)
     {
         State Instance = UnityEngine.Object.Instantiate(State);
         Instance.Initialize(Controller, this);
         StateMap.Add(Instance.GetType(), Instance);
         CurrentState ??= Instance;
     }
     CurrentState.Enter();
 }
Example #17
0
 /// <summary>
 /// Changes the current state.
 /// </summary>
 public void ChangeState()
 {
     if (nextState != null && nextState != State)
     {
         if (State != null)
         {
             State.Release();
         }
         State = nextState;
         State.Initialize();
         nextState = null;
     }
 }
Example #18
0
    private void Awake()
    {
        brain  = GetComponent <Brain>();
        states = new Dictionary <StateID, State>();

        foreach (State state in stateTemplates)
        {
            State stateCopy = Instantiate(state);
            stateCopy.Initialize(brain, this);
            states.Add(stateCopy.id, stateCopy);
        }

        currentState = states[startState];
    }
Example #19
0
 protected virtual void Awake()
 {
     foreach (State state in states)
     {
         State instance = Instantiate(state);
         instance.Initialize(this);
         stateDictionary.Add(instance.GetType(), instance);
         if (currentState == null)
         {
             currentState = instance;
         }
     }
     currentState.Enter();
 }
Example #20
0
 protected virtual void Awake()
 {
     foreach (State s in states)
     {
         State state = Instantiate(s);
         state.Initialize(this);
         allStates.Add(state.GetType(), state);
         if (currentState == null)
         {
             currentState = state;
         }
     }
     currentState.Enter();
 }
Example #21
0
    // Function used to switch state from a previous to a new one.
    protected virtual void SwitchState()
    {
        // If the next state is null, it means  the current state did not
        // returned any new state when handling the inputs.
        if (m_nextState == null)
        {
            return;
        }

        m_nextState.Initialize(this);
        currentState.Exit();
        currentState = m_nextState;
        currentState.Enter();
        m_nextState = null;
    }
Example #22
0
 public void Awake()
 {
     foreach (State state in _states)
     {
         State instance = Instantiate(state);
         instance.Initialize(this);
         _stateDictionary.Add(instance.GetType(), instance);
         if (CurrentState != null)
         {
             continue;
         }
         CurrentState = instance;
         CurrentState.Enter();
     }
 }
Example #23
0
        void SessionGameStartedHandler(object sender, GameStartedEventArgs e)
        {
            if (Session.IsHost)
            {
                GlobalState = new GameState();
                GlobalState.Initialize(null);
            }
            else
            {
                GlobalState = new ClientState();
                GlobalState.Initialize(null);
            }

            GlobalState.LoadContent(Content);
            HookGameStateEvents();
        }
Example #24
0
        private void Initialize(int id, Bird bird, BirdTypeData birdType)
        {
            Initialize(id);

            name = $"Player {Id}";
            Bird = bird;

            Bird.Initialize(this, birdType);
            Controller.Initialize(this);
            State.Initialize();

            _godRay = Instantiate(PlayerManager.Instance.PlayerGodRayPrefab, transform);
            _godRay.SetupPlayer(this);

            LogInfo();
        }
Example #25
0
 /*******************************************************************************************
 ********************************************************************************************
 *
 *  ●●●●●●●●●●●●●●●●●●●● View ●●●●●●●●●●●●●●●●●●●●
 *
 ********************************************************************************************
 *******************************************************************************************/
 //●Index
 public IActionResult Index()
 {
     using (var db = new ShopDbContext())
     {
         //DBに初期値のデータを入れる
         ProductImages.Initialize(db);
         ProductCategoryList.Initialize(db);
         Product.Initialize(db);
         Country.Initialize(db);
         State.Initialize(db);
         City.Initialize(db);
         Models.User.Initialize(db);
         //Index画面に表す6個を呼び出す
         var model = db.Product.OrderByDescending(n => n.ProductNo).Take(6).ToList();
         return(View(model));
     }
 }
 public State GetState(Type type)
 {
     if (_stateCache.ContainsKey(type))
     {
         return(_stateCache[type]);
     }
     else
     {
         //State state = (State) Activator.CreateInstance(type,Game);
         State state = (State)Activator.CreateInstance(type);
         state.Game = Game;
         state.Initialize();
         state.LoadContent();
         _stateCache[type] = state;
         return(state);
     }
 }
 protected virtual void Awake()
 {
     foreach (State state in states)
     {
         //Går igenom states, Gör kopia med instantiate
         //Initialize på Statenn och lägger till dem i dictionary
         State instance = Instantiate(state);
         instance.Initialize(this);
         stateDictionary.Add(instance.GetType(), instance);
         if (currentState != null) // om vi inte har currentState lägger vi till den första staten som det
         {
             continue;
         }
         currentState = instance;
         currentState.Enter();
     }
 }
Example #28
0
        void CreateGameHandler(object sender, EventArgs e)
        {
            try
            {
                Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
                HookSessionEvents();
            }
            catch (Exception exception)
            {
            }
        }
Example #29
0
        /// <summary>
        /// Setup the circuit
        /// </summary>
        public void Setup()
        {
            if (IsSetup)
            {
                return;
            }
            IsSetup = true;

            // Rebuild the list of circuit components
            Components.BuildOrderedComponentList();

            // Setup all devices
            foreach (var c in Components)
            {
                c.Setup(this);
            }

            // Initialize the state
            State.Initialize(this);
        }
Example #30
0
        /// <summary>
        /// Moves to another state.
        /// </summary>
        /// <param name="id">State identifier</param>
        /// <param name="parameters">Arguments needed by the state constructor.</param>
        /// <param name="swap">Swaps current state with the new one or no.</param>
        public void GoTo(StateID id, object[] parameters, bool swap)
        {
            //Search for existing state
            State Destination = null;

            foreach (State state in m_StateList)
            {
                if (state.GetIdentifier() == id)
                {
                    Destination = state;
                }
            }

            //If exist, return there
            if (Destination != null)
            {
                ReturnTo(Destination);
            }
            else
            {
                //Create new state
                State NewState = StateFactory.Instance().CreateState(id, parameters);

                //If not swap, add it on the last
                if (!swap)
                {
                    AddState(NewState);
                }
                else
                {
                    //Add it before
                    m_Depth += 1;
                    m_StateList.AddBefore(m_StateList.Last, NewState);
                    NewState.Initialize();

                    //Logging
                    Global.Logger.AddLine(NewState + " has been added to the state list.");
                }
            }
        }
Example #31
0
        void SessionGameStartedHandler(object sender, GameStartedEventArgs e)
        {
            if (Session.IsHost)
            {
                GlobalState = new GameState();
                GlobalState.Initialize(null);
            }
            else
            {
                GlobalState = new ClientState();
                GlobalState.Initialize(null);
            }

            GlobalState.LoadContent(Content);
            HookGameStateEvents();
        }
Example #32
0
        void CreateGameHandler(object sender, EventArgs e)
        {
            try
            {
                Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
                HookSessionEvents();
            }
            catch (Exception exception)
            {

            }
        }
Example #33
0
        void JoinGameHandler(object sender, EventArgs e)
        {
            AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null);
            if (sessions.Count < 1)
                return;
            Session = NetworkSession.Join(sessions[0]);
            if (Session != null)
            {
                HookSessionEvents();

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
            }
        }
Example #34
0
        void ReplayGameHandler(object sender, EventArgs e)
        {
            UnhookHomeStateEvents();

            GlobalState = new GameState();
            GlobalState.Initialize(null);
            GlobalState.LoadContent(Content);

            HookGameStateEvents();
        }
    public void SetState(State nextState)
    {
        Assert.IsNotNull(nextState, "Next State is NULL");
        Debug.Log("Passing from state " + currentState + " to " + nextState);
        // Change the pivot of the current menu to set it outside of view
        if (currentState)
            //this.currentState.GetComponent<RectTransform>().pivot = closedMenuPivot;
            currentState.gameObject.SetActive(false);

        // Initialize the next state
        nextState.Initialize();

        // Set the current state to be the next state
        currentState = nextState;

        // Set the next state to be in view
        //this.currentState.GetComponent<RectTransform>().pivot = openMenuPivot;
        currentState.gameObject.SetActive(true);
    }
 public static State Generate(SyntaxNode declaration, SemanticModel semanticModel, OptionSet optionSet, bool isVariableDeclarationContext, CancellationToken cancellationToken)
 {
     var state = new State(isVariableDeclarationContext);
     state.Initialize(declaration, semanticModel, optionSet, cancellationToken);
     return state;
 }