예제 #1
0
    /// <summary>Handles debugging features</summary>
    private void Update()
    {
        // the debug menu shouldn't function if the game is frozen
        if (Time.timeScale <= 0f)
        {
            return;
        }

        // toggle the debug menu
        if (Input.GetKeyDown(KeyCode.F9))
        {
            _debug = !_debug;

            // if the debug menu was on previously,
            // turn off any cheats that may be on.
            if (!_debug)
            {
                _noclip         = false;
                _infiniteEnergy = false;
                _infiniteHealth = false;

                // make hud visible
                _hudUi.SetActive(true);
            }
        }

        // debug mode is off, nothing more to do here
        if (!_debug)
        {
            return;
        }

        // retrieve object and component references
        if (_player == null)
        {
            _player = GameObject.Find("SimplePlayer");
        }
        if (_fpController == null)
        {
            _fpController = _player?.GetComponent <vp_FPController>();
        }
        if (_camera == null)
        {
            _camera = GameObject.Find("FPSCamera");
        }
        if (_hudUi == null)
        {
            _hudUi = GameObject.Find("HudUI");
        }

        // decrement time of day
        if (Input.GetKeyDown(KeyCode.LeftBracket))
        {
            _timeDir.AdjustTimeOfDay(-0.0416666679f);

            // check for negative time
            if (_timeDir.WorldTime() <= 0f)
            {
                _timeDir.SetWorldTime(0f);
            }
        }

        // increment time of day
        else if (Input.GetKeyDown(KeyCode.RightBracket))
        {
            _timeDir.AdjustTimeOfDay(0.0416666679f);
        }

        // toggle help menu
        if (Input.GetKeyDown(KeyCode.F10))
        {
            _showHelp = !_showHelp;
        }

        // add 1000 credits
        if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            _playerState.AddCurrency(1000);
        }

        // subtract 1000 credits
        else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            _playerState.AddCurrency(-1000);
        }

        // toggle heads-up display
        if (Input.GetKeyDown(KeyCode.F6))
        {
            _hudUi.SetActive(!_hudUi.activeSelf);
        }

        // reset player progress
        if (Input.GetKeyDown(KeyCode.F12))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Reset");
            _pediaDir.DebugClearUnlocked();
            _tutorialDir.DebugClearCompleted();
            _achieveDir.DebugClearAwarded();
            _progressDir.DebugClearProgress();
        }

        // unlock all progress
        else if (Input.GetKeyDown(KeyCode.F11))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Unlocked");
            _pediaDir.DebugAllUnlocked();
            _tutorialDir.DebugAllCompleted();
            _achieveDir.DebugAllAwarded();
            _progressDir.DebugUnlockProgress();
        }

        // unlock all upgrades
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            Console.WriteLine("DEBUG: All Personal Upgrades");
            _playerState.DebugGiveAllUpgrades();
            _playerState.SetHealth(_playerState.GetMaxHealth());
            _playerState.SetEnergy(_playerState.GetMaxEnergy());

            // add 5 keys
            for (var i = 0; i < 5; i++)
            {
                _playerState.AddKey();
            }
        }

        // fill inventory with random items and ammo
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            Console.WriteLine("DEBUG: Fill Ammo");
            _playerState.Ammo.DebugFillRandomAmmo(_playerState.GetMaxAmmo());
        }

        // toggle infinite energy
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            _infiniteEnergy = !_infiniteEnergy;
        }

        // toggle infinite health
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            _infiniteHealth = !_infiniteHealth;
        }

        // clear inventory
        if (Input.GetKeyDown(KeyCode.M))
        {
            _playerState.Ammo.Clear();
        }

        // toggle noclip
        if (Input.GetKeyDown(KeyCode.N) && _player)
        {
            _noclip    = !_noclip;
            _noclipPos = _player.transform.position;
        }

        // force the game to save
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            Console.WriteLine("DEBUG: Forcing save now");
            _autoSave.SaveAllNow();
        }

        // handle noclip, if it's enabled
        if (_noclip && _camera && _fpController)
        {
            // calculate speed, will be multiplied by two if run is held
            var speed = 20f * (SRInput.Actions.run.State ? 2f : 1f);

            // add movement
            _noclipPos += _camera.transform.forward * SRInput.Actions.vertical.RawValue * speed * Time.deltaTime;
            _noclipPos += _camera.transform.right * SRInput.Actions.horizontal.RawValue * speed * Time.deltaTime;

            // stop all movement on the controller and reposition it
            _fpController.Stop();
            _fpController.SetPosition(_noclipPos);
        }

        if (_infiniteEnergy) // infinite energy's on, set our energy to max
        {
            _playerState.SetEnergy(_playerState.GetMaxEnergy());
        }

        if (_infiniteHealth) // god mode's on, set our health to max
        {
            _playerState.SetHealth(_playerState.GetMaxHealth());
        }
    }
    /// <summary>Handles debugging features</summary>
    private void Update()
    {
        // retrieve the directors
        if (!_timeDir)
        {
            _timeDir = FindObjectOfType <TimeDirector>();
        }
        if (!_pediaDir)
        {
            _pediaDir = FindObjectOfType <PediaDirector>();
        }
        if (!_tutorialDir)
        {
            _tutorialDir = FindObjectOfType <TutorialDirector>();
        }
        if (!_achieveDir)
        {
            _achieveDir = FindObjectOfType <AchievementsDirector>();
        }
        if (!_progressDir)
        {
            _progressDir = FindObjectOfType <ProgressDirector>();
        }
        if (!_playerState)
        {
            _playerState = FindObjectOfType <PlayerState>();
        }
        if (!_autoSave)
        {
            _autoSave = FindObjectOfType <AutoSaveDirector>();
        }
        if (!_inputDir)
        {
            _inputDir = FindObjectOfType <InputDirector>();
            if (_inputDir) // prevent user from submitting bug reports.
            {
                var bugReportUI = _inputDir.bugReportPrefab.GetComponentInChildren <BugReportUI>();
                bugReportUI.submitButton.interactable = false;
                bugReportUI.summaryField.interactable = false;
                bugReportUI.descField.interactable    = false;

                bugReportUI.summaryField.text = "Debug Menu Mod installed - Reporting Issues is deactivated";
                bugReportUI.descField.text    = "Notice: While this debug menu mod is active, you will not be able to report bugs. " +
                                                "This mod is not supported by Monomi Park and never will be.";
            }
        }

        // retrieve object and component references
        if (!_player)
        {
            _player = GameObject.Find("SimplePlayer");
        }
        if (!_fpController)
        {
            _fpController = _player?.GetComponent <vp_FPController>();
            if (_noclip)
            {
                StartNoclip();
            }
        }
        if (!_camera)
        {
            _camera = GameObject.Find("FPSCamera");
        }
        if (!_hudUi)
        {
            _hudUi = GameObject.Find("HudUI");
        }

        // the debug menu shouldn't function if the game is frozen
        if (Time.timeScale <= 0f)
        {
            return;
        }

        // toggle the debug menu
        if (Input.GetKeyDown(KeyCode.F9))
        {
            _debug = !_debug;

            // if the debug menu was on previously,
            // turn off any cheats that may be on.
            if (!_debug)
            {
                _noclip         = false;
                _infiniteEnergy = false;
                _infiniteHealth = false;

                // make hud visible
                _hudUi?.SetActive(true);
            }
        }

        // debug mode is off, nothing more to do here
        if (!_debug)
        {
            return;
        }

        // decrement time of day
        if (Input.GetKeyDown(KeyCode.LeftBracket))
        {
            _timeDir?.AdjustTimeOfDay(-0.0416666679f);

            // check for negative time
            if (_timeDir?.WorldTime() <= 0f)
            {
                _timeDir?.SetWorldTime(0f);
            }
        }

        // increment time of day
        else if (Input.GetKeyDown(KeyCode.RightBracket))
        {
            _timeDir?.AdjustTimeOfDay(0.0416666679f);
        }

        // toggle help menu
        if (Input.GetKeyDown(KeyCode.F10))
        {
            _showHelp = !_showHelp;
        }

        // add 1000 credits
        if (Input.GetKeyDown(KeyCode.Equals) || Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            _playerState?.AddCurrency(1000);
        }

        // subtract 1000 credits
        else if (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            _playerState?.AddCurrency(-1000);
        }

        // toggle heads-up display
        if (Input.GetKeyDown(KeyCode.F6))
        {
            _hudUi?.SetActive(!_hudUi.activeSelf);
        }

        // reset player progress
        if (Input.GetKeyDown(KeyCode.F12))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Reset");
            _pediaDir?.DebugClearUnlocked();
            _tutorialDir?.DebugClearCompleted();
            _achieveDir?.DebugClearAwarded();
            _progressDir?.DebugClearProgress();
        }

        // unlock all progress
        else if (Input.GetKeyDown(KeyCode.F11))
        {
            Console.WriteLine("DEBUG: Tutorials/Pedia/Achievements/Progress Unlocked");
            _pediaDir?.DebugAllUnlocked();
            _tutorialDir?.DebugAllCompleted();
            _achieveDir?.DebugAllAwarded();
            _progressDir?.DebugUnlockProgress();
        }

        // unlock all upgrades
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            Console.WriteLine("DEBUG: All Personal Upgrades");
            _playerState?.DebugGiveAllUpgrades();
            _playerState?.SetHealth(_playerState.GetMaxHealth());
            _playerState?.SetEnergy(_playerState.GetMaxEnergy());

            // add 5 keys
            for (var i = 0; i < 5; i++)
            {
                _playerState?.AddKey();
            }
        }

        // fill inventory with random items and ammo
        if (Input.GetKeyDown(KeyCode.Alpha9) && _playerState)
        {
            Console.WriteLine("DEBUG: Fill Ammo");
            _playerState?.Ammo?.DebugFillRandomAmmo();
        }

        // toggle infinite energy
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            _infiniteEnergy = !_infiniteEnergy;
        }

        // toggle infinite health
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            _infiniteHealth = !_infiniteHealth;
        }

        // clear inventory
        if (Input.GetKeyDown(KeyCode.K))
        {
            _playerState?.Ammo?.Clear();
        }

        // refill inventory
        if (Input.GetKeyDown(KeyCode.L) && _playerState)
        {
            _playerState?.Ammo?.DebugRefillAmmo();
        }

        // toggle noclip
        if (Input.GetKeyDown(KeyCode.N) && _player)
        {
            if (!_noclip)
            {
                StartNoclip();
            }
            else
            {
                StopNoclip();
            }
        }

        // force the game to save
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            Console.WriteLine("DEBUG: Forcing save now");
            _autoSave?.SaveAllNow();
        }

        // handle noclip, if it's enabled
        if (_noclip && _camera && _fpController)
        {
            // calculate speed, will be multiplied by two if run is held
            var speed = 20f * (SRInput.Actions.run.State ? 2f : 1f);

            // add movement
            _noclipPos += _camera.transform.forward * SRInput.Actions.vertical.RawValue * speed * Time.deltaTime;
            _noclipPos += _camera.transform.right * SRInput.Actions.horizontal.RawValue * speed * Time.deltaTime;

            // stop all movement on the controller and reposition it
            _fpController?.Stop();
            _fpController?.SetPosition(_noclipPos);
        }

        if (_infiniteEnergy && _playerState) // infinite energy's on, set our energy to max
        {
            _playerState.SetEnergy(_playerState.GetMaxEnergy());
        }

        if (_infiniteHealth && _playerState) // god mode's on, set our health to max
        {
            _playerState.SetHealth(_playerState.GetMaxHealth());
        }
    }