Пример #1
0
        //-------------------------------------------------------------------------------------
        // Game Mode functions

        /// <summary>
        /// Add a known GameMode handler to the class
        /// </summary>
        /// <param name="gameMode"></param>
        public void AddGameModeHandler(GameModeBase gameMode)
        {
            Type modeType = gameMode.GetType();

            // Does this mode already exist in the dictionary?
            if (_gameModeHandlers.ContainsKey(modeType))
            {
                // Yes, so update the dictionary with the newly-provided instance
                _gameModeHandlers[modeType] = gameMode;
            }
            else
            {
                // No, so add to the dictionary with the game mode type name as the key
                _gameModeHandlers.Add(modeType, gameMode);
            }
        }
Пример #2
0
        private void OnSceneChanged(Scene oldScene, Scene newScene)
        {
            foreach (SceneGameModePair sceneGameModePair in Settings.GameModeOverrides)
            {
                if (sceneGameModePair.Scene.ScenePath != newScene.path ||
                    sceneGameModePair.GameModePrefab == null)
                {
                    continue;
                }

                // Spawn custom game override
                GameMode = Instantiate(sceneGameModePair.GameModePrefab);
                return;
            }

            // No game mode override found for the scene, spawn default game mode
            GameMode = Instantiate(Settings.DefaultGameMode);
        }
Пример #3
0
        public T SetGameMode <T>() where T : GameModeBase
        {
            Type modeType = typeof(T);

            // If this is the current mode, do nothing
            if (_currentGameModeHandler != null && modeType == _currentGameModeHandler.GetType())
            {
                return(_currentGameModeHandler as T);
            }

            // Leave the current mode
            if (_currentGameModeHandler != null)
            {
                _currentGameModeHandler.Deactivate();
            }

            // Select the new mode
            if (_gameModeHandlers.ContainsKey(modeType))
            {
                _currentGameModeHandler = _gameModeHandlers[modeType];
            }
            else
            {
                // Don't know of any game mode handler with this name so deactivate the current mode handler
                _currentGameModeHandler = null;
            }

            // Enter the new mode
            if (_currentGameModeHandler != null)
            {
                // Set this handler's list of game objects into the game itself
                GameObjects = _currentGameModeHandler.GameObjects;
                _currentGameModeHandler.Activate();
            }

            return(_currentGameModeHandler as T);
        }