Пример #1
0
        public static IEnumerator ExecuteDownload(ConvertSetting s)
        {
            GSPluginSettings.Sheet sheet = new GSPluginSettings.Sheet();
            sheet.sheetId = s.sheetID;
            sheet.gid     = s.gid;

            GlobalCCSettings gSettings = CCLogic.GetGlobalSettings();

            string csvPath = s.GetCsvPath(gSettings);

            if (string.IsNullOrWhiteSpace(csvPath))
            {
                Debug.LogError("unexpected downloadPath: " + csvPath);
                downloadSuccess = false;
                yield break;
            }

            string absolutePath = CCLogic.GetFilePathRelativesToAssets(s.GetDirectoryPath(), csvPath);

            // 先頭の Assets を削除する
            if (absolutePath.StartsWith("Assets" + Path.DirectorySeparatorChar))
            {
                sheet.targetPath = absolutePath.Substring(6);
            }
            else
            {
                Debug.LogError("unexpected downloadPath: " + absolutePath);
                downloadSuccess = false;
                yield break;
            }

            sheet.isCsv   = true;
            sheet.verbose = false;

            string title = "Google Spreadsheet Loader";

            yield return(EditorCoroutineRunner.StartCoroutineWithUI(GSEditorWindow.Download(sheet, s.GetDirectoryPath()), title, true));

            // 成功判定を行う.
            if (GSEditorWindow.previousDownloadSuccess)
            {
                downloadSuccess = true;
            }

            yield break;
        }
Пример #2
0
        public static IEnumerator Download(GSPluginSettings.Sheet ss, string settingDir)
        {
            previousDownloadSuccess = false;
            string sheetId = ss.sheetId;
            string gid     = ss.gid;

            string label = "Downloading " + ss.targetPath;

            EditorCoroutineRunner.UpdateUILabel(label);

            var gsLoader       = new GSLoader();
            var globalSettings = CCLogic.GetGlobalSettings();

            string apiKey = globalSettings.apiKey;
            bool   useV4  = globalSettings.useV4;

            yield return(EditorCoroutineRunner.StartCoroutine(gsLoader.LoadGS(sheetId, gid, apiKey, useV4)));

            if (!gsLoader.isSuccess)
            {
                Debug.Log("Failed to load spreadsheet data.");
                yield break;
            }

            CsvData csvData = gsLoader.loadedCsvData;
            string  targetPathRelativeToAssets = ss.GetFilePathRelativesToAssets(settingDir);

            if (csvData != null)
            {
                if (ss.isCsv)
                {
                    string targetDir = Path.GetDirectoryName(targetPathRelativeToAssets);

                    if (!Directory.Exists(targetDir))
                    {
                        try
                        {
                            Directory.CreateDirectory(targetDir);
                            Debug.Log("指定のフォルダが存在しないため、作成しました: " + targetDir);
                        }
                        catch (Exception e)
                        {
                            Debug.LogError("指定のフォルダの作成に失敗: " + e.Message);
                        }
//                            Debug.LogError("指定のフォルダは存在しません: " + targetDir);
//                        return;
                    }

                    using (var s = new StreamWriter(targetPathRelativeToAssets)) {
                        s.Write(csvData.ToString());
                    }
                }
                else
                {
                    // AssetDatabase.CreateAsset(csvData, targetPathRelativeToAssets);
                    Debug.LogError("CsvData の書き出しには未対応になりました");
                }

                if (ss.verbose)
                {
                    Debug.Log("Write " + ss.targetPath);
                }

                previousDownloadSuccess = true;
                AssetDatabase.Refresh();
            }
            else
            {
                Debug.LogError("Fails for " + ss.ToString());
            }
        }
Пример #3
0
        public static void DownloadOne(GSPluginSettings.Sheet sheet, string settingPath)
        {
            string title = "Google Spreadsheet Loader";

            EditorCoroutineRunner.StartCoroutineWithUI(Download(sheet, settingPath), title, true);
        }