예제 #1
0
        public static string Get(string key, UnityEngine.SystemLanguage language, bool forced = false)
        {
            if (LocalizationSystem.IsReady() == true || forced == true)
            {
                string[] values;
                if (LocalizationSystem.valuesByLanguage.TryGetValue(language, out values) == true)
                {
                    var keys = LocalizationSystem.GetKeys();
                    if (keys != null && key != null)
                    {
                        var index = System.Array.IndexOf(keys, key.ToLower());
                        if (index >= 0 && index < values.Length)
                        {
                            return(values[index]);
                        }
                    }
                }
            }
            else
            {
                if (Application.isPlaying == true)
                {
                    WindowSystemLogger.Warning(LocalizationSystem.GetName(), string.Format("System not ready. Do not use `LocalizationSystem.Get()` method while/before system starting. You can check it's state by `LocalizationSystem.IsReady()` call. Key: `{0}`.", key));
                }
            }

            if (string.IsNullOrEmpty(key) == true)
            {
                return(string.Empty);
            }

            return(string.Format(LocalizationSystem.NO_KEY_STRING, key));
        }
        public override System.Collections.Generic.IEnumerator <byte> Auth(string key, ServiceItem serviceItem)
        {
            net.SetName("stat");
            this.needReconnect = true;

            var hasError = false;

            this.Connect(key, (resultOk) => hasError = !resultOk);

            while (this.net.Connected() == false && hasError == false)
            {
                yield return(0);
            }

            var seconds = (System.DateTime.UtcNow - connectDT).TotalSeconds;

            if (hasError == false)
            {
                WindowSystemLogger.Warning(this, string.Format("Stat connected: {0} in {1} s", host, seconds));

                foreach (var identityMsg in this.userMap.Values)
                {
                    this.SendMsg(identityMsg);
                }
            }
            else
            {
                WindowSystemLogger.Warning(this, string.Format("Stat connecting error to host: {0} in {1} s", host, seconds));
            }

            yield return(0);
        }
예제 #3
0
        public static void CreatePool <T>(System.Type prefab, int capacity) where T : IPoolItem, new()
        {
            if (prefab == null)
            {
                return;
            }

            if (Pool.objectLookup.ContainsKey(prefab) == false)
            {
                Pool.objectLookup.Add(prefab, new List <IPoolItem>());
                Pool.objectLookupCounters.Add(prefab, 0);
                if (WindowSystemLogger.IsLogEnabled() == true)
                {
                    if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                    {
                        UnityEngine.Debug.LogWarning("ADD POOL[" + capacity + "]: " + prefab);
                    }
                }

                var preAllocated = new List <IPoolItem>();
                for (int i = 0; i < capacity; ++i)
                {
                    var item = prefab.Spawn <T>();
                    preAllocated.Add(item);
                }

                foreach (var item in preAllocated)
                {
                    item.Recycle();
                }
            }
        }
예제 #4
0
        public IEnumerator Init(System.Action onComplete = null)
        {
            if (this.logEnabled == true)
            {
                WindowSystemLogger.Log(this, "Initializing...");
            }

            if (FlowSystem.GetData().IsValidAuthKey(this.GetAuthPermission()) == false)
            {
                if (this.logEnabled == true)
                {
                    WindowSystemLogger.Warning(this, "Permission denied");
                }
                yield break;
            }

            var settings = this.settings;

            if (settings == null)
            {
                yield break;
            }

            this.OnInitialized();

            if (this.services != null)
            {
                var items = settings.GetItems();

                foreach (var service in this.services)
                {
                    for (int i = 0; i < items.Count; ++i)
                    {
                        var item = items [i];
                        if (item.serviceName == service.GetServiceName())
                        {
                            service.isActive = item.enabled;
                            if (service.isActive == true)
                            {
                                yield return(this.StartCoroutine(service.Auth(service.GetAuthKey(item))));

                                yield return(this.StartCoroutine(this.OnAfterAuth(service)));
                            }
                        }
                    }
                }
            }

            if (this.logEnabled == true)
            {
                WindowSystemLogger.Log(this, "Initialized");
            }

            if (onComplete != null)
            {
                onComplete.Invoke();
            }
        }
예제 #5
0
        public override IEnumerator GetData(string url, System.Action <LocalizationResult> onResult)
        {
                        #if !UNITY_EDITOR
            if (this.serviceManager.logEnabled == true)
            {
                        #endif

            WindowSystemLogger.Log(this, string.Format("Loading: {0}", url));

                        #if !UNITY_EDITOR
        }
                        #endif

            var www = new WWW(url + "&www_cache=" + Random.Range(0, 100000).ToString());
                        #if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                while (www.isDone == false)
                {
                    if (UnityEditor.EditorUtility.DisplayCancelableProgressBar("Wait a while", "...", www.progress) == true)
                    {
                        break;
                    }
                }

                UnityEditor.EditorUtility.ClearProgressBar();
            }
            else
            {
                        #endif

            while (www.isDone == false)
            {
                yield return(false);
            }

                        #if UNITY_EDITOR
        }
                        #endif

            onResult.Invoke(new LocalizationResult()
            {
                hasError = !string.IsNullOrEmpty(www.error), data = www.text
            });

            www.Dispose();
            www = null;
        }
        public override System.Collections.Generic.IEnumerator <byte> GetData(string url, System.Action <WindowSystemResourcesResult> onResult)
        {
                        #if !UNITY_EDITOR
            if (this.serviceManager.logEnabled == true)
            {
                        #endif

            WindowSystemLogger.Log(this, string.Format("Loading: {0}", url));

                        #if !UNITY_EDITOR
        }
                        #endif

            var www = new WWW(url);
                        #if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                while (www.isDone == false)
                {
                    if (UnityEditor.EditorUtility.DisplayCancelableProgressBar("Wait a while", "...", www.progress) == true)
                    {
                        break;
                    }
                }

                UnityEditor.EditorUtility.ClearProgressBar();
            }
            else
            {
                        #endif

            while (www.isDone == false)
            {
                yield return(0);
            }

                        #if UNITY_EDITOR
        }
                        #endif

            onResult.Invoke(new WindowSystemResourcesResult()
            {
                hasError = !string.IsNullOrEmpty(www.error), data = www.text
            });

            www.Dispose();
            www = null;
        }
        public static string Get(LocalizationKey key, params object[] parameters)
        {
            if (parameters.Length == key.parameters)
            {
                var value = LocalizationSystem.Get(key.key, LocalizationSystem.GetCurrentLanguage());
                if (key.formatWithDeclension == true)
                {
                    return(LocalizationSystem.FormatWithDeclension(value, returnWithNumber: !key.outputDeclensionWithoutNumber, parameters: parameters));
                }

                return(string.Format(value, parameters));
            }
            else
            {
                WindowSystemLogger.Warning(LocalizationSystem.GetName(), string.Format("Wrong parameters length in key `{0}`", key.key));
            }

            return(key.key);
        }
예제 #8
0
        public static string Get(LocalizationKey key, params object[] parameters)
        {
            if (parameters != null && parameters.Length == key.parameters)
            {
                var lang  = LocalizationSystem.GetCurrentLanguage();
                var value = LocalizationSystem.Get(key.key, lang);
                if (key.formatWithDeclension == true)
                {
                    return(LocalizationSystem.ArabicCheck(LocalizationSystem.FormatWithDeclension(value, returnWithNumber: !key.outputDeclensionWithoutNumber, parameters: parameters), lang));
                }

                return(LocalizationSystem.ArabicCheck(string.Format(value, parameters), lang));
            }
            else
            {
                if (LocalizationSystem.instance.logEnabled == true)
                {
                    WindowSystemLogger.Warning(LocalizationSystem.GetName(), string.Format("Wrong parameters length in key `{0}`", key.key));
                }
            }

            return(key.key);
        }
예제 #9
0
        public static void TryToSaveCSV(string data, bool loadCacheOnFail = true)
        {
            try {
                var parsed = CSVParser.ReadCSV(data);

                var defaultLanguage = parsed[0][0];
                LocalizationSystem.defaultLanguage = (UnityEngine.SystemLanguage)System.Enum.Parse(typeof(UnityEngine.SystemLanguage), defaultLanguage);

                var keysCount = 0;

                #region KEYS
                var keys = new List <string>();
                for (int i = 0; i < parsed.Count; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var row = parsed[i];
                    if (string.IsNullOrEmpty(row[0].Trim()) == true)
                    {
                        continue;
                    }

                    keys.Add(row[0].ToLower());

                    ++keysCount;
                }

                LocalizationSystem.keys = keys.ToArray();
                #endregion

                var langCount = 0;

                #region LANGUAGES
                var languages = new List <UnityEngine.SystemLanguage>();
                for (int i = 0; i < parsed[0].Length; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var col = parsed[0][i];
                    languages.Add((UnityEngine.SystemLanguage)System.Enum.Parse(typeof(UnityEngine.SystemLanguage), col));

                    if (col == LocalizationSystem.defaultLanguage.ToString())
                    {
                        LocalizationSystem.currentVersionNumber = int.Parse(parsed[1][i]);
                    }

                    ++langCount;
                }

                LocalizationSystem.languages = languages.ToArray();
                #endregion

                #region VALUES
                var values = new Dictionary <UnityEngine.SystemLanguage, string[]>();
                for (int j = 0; j < languages.Count; ++j)
                {
                    var lang = languages[j];

                    var output = new List <string>();
                    for (int i = 0; i < parsed.Count; ++i)
                    {
                        if (i == 0)
                        {
                            continue;
                        }

                        var col = parsed[i][j + 1];
                        if (string.IsNullOrEmpty(col.Trim()) == true)
                        {
                            continue;
                        }

                        output.Add(col);
                    }

                    values.Add(lang, output.ToArray());
                }

                LocalizationSystem.valuesByLanguage = values;
                #endregion

                var path = LocalizationSystem.GetCachePath();
                System.IO.File.WriteAllText(path, data);

                LocalizationSystem.currentLanguage = LocalizationSystem.defaultLanguage;

                if (LocalizationSystem.instance == null || LocalizationSystem.instance.logEnabled == true)
                {
                    WindowSystemLogger.Log(LocalizationSystem.GetName(), string.Format("Loaded version {3}. Cache saved to: {0}, Keys: {1}, Languages: {2}", path, keysCount, langCount, LocalizationSystem.GetCurrentVersionId()));
                }

                LocalizationSystem.isReady = true;
            } catch (System.Exception ex) {
                if (LocalizationSystem.instance == null || LocalizationSystem.instance.logEnabled == true)
                {
                    // Nothing to do: failed to parse
                    WindowSystemLogger.Error(LocalizationSystem.GetName(), string.Format("Parser error: {0}\n{1}", ex.Message, ex.StackTrace));
                }

                if (loadCacheOnFail == true)
                {
                    LocalizationSystem.TryToLoadCache();
                }
            }
        }
 protected virtual bool IsPlaying(ResourceBase resource, Texture texture)
 {
     WindowSystemLogger.Log(this.system, "`IsPlaying` method not supported on current platform");
     return(false);
 }
 protected virtual void OnStop(ResourceBase resource, Texture movie)
 {
     WindowSystemLogger.Log(this.system, "`Stop` method not supported on current platform");
 }
 protected virtual void OnPlay(ResourceBase resource, Texture movie, bool loop, System.Action onComplete)
 {
     WindowSystemLogger.Log(this.system, "`Play` method not supported on current platform");
 }
 protected virtual void OnRewind(ResourceBase resource, Texture movie, bool pause)
 {
     WindowSystemLogger.Log(this.system, "`Rewind` method not supported on current platform");
 }
예제 #14
0
        public static void TryToSaveCSV(string data, bool loadCacheOnFail = true)
        {
            try {
                var parsed = CSVParser.ReadCSV(data);

                if (GameDataSystem.currentVersion == default(Version))
                {
                    var defaultVersion = parsed[0][0];
                    GameDataSystem.currentVersion = new Version(defaultVersion);

                    if (GameDataSystem.instance == null || GameDataSystem.instance.logEnabled == true)
                    {
                        WindowSystemLogger.Warning(GameDataSystem.GetName(), string.Format("Default version is used: {0}", GameDataSystem.currentVersion));
                    }
                }
                GameDataSystem.defaultVersion = GameDataSystem.currentVersion;

                var keysCount = 0;

                #region KEYS
                var keys = new List <string>();
                for (int i = 0; i < parsed.Count; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var row = parsed[i];
                    var str = row[0].Trim();
                    if (string.IsNullOrEmpty(str) == true)
                    {
                        //str = string.Empty;
                        continue;
                    }

                    keys.Add(str.ToLower());

                    ++keysCount;
                }

                GameDataSystem.keys = keys.ToArray();
                #endregion

                var verCount = 0;

                #region VERSIONS
                var versions = new List <Version>();
                for (int i = 0; i < parsed[0].Length; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var col     = parsed[0][i];
                    var version = new Version(col);
                    versions.Add(version);

                    if (version == GameDataSystem.defaultVersion)
                    {
                        GameDataSystem.currentVersionNumber = int.Parse(parsed[1][i]);
                    }

                    ++verCount;
                }

                GameDataSystem.versions = versions.ToArray();
                #endregion

                #region VALUES
                var values = new Dictionary <VersionCrc, float[]>();
                for (int j = 0; j < versions.Count; ++j)
                {
                    var version = versions[j];
                    var crc     = new VersionCrc(version);

                    var output = new List <float>();
                    for (int i = 0; i < parsed.Count; ++i)
                    {
                        if (i == 0)
                        {
                            continue;
                        }

                        var value = parsed[i][j + 1];
                        if (string.IsNullOrEmpty(value.Trim()) == true)
                        {
                            //value = "0";
                            continue;
                        }

                        value = value.Replace(",", ".").Replace(" ", string.Empty);

                        var col = float.Parse(value);
                        output.Add(col);
                    }

                    if (values.ContainsKey(crc) == false)
                    {
                        values.Add(crc, output.ToArray());
                    }
                }

                GameDataSystem.valuesByVersion = values;
                #endregion

                var path = GameDataSystem.GetCachePath();
                                #if STORAGE_NOT_SUPPORTED
                PlayerPrefs.SetString(path, data);
                                #else
                System.IO.File.WriteAllText(path, data);
                                #endif

                                #if UNITY_EDITOR
                path = GameDataSystem.GetBuiltinCachePath();
                System.IO.File.WriteAllText(path, data);
                                #endif

                GameDataSystem.currentVersion = GameDataSystem.defaultVersion;

                if (GameDataSystem.instance == null || GameDataSystem.instance.logEnabled == true)
                {
                    WindowSystemLogger.Log(GameDataSystem.GetName(), string.Format("Loaded version {3}. Cache saved to: {0}, Keys: {1}, Versions: {2}, Version: {4}", path, keysCount, verCount, GameDataSystem.GetCurrentVersionId(), GameDataSystem.currentVersion));
                }

                GameDataSystem.isReady = true;
            } catch (System.Exception ex) {
                if (GameDataSystem.instance == null || GameDataSystem.instance.logEnabled == true)
                {
                    // Nothing to do: failed to parse
                    WindowSystemLogger.Error(GameDataSystem.GetName(), string.Format("Parser error: {0}\n{1}", ex.Message, ex.StackTrace));
                }

                if (loadCacheOnFail == true)
                {
                    GameDataSystem.TryToLoadCache();
                }
            }
        }
예제 #15
0
        public override System.Collections.Generic.IEnumerator <byte> GetData(LocalizationSettings settings, System.Action <LocalizationResult> onResult)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                onResult.Invoke(new LocalizationResult()
                {
                    hasError = true, errorText = "No Connection", data = string.Empty
                });
                yield break;
            }

                        #if !UNITY_EDITOR
            if (this.serviceManager.logEnabled == true)
            {
                        #endif

            WindowSystemLogger.Log(this, string.Format("Loading: {0} ({1})", settings.url, settings.eTag));

                        #if !UNITY_EDITOR
        }
                        #endif

            var eTag         = settings.eTag;
            var eTagPrefsKey = "LocalizationSystem.GoogleService.ETag";
            if (PlayerPrefs.HasKey(eTagPrefsKey) == true)
            {
                eTag = PlayerPrefs.GetString(eTagPrefsKey);
            }

#if !UNITY_SWITCH
            var www = UnityWebRequest.Get(settings.url);
            www.SetRequestHeader("ETag", eTag);
            www.SendWebRequest();
#else
            var form = new WWWForm();
            form.AddField("ETag", eTag);
            var www = new WWW(settings.url, form);
#endif
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                while (www.isDone == false)
                {
#if !UNITY_SWITCH
                    var progress = www.downloadProgress;
#else
                    var progress = www.progress;
#endif
                    if (UnityEditor.EditorUtility.DisplayCancelableProgressBar("Wait a while", "...", progress) == true)
                    {
                        break;
                    }
                }

                UnityEditor.EditorUtility.ClearProgressBar();

#if !UNITY_SWITCH
                eTag = www.GetResponseHeader("ETag");
#else
                www.responseHeaders.TryGetValue("ETag", out eTag);
#endif
                if (eTag != null)
                {
                    settings.eTag = eTag;
                    PlayerPrefs.SetString(eTagPrefsKey, eTag);
                }
            }
            else
            {
                        #endif

            while (www.isDone == false)
            {
                yield return(0);
            }

#if !UNITY_SWITCH
            eTag = www.GetResponseHeader("ETag");
#else
            www.responseHeaders.TryGetValue("ETag", out eTag);
#endif
            if (eTag != null)
            {
                PlayerPrefs.SetString(eTagPrefsKey, eTag);
            }

                        #if UNITY_EDITOR
        }
                        #endif
#if !UNITY_SWITCH
            var data = www.downloadHandler.text;
#else
            var data = www.text;
#endif

            onResult.Invoke(new LocalizationResult()
            {
                hasError = !string.IsNullOrEmpty(www.error), data = data, errorText = www.error
            });

            www.Dispose();
            www = null;
        }
예제 #16
0
        public System.Collections.IEnumerator Init(System.Action onComplete = null)
        {
            if (this.logEnabled == true)
            {
                WindowSystemLogger.Log(this, "Initializing...");
            }

            if (FlowSystem.GetData().IsValidAuthKey(this.GetAuthPermission()) == false)
            {
                WindowSystemLogger.Warning(this, "Permission denied");

                if (onComplete != null)
                {
                    onComplete.Invoke();
                }

                yield break;
            }

            var settings = this.settings;

            if (settings == null)
            {
                WindowSystemLogger.Warning(this, "Settings is null");

                if (onComplete != null)
                {
                    onComplete.Invoke();
                }

                yield break;
            }

            this.OnInitialized();

            if (this.services != null)
            {
                var items = settings.GetItems();

                foreach (var service in this.services)
                {
                    for (int i = 0; i < items.Count; ++i)
                    {
                        var item = items[i];
                        if (item.serviceName == service.GetServiceName())
                        {
                            var isSupported = service.IsSupported();
                            service.isActive = (item.enabled == true && isSupported == true);
                            if (service.isActive == true && isSupported == true)
                            {
                                //Debug.Log("ServiceManager::Auth (" + service.GetServiceName() + ")");
                                this.StartCoroutine(this.InitializeService(service, item));
                            }
                        }
                    }
                }
            }

            if (this.logEnabled == true)
            {
                WindowSystemLogger.Log(this, "Initialized");
            }

            if (onComplete != null)
            {
                onComplete.Invoke();
            }
        }
예제 #17
0
            public void Create(WindowBase window, WindowLayoutElement root, System.Action <WindowComponent> callback = null, bool async = false, System.Action <WindowObjectElement> onItem = null)
            {
                if (this.stopped == true)
                {
                    return;
                }

                this.window = window;
                this.root   = root;

                System.Action <WindowComponent> onLoaded = (component) => {
                    if (this.stopped == true)
                    {
                        return;
                    }

                    if (component == null && this.root == null)
                    {
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    if (component == null)
                    {
                        this.root.Setup(null, this);
                        if (callback != null)
                        {
                            callback.Invoke(null);
                        }
                        return;
                    }

                    //if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true) UnityEngine.Debug.Log("Unpack component: " + component.name);
                    var instance = component.Spawn(activeByDefault: false);
                    //instance.SetComponentState(WindowObjectState.NotInitialized);
                    instance.SetParent(root, setTransformAsSource: false, worldPositionStays: false);
                    instance.SetTransformAs();

                    if (this.componentParameters != null)
                    {
                        instance.Setup(this.componentParameters);
                    }

                    var rect = instance.transform as RectTransform;
                    if (rect != null)
                    {
                        rect.sizeDelta        = (component.transform as RectTransform).sizeDelta;
                        rect.anchoredPosition = (component.transform as RectTransform).anchoredPosition;
                    }

                    this.root.Setup(instance, this);
                    instance.Setup(window);

                    if (instance.autoRegisterInRoot == true && root.autoRegisterSubComponents == true)
                    {
                        root.RegisterSubComponent(instance);
                    }

                    instance.transform.SetSiblingIndex(this.sortingOrder);

                    this.instance = instance;
                    instance.DoLoad(async, onItem, () => {
                        if (this.stopped == true)
                        {
                            return;
                        }

                        //if (instance != null) instance.gameObject.SetActive(true);
                        if (callback != null)
                        {
                            callback.Invoke(this.instance as WindowComponent);
                        }
                    });
                };

                WindowComponent loadedComponent = null;

                if (this.componentResource.IsLoadable() == true)
                {
                    WindowSystemResources.LoadRefCounter <WindowComponent>(this, (component) => {
                        loadedComponent = component;
                        onLoaded.Invoke(loadedComponent);

                        WindowSystemResources.Unload(this, this.GetResource(), resetController: false);
                    }, () => {
                                                #if UNITY_EDITOR
                        if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                        {
                            UnityEngine.Debug.LogWarningFormat("[ Layout ] Resource request failed {0} [{1}].", UnityEditor.AssetDatabase.GetAssetPath(this.component.GetInstanceID()), window.name);
                        }
                                                #endif
                    }, async);
                    return;
                }
                else
                {
                    loadedComponent = this.componentNoResource;
                                        #if UNITY_EDITOR
                    if (WindowSystemLogger.IsLogEnabled() == true)
                    {
                        if (loadedComponent != null)
                        {
                            if (UnityEngine.UI.Windows.Constants.LOGS_ENABLED == true)
                            {
                                UnityEngine.Debug.LogWarningFormat("[ Layout ] Resource `{0}` [{1}] should be placed in `Resources` folder to be loaded/unloaded automaticaly. Window `{2}` requested this resource. This warning shown in editor only.", loadedComponent.name, UnityEditor.AssetDatabase.GetAssetPath(loadedComponent.GetInstanceID()), window.name);
                            }
                        }
                    }
                                        #endif
                }

                onLoaded.Invoke(loadedComponent);
            }
예제 #18
0
        public static void TryToSaveCSV(string data, bool loadCacheOnFail = true)
        {
            try {
                                #if UNITY_EDITOR
                var monoMemorySize = Profiler.GetMonoUsedSizeLong();
                                #endif

                var parsed = CSVParser.ReadCSV(data);

                var defaultLanguage = parsed[0][0];
                LocalizationSystem.defaultLanguage = (UnityEngine.SystemLanguage)System.Enum.Parse(typeof(UnityEngine.SystemLanguage), defaultLanguage);

                var keysCount = 0;

                #region KEYS
                var keys = new List <string>();
                for (int i = 0; i < parsed.Count; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var row = parsed[i];
                    if (string.IsNullOrEmpty(row[0].Trim()) == true)
                    {
                        continue;
                    }

                    keys.Add(row[0].ToLower());

                    ++keysCount;
                }

                LocalizationSystem.keys = keys.ToArray();
                #endregion

                var langCount = 0;

                #region LANGUAGES
                var languages = new List <UnityEngine.SystemLanguage>();
                for (int i = 0; i < parsed[0].Length; ++i)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    var col = parsed[0][i];
                    try {
                        var lng = (UnityEngine.SystemLanguage)System.Enum.Parse(typeof(UnityEngine.SystemLanguage), col);
                        languages.Add(lng);
                    } catch (Exception) {
                    }

                    if (col == LocalizationSystem.defaultLanguage.ToString())
                    {
                        LocalizationSystem.currentVersionNumber = int.Parse(parsed[1][i]);
                    }

                    ++langCount;
                }

                LocalizationSystem.languages = languages.ToArray();
                #endregion

                #region VALUES
                var values = new Dictionary <UnityEngine.SystemLanguage, string[]>();
                for (int j = 0; j < languages.Count; ++j)
                {
                    var lang = languages[j];

                    var output = new List <string>();
                    for (int i = 0; i < parsed.Count; ++i)
                    {
                        if (i == 0)
                        {
                            continue;
                        }

                        var col = parsed[i][j + 1];
                        if (string.IsNullOrEmpty(col.Trim()) == true)
                        {
                            continue;
                        }

                        output.Add(col);
                    }

                    values.Add(lang, output.ToArray());
                }

                LocalizationSystem.valuesByLanguage = values;
                #endregion

                foreach (var lang in languages)
                {
                    var val = LocalizationSystem.Get("Last", lang, forced: true);
                    if (val != "Last")
                    {
                        Debug.Log("Last Key: " + keys.Last());
                        Debug.Log("Value: " + val);
                        foreach (var key in keys)
                        {
                            Debug.Log(key + " :: " + LocalizationSystem.Get(key, lang, forced: true));
                        }

                        throw new Exception(string.Format("Language `{0}` has errors", lang));
                    }
                }

                var path = LocalizationSystem.GetCachePath();
                                #if STORAGE_NOT_SUPPORTED
                PlayerPrefs.SetString(path, data);
                                #else
                System.IO.File.WriteAllText(path, data);
                                #endif

                                #if UNITY_EDITOR
                path = LocalizationSystem.GetBuiltinCachePath();
                System.IO.File.WriteAllText(path, data);
                                #endif

                LocalizationSystem.currentLanguage = LocalizationSystem.defaultLanguage;

                if (LocalizationSystem.instance == null || LocalizationSystem.instance.logEnabled == true)
                {
                    WindowSystemLogger.Log(LocalizationSystem.GetName(), string.Format("Loaded version {3}. Cache saved to: {0}, Keys: {1}, Languages: {2}", path, keysCount, langCount, LocalizationSystem.GetCurrentVersionId()));
                }

                LocalizationSystem.isReady = true;

                                #if UNITY_EDITOR
                var monoMemorySizeAfter = Profiler.GetMonoUsedSizeLong();
                var deltaMemory         = monoMemorySizeAfter - monoMemorySize;
                WindowSystemLogger.Warning(LocalizationSystem.GetName(), string.Format("Allocated: {0} bytes ({1}MB)", deltaMemory, (deltaMemory / 1024f / 1024f)));
                                #endif
            } catch (System.Exception ex) {
                Debug.LogError("LocalizationSystem parse failed");

                if (LocalizationSystem.instance == null || LocalizationSystem.instance.logEnabled == true)
                {
                    // Nothing to do: failed to parse
                    WindowSystemLogger.Error(LocalizationSystem.GetName(), string.Format("Parser error: {0}\n{1}", ex.Message, ex.StackTrace));
                }

                if (loadCacheOnFail == true)
                {
                    LocalizationSystem.TryToLoadCache();
                }
            }
        }
예제 #19
0
        public override System.Collections.Generic.IEnumerator <byte> GetData(LocalizationSettings settings, System.Action <LocalizationResult> onResult)
        {
                        #if !UNITY_EDITOR
            if (this.serviceManager.logEnabled == true)
            {
                        #endif

            WindowSystemLogger.Log(this, string.Format("Loading: {0} ({1})", settings.url, settings.eTag));

                        #if !UNITY_EDITOR
        }
                        #endif

            var eTag         = settings.eTag;
            var eTagPrefsKey = "LocalizationSystem.GoogleService.ETag";
            if (PlayerPrefs.HasKey(eTagPrefsKey) == true)
            {
                eTag = PlayerPrefs.GetString(eTagPrefsKey);
            }

            var www = UnityWebRequest.Get(settings.url);
            www.SetRequestHeader("ETag", eTag);
            www.Send();
                        #if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                while (www.isDone == false)
                {
                    if (UnityEditor.EditorUtility.DisplayCancelableProgressBar("Wait a while", "...", www.downloadProgress) == true)
                    {
                        break;
                    }
                }

                UnityEditor.EditorUtility.ClearProgressBar();

                eTag = www.GetResponseHeader("ETag");
                if (eTag != null)
                {
                    settings.eTag = eTag;
                    PlayerPrefs.SetString(eTagPrefsKey, eTag);
                }
            }
            else
            {
                        #endif

            while (www.isDone == false)
            {
                yield return(0);
            }

            eTag = www.GetResponseHeader("ETag");
            if (eTag != null)
            {
                PlayerPrefs.SetString(eTagPrefsKey, eTag);
            }

                        #if UNITY_EDITOR
        }
                        #endif

            onResult.Invoke(new LocalizationResult()
            {
                hasError = !string.IsNullOrEmpty(www.error), data = www.downloadHandler.text, errorText = www.error
            });

            www.Dispose();
            www = null;
        }