Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MusicController
- {
- private FMOD.Studio.EventInstance _eventInstance;
- public MusicController()
- {
- if (PlayerPrefs.HasKey("music_enabled"))
- return;
- Utils.Prefs.SetBool("music_enabled", true);
- }
- public void PlayMusic(string musicKey)
- {
- StopMusic();
- if (!Utils.Prefs.GetBool("music_enabled"))
- return;
- _eventInstance = RuntimeManager.CreateInstance(musicKey);
- _eventInstance.start();
- }
- public void StopMusic()
- {
- if (!_eventInstance.Equals(default(FMOD.Studio.EventInstance)))
- {
- _eventInstance.stop(STOP_MODE.ALLOWFADEOUT);
- _eventInstance.release();
- }
- }
- }
- // ------------------------------
- public void Init(Transform parent)
- {
- var window = _uiService.Show<UISettingsWindow>();
- window.MusicToggle.Switch(Utils.Prefs.GetBool("music_enabled"));
- window.MusicToggle.OnValueChanged.AddListener(on =>
- {
- Utils.Prefs.SetBool("music_enabled", on);
- if (on)
- _musicController.PlayMusic("event:/Music/MainMusic");
- else
- _musicController.StopMusic();
- });
- window.SoundToggle.Switch(Utils.Prefs.GetBool("sound_enabled"));
- window.SoundToggle.OnValueChanged.AddListener(on => Utils.Prefs.SetBool("sound_enabled", on));
- window.CloseClickCommand.Subscribe(_ => Dispose()).AddTo(CompositeDisposable);
- }
Advertisement
Add Comment
Please, Sign In to add comment