public override void OnClose() { AudioSvc audio = AmbitionApp.GetService <AudioSvc>(); string path = Path.Combine(UnityEngine.Application.persistentDataPath, Filepath.SETTINGS); _settings.Volume = new Dictionary <AudioChannel, int>() { { AudioChannel.Ambient, audio.GetVolume(AudioChannel.Ambient) }, { AudioChannel.Sfx, audio.GetVolume(AudioChannel.Sfx) }, { AudioChannel.Music, audio.GetVolume(AudioChannel.Music) }, { AudioChannel.Master, audio.GetVolume(AudioChannel.Master) } }; _settings.Resolution = Screen.currentResolution; _settings.Language = _languages[LocSelector.value]; File.WriteAllText(path, JsonConvert.SerializeObject(_settings)); }
// Not used, but useful to keep around IEnumerator SetVolume(AudioChannel channel, int delta) { AudioSvc audio = AmbitionApp.GetService <AudioSvc>(); int volume = audio.GetVolume(channel); do { volume += delta; if (volume < 0) { volume = 0; } else if (volume > 100) { volume = 100; } audio.SetVolume(channel, volume); _settings.Volume[channel] = volume; yield return(null); }while (volume >= 0 && volume <= 100); _settings.Volume[channel] = volume; }
static void Initialize() { LocalizationSvc loc = App.Register <LocalizationSvc>(); App.Register <MessageSvc>(); App.Register <CommandSvc>(); App.Register <ModelSvc>().Register <LocalizationModel>(); AudioSvc audio = App.Register <AudioSvc>(); AmbitionApp.RegisterCommand <LoadGameCmd, string>(GameMessages.LOAD_GAME); AmbitionApp.RegisterCommand <QuitGameCmd>(GameMessages.QUIT_GAME); AmbitionApp.RegisterCommand <AmbitionErrorCmd, ErrorEventArgs>(GameMessages.ERROR); // Load game settings Application.targetFrameRate = 60; string filepath = Path.Combine(UnityEngine.Application.persistentDataPath, Filepath.SETTINGS); GameSettingsVO settings; if (File.Exists(filepath)) { string json = File.ReadAllText(filepath); settings = JsonConvert.DeserializeObject <GameSettingsVO>(json); } else { settings = new GameSettingsVO() { Fullscreen = true }; for (int i = 0; i < GameSettingsVO.RESOLUTIONS.Length; i += 2) { if (Screen.currentResolution.width >= GameSettingsVO.RESOLUTIONS[i]) { settings.Resolution = new Resolution() { width = GameSettingsVO.RESOLUTIONS[i], height = GameSettingsVO.RESOLUTIONS[i + 1], refreshRate = Screen.currentResolution.refreshRate }; break; } } } foreach (KeyValuePair <AudioChannel, int> volume in settings.Volume) { audio.SetVolume(volume.Key, volume.Value); } // TODO: Finish locs TextAsset txt = Resources.Load <TextAsset>(Filepath.LOCALIZATIONS + SystemLanguage.English.ToString()); //TextAsset txt = Resources.Load<TextAsset>(Filepath.LOCALIZATIONS + settings.Language.ToString()); if (txt != null) { // TODO: Load loc-relevant fonts in assetbundle FontSet fonts = Resources.Load <FontSet>("LocFonts/" + SystemLanguage.English.ToString() + "/Fonts"); loc.DefaultLanguage = settings.Language; loc.LoadLocFile(settings.Language, txt.text); loc.ClearProxyFonts(); loc.DefaultFont = fonts?.Default; if (fonts?.Fonts != null) { foreach (FontSet.FontSubstitution proxy in fonts.Fonts) { loc.SetProxyFont(proxy.ProxyFont, proxy.SubstitutionFont); } } } Screen.SetResolution(settings.Resolution.width, settings.Resolution.height, settings.Fullscreen, settings.Resolution.refreshRate); AmbitionApp.SendMessage(GameMessages.UPDATE_LOCALIZATION, settings.Language); }