Beispiel #1
0
    //设置时间缩放,如果是0的话,游戏完全暂停。注意如果没有设置持续时间的话,用完要自己释放
    public TimeScaleHandle AddTimeScale(float scale, float duration, int priority = 0)
    {
        TimeScaleHandle handle = new TimeScaleHandle(scale, duration);

        m_timeScale.Add(handle, priority);
        return(handle);
    }
        protected override void OnEnable()
        {
            base.OnEnable();
            Observe(_gameManager.OnNewDayBegin);
            Observe(_gameManager.OnDayEnd);
            Observe(_gameManager.OnTimerChanged);
            Observe(_settingsManager.OnLoadGame);
            Observe(_settingsManager.OnLoadSettings);

            _lastTimerSec = Mathf.FloorToInt(_gameManager.DayTimeLeft % 60);

            void PlayButtonClickSound()
            {
                _soundManager.Sfx.Play(ButtonClickSound);
            }

            SaveButton.onClick.AddListener(() =>
            {
                _settingsManager.SaveGame();
                PlayButtonClickSound();
            });

            LoadButton.onClick.AddListener(() =>
            {
                _settingsManager.LoadGame();
                PlayButtonClickSound();
            });

            MusicVolumeSlider.onValueChanged.AddListener(delegate { MusicVolumeChanged(); });
            SoundVolumeSlider.onValueChanged.AddListener(delegate { SoundVolumeChanged(); });

            var finishPositionX = SettingsButton.transform.localPosition.x;

            SettingsButton.transform.DOLocalMoveX(finishPositionX, 1).From(finishPositionX - 200); //не стал длительность и оффсет в переменные выносить, здесь не важно


            NextDayButton.onClick.AddListener(() =>
            {
                PlayButtonClickSound();

                foreach (var it in OnNextDayButtonPress.Enumerate())
                {
                    it.Do();
                }
                _gameManager.EndDay();
            });

            PauseButton.onClick.AddListener(() =>
            {
                PlayButtonClickSound();

                float scale = 0.0f;

                if (timeScaleHandle == null)
                {
                    timeScaleHandle = new TimeScaleHandle();
                }

                if (Time.timeScale > 0.0f)
                {
                    _timeScaleManager.BeginTimeScale(timeScaleHandle, scale);
                }
                else
                {
                    _timeScaleManager.EndTimeScale(timeScaleHandle);
                }

                foreach (var it in OnPauseButtonPress.Enumerate())
                {
                    it.Do();
                }
            });

            AppQuitButton.onClick.AddListener(() =>
            {
                Application.Quit();
                PlayButtonClickSound();
            });

            SettingsButton.onClick.AddListener(() =>
            {
                PlayButtonClickSound();

                _iSceneStateManager.Push(_settingsMenuState);

                foreach (var it in OnSettingsButtonPress.Enumerate())
                {
                    it.Do();
                }
            });

            LanguageSelector.GetComponent <Dropdown>().onValueChanged.AddListener(delegate {
                _settingsManager.ChangeLanguage(LanguageSelector.GetComponent <Dropdown>().value);
            });

            GraficPresetSelector.GetComponent <Dropdown>().onValueChanged.AddListener(delegate {
                _settingsManager.ChangeGraficPreset(GraficPresetSelector.GetComponent <Dropdown>().value);
            });
        }