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();
            }
        }
Example #2
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;
        }
Example #4
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();
                }
            }
        }
 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");
 }
Example #9
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();
                }
            }
        }
Example #10
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();
                }
            }
        }
Example #11
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();
            }
        }
Example #12
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;
        }
Example #13
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;
        }