private static void FetchUrl(string url, Action <string> onComplete)
        {
            using (var www = new WWW(url))
            {
                var startTime  = Time.realtimeSinceStartup;
                var timeOutSec = TimeOutSec;
                while (!www.isDone)
                {
                    if (Time.realtimeSinceStartup - startTime > timeOutSec)
                    {
                        LocalTextLogger.Error("GoogleSpreadSheetImporter : Timeout. Confirm spreadsheet setting.");
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(www.error))
                {
                    LocalTextLogger.Error("GoogleSpreadSheetImporter : Api Network Error.");
                    return;
                }

                var csv = www.text;
                if (string.IsNullOrEmpty(csv))
                {
                    LocalTextLogger.Error("GoogleSpreadSheetImporter : Response body is Empty.");
                    return;
                }

                onComplete(csv);
            }
        }
        public static void SyncGoogleSpreadSheetApi(Settings settings)
        {
            if (string.IsNullOrEmpty(settings.GoogleSpreadSheetUrl))
            {
                LocalTextLogger.Error("GoogleSpreadSheetImporter : Settings GoogleSpreadsheetUrl is Empty.");
                return;
            }

            FetchUrl(settings.GoogleSpreadSheetUrl, csv =>
            {
                AssetCreator.CreateAll(settings, csv);
            });
        }
Example #3
0
        public string Text(string key)
        {
            var text = "";

            try
            {
                text = currentLanguageTextSet[key];
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                LocalTextLogger.Error("No value found for key {0}. Confirm TextSet Inspector.", key);
            }
            return(text);
        }
Example #4
0
        public static void CreateAll(Settings settings, string csv)
        {
            OnPreProcessImport += ReplaceNewline;

            CreteKeyDefinitionFile(settings, csv);
            try
            {
                CreateTextSet(settings, csv);
            }
#pragma warning disable 168
            catch (IndexOutOfRangeException e)
#pragma warning restore 168
            {
                LocalTextLogger.Error("Parse Fail.The number of columns may be incorrect");
            }

            AssetDatabase.Refresh();
        }
Example #5
0
        public static void MenuItem()
        {
            LocalTextLogger.Info(Constant.MenuName.AssetMenuName);

            var assetRootPath = AssetDataBaseHelper.FirstAssetPathOrDefault("t:Object", "LocalizedText");

            if (string.IsNullOrEmpty(assetRootPath))
            {
                LocalTextLogger.Error("LocalizedText directory not found. " +
                                      "LocalizedText assets must be placed under LocalizedText directory.");
                return;
            }

            LocalTextLogger.Verbose("CreateSingletonSettingsMenu assetRootPath {0}", assetRootPath);

            var singletonSettings = AssetDataBaseHelper.FindScriptableObject <SingletonSettings>("LocalizedTextSettings");

            if (singletonSettings)
            {
                LocalTextLogger.Error("LocalizedTextSettings singleton settings already exist.");
                EditorGUIUtility.PingObject(singletonSettings);
                return;
            }

            singletonSettings                  = ScriptableObject.CreateInstance <SingletonSettings>();
            singletonSettings.name             = "LocalizedTextSettings";
            singletonSettings.TextSetAssetName = "TextSet";

            var resourcesDirectory = Path.Combine(assetRootPath, "Resources");

            if (!Directory.Exists(resourcesDirectory))
            {
                LocalTextLogger.Verbose("Create directory :{0}", resourcesDirectory);
                AssetDatabase.CreateFolder(assetRootPath, "Resources");
            }
            singletonSettings.TextSetGenerateDirectory = resourcesDirectory;

            singletonSettings.KeyDefinitionClassName = "TextSetKey";

            const string scripts   = "Scripts";
            const string generated = "Generated";

            var generatedDirectory = new[] { assetRootPath, scripts, generated }.Aggregate(Path.Combine);

            if (!Directory.Exists(generatedDirectory))
            {
                LocalTextLogger.Verbose("Create directory : {0}", generatedDirectory);
                AssetDatabase.CreateFolder(Path.Combine(assetRootPath, scripts), generated);
            }
            singletonSettings.KeyClassGenerateDirectory = generatedDirectory;

            singletonSettings.SelectedDataSource = Settings.DataSource.GoogleSpreadSheetAsWeb;
            singletonSettings.SelectedDataFormat = Settings.DataFormat.Tsv;

            const string editor   = "Editor";
            const string settings = "Settings";

            var settingsDirectory = new[] { assetRootPath, editor, settings }.Aggregate(Path.Combine);

            if (!Directory.Exists(settingsDirectory))
            {
                LocalTextLogger.Verbose("Create directory :{0}", settingsDirectory);
                AssetDatabase.CreateFolder(Path.Combine(assetRootPath, editor), settings);
            }

            var settingsPath = Path.Combine(settingsDirectory, "LocalizedTextSettings.asset");

            AssetDatabase.CreateAsset(singletonSettings, settingsPath);

            EditorUtility.SetDirty(singletonSettings);
            AssetDatabase.SaveAssets();
        }