Beispiel #1
0
        /// <summary>
        /// Changes the state of the AI State Machine.
        /// Intended to be PROTECTED - only the AI States should be able to call this from their encapsulated transition methods.
        /// Changes the internal state of the AI State Machine based on the given state type Enum.
        /// </summary>
        /// <param name="stateType">The new state type to be changed to.</param>
        /// <param name="optionalData">Optional data to be passed to the transitioning state.</param>
        public void ChangeState(StateEnum stateType, object optionalData = null)
        {
            if (currentState != null)
            {
                // Only time when the current state will be null is when state machine spawns.
                currentState.Exit();
                currentState.enabled = false;
            }

            try
            {
                switch (stateType)
                {
                case StateEnum.Intermission: currentState = GetComponent <AIIntermissionState>(); break;

                case StateEnum.Race: currentState = GetComponent <AIRaceState>(); break;

                case StateEnum.ClientSpectate: currentState = GetComponent <AISpectateState>(); break;

                default: throw new InvalidOperationException("Invalid AI ChangeState attempt: " + stateType.ToString());
                }
                SentrySdk.AddBreadcrumb($"AI State Machine change state from { StateType } to { stateType }.");
                StateType = stateType;
            }
            catch (InvalidOperationException e)
            {
                Debug.LogError(e);
            }

            currentState.enabled = true;
            currentState.Enter(optionalData);
        }