示例#1
0
        private static IEnumerator downloadAll(List <GSPluginSettings.Sheet> sheets, string settingDir)
        {
            float progress = 0f;
            int   i        = 0;

            foreach (var ss in sheets)
            {
                EditorCoroutineRunner.UpdateUILabel("Downloading " + ss.targetPath);
                yield return(EditorCoroutineRunner.StartCoroutine(Download(ss, settingDir)));

                progress = (float)(++i) / sheets.Count;
                EditorCoroutineRunner.UpdateUIProgressBar(progress);
            }

            AssetDatabase.Refresh();
        }
示例#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());
            }
        }