예제 #1
0
        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);
        }
예제 #2
0
        public override void OnOpen()
        {
            string         filepath = Path.Combine(UnityEngine.Application.persistentDataPath, Filepath.SETTINGS);
            SystemLanguage language;
            List <string>  languages = new List <string>();

            if (File.Exists(filepath))
            {
                string json = File.ReadAllText(filepath);
                _settings = JsonConvert.DeserializeObject <GameSettingsVO>(json);
            }
            else
            {
                _settings = new GameSettingsVO()
                {
                    Resolution = Screen.currentResolution
                };
            }

            _svc  = AmbitionApp.GetService <LocalizationSvc>();
            _locs = new Dictionary <SystemLanguage, TextAsset>();
            TextAsset[] locs = Resources.LoadAll <TextAsset>(Filepath.LOCALIZATIONS);
            _languages = new List <SystemLanguage>()
            {
                _settings.Language
            };
            languages.Add(_settings.Language.ToString());

            LocSelector.ClearOptions();
            foreach (TextAsset asset in locs)
            {
                if (Enum.TryParse(asset.name, out language))
                {
                    _locs[language] = asset;
                    if (language != _svc.DefaultLanguage)
                    {
                        _languages.Add(language);
                        languages.Add(language.ToString());
                    }
                }
            }
            LocSelector.AddOptions(languages);
            LocSelector.value            = 0;
            LocSelector.captionText.text = locs[0].name;
            HandleLoc();

            int           index   = 0;
            List <string> options = new List <string>();

            for (int i = 0; i < GameSettingsVO.RESOLUTIONS.Length; ++i)
            {
                if (GameSettingsVO.RESOLUTIONS[i] >= Screen.width)
                {
                    index = (i >> 1);
                }
                options.Add(GameSettingsVO.RESOLUTIONS[i] + " x " + GameSettingsVO.RESOLUTIONS[++i]);
            }

            ResolutionSelector.ClearOptions();
            ResolutionSelector.AddOptions(options);
            ResolutionSelector.value = index;
            ResolutionSelector.RefreshShownValue();
            FullscreenBtnLabel.text = AmbitionApp.Localize(Screen.fullScreen ? "options.windowed" : "options.fullscreen");
        }