コード例 #1
0
        public void SetSettings(ConvertSetting setting)
        {
            this.settings  = setting;
            this.createNew = false;

            className    = setting.className;
            sheetId      = setting.sheetID;
            gid          = setting.gid;
            key          = setting.key;
            isDictionary = setting.isDictionary;
        }
コード例 #2
0
        public void SetNewSettings(ConvertSetting setting, string newAssetDir)
        {
            this.settings    = setting;
            this.createNew   = true;
            this.newAssetDir = newAssetDir;

            className    = setting.className;
            sheetId      = setting.sheetID;
            gid          = setting.gid;
            key          = setting.key;
            isDictionary = setting.isDictionary;
        }
コード例 #3
0
        public static string GenerateTableClass(ConvertSetting setting, string tableClassName, Field[] keys)
        {
            string className = setting.className;

            string code = "";

            if (setting.isDictionary)
            {
                code = LoadDictTableTemplate();

                if (keys == null)
                {
                    throw new Exception("Dictionary Table にはキーが必要です");
                }

                if (keys.Length != 1)
                {
                    throw new Exception("Dictionary Table はキーを1つだけ指定してください");
                }

                code = code.Replace("%KeyType%", keys[0].typeName);
                code = code.Replace("%KeyName%", keys[0].fieldName);
            }
            // キーが有効な場合はキーから検索できるようにする
            else if (keys != null && keys.All((arg) => arg.isValid))
            {
                code = LoadListTableTemplate();

                string argStr  = "";
                string condStr = "";

                for (int i = 0; i < keys.Length; i++)
                {
                    argStr  += string.Format("{0} {1}, ", keys[i].typeName, keys[i].fieldName);
                    condStr += string.Format("o.{0} == {0} && ", keys[i].fieldName);
                }

                argStr  = argStr.Substring(0, argStr.Length - 2);
                condStr = condStr.Substring(0, condStr.Length - 4);
                code    = code.Replace("%FindArguments%", argStr);
                code    = code.Replace("%FindPredicate%", condStr);
            }
            // キーなしリストテーブル
            else
            {
                code = LoadNoKeyListTableTemplate();
            }

            code = code.Replace("%TableClassName%", tableClassName);
            code = code.Replace("%ClassName%", className);

            return(code);
        }
コード例 #4
0
        public static IEnumerator ExecuteImport(ConvertSetting s)
        {
            downloadSuccess = false;
            yield return(EditorCoroutineRunner.StartCoroutine(ExecuteDownload(s)));

            if (!downloadSuccess)
            {
                yield break;
            }

            CreateAssetsJob createAssetsJob = new CreateAssetsJob(s);

            // Generate Code if type script is not found.
            Type assetType;

            if (s.isEnum || !CsvConvert.TryGetTypeWithError(s.className, out assetType,
                                                            s.checkFullyQualifiedName, dialog: false))
            {
                GlobalCCSettings gSettings = CCLogic.GetGlobalSettings();
                GenerateOneCode(s, gSettings);

                if (!s.isEnum)
                {
                    EditorUtility.DisplayDialog(
                        "Code Generated",
                        "Please reimport for creating assets after compiling",
                        "ok"
                        );
                }
            }
            // Create Assets
            else
            {
                createAssetsJob.Execute();
            }

            // AfterImport 処理
            for (int i = 0; i < s.executeAfterImport.Count; i++)
            {
                var afterSettings = s.executeAfterImport[i];

                if (afterSettings != null)
                {
                    yield return(EditorCoroutineRunner.StartCoroutine(ExecuteImport(afterSettings)));
                }
            }
        }
コード例 #5
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;
        }
コード例 #6
0
        public static void GenerateOneCode(ConvertSetting s, GlobalCCSettings gSettings)
        {
            show_progress(s.className, 0, 0, 1);

            try
            {
                CsvConvert.GenerateCode(s, gSettings);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            show_progress(s.className, 1, 1, 1);

            EditorUtility.ClearProgressBar();
        }
コード例 #7
0
ファイル: CCLogic.cs プロジェクト: akagik/KoheiUtils
        /// <summary>
        /// メインの出力アセットへのパスを指す.
        /// </summary>
        public static string GetMainOutputPath(ConvertSetting s)
        {
            string settingsPath = s.GetDirectoryPath();
            string dst          = "";

            if (s.isEnum)
            {
                dst = CCLogic.GetFilePathRelativesToAssets(settingsPath, s.codeDestination);
                return(Path.Combine(dst, s.className + ".cs"));
            }

            if (s.tableGenerate)
            {
                dst = CCLogic.GetFilePathRelativesToAssets(settingsPath, s.destination);
                return(Path.Combine(dst, s.tableAssetName + ".asset"));
            }

            return(dst);
        }
コード例 #8
0
        public static int[] FindKeyIndexes(ConvertSetting setting, Field[] fields)
        {
            List <int> indexes = new List <int>();

            string[] keys = setting.keys;
            // Debug.Log(keys.ToString<string>());

            for (int j = 0; j < keys.Length; j++)
            {
                for (int i = 0; i < fields.Length; i++)
                {
                    if (fields[i].fieldName == keys[j])
                    {
                        indexes.Add(i);
                    }
                }
            }

            return(indexes.ToArray());
        }
コード例 #9
0
ファイル: CsvConvert.cs プロジェクト: akagik/KoheiUtils
        public static void CreateAssets(ConvertSetting s, GlobalCCSettings gSettings)
        {
            string    settingPath = s.GetDirectoryPath();
            string    csvPath     = CCLogic.GetFilePathRelativesToAssets(settingPath, s.GetCsvPath(gSettings));
            TextAsset textAsset   = AssetDatabase.LoadAssetAtPath <TextAsset>(csvPath);

            if (textAsset == null)
            {
                Debug.LogError("Not found : " + csvPath);
                return;
            }

            if (s.isEnum)
            {
                return;
            }

            // csv ファイルから読み込み
            CsvData csv      = CsvLogic.GetValidCsvData(textAsset.text, gSettings);
            CsvData contents = csv.Slice(gSettings.rowIndexOfContentStart);

            Field[] fields = CsvLogic.GetFieldsFromHeader(csv, gSettings);

            // アセットを生成する.
            AssetsGenerator assetsGenerator = new AssetsGenerator(s, fields, contents);

            // カスタムアセットタイプを設定する
            // これはプロジェクト固有のアセットをテーブルでセット出来るようにする.
            {
                Type[] customAssetTypes = new Type[gSettings.customAssetTypes.Length];
                for (int i = 0; i < customAssetTypes.Length; i++)
                {
                    if (TryGetTypeWithError(gSettings.customAssetTypes[i], out var type, s.checkFullyQualifiedName))
                    {
                        customAssetTypes[i] = type;
                    }
コード例 #10
0
ファイル: CsvConvert.cs プロジェクト: akagik/KoheiUtils
        public static void GenerateCode(ConvertSetting s, GlobalCCSettings gSettings)
        {
            string    settingPath = s.GetDirectoryPath();
            string    csvPath     = CCLogic.GetFilePathRelativesToAssets(settingPath, s.GetCsvPath(gSettings));
            TextAsset textAsset   = AssetDatabase.LoadAssetAtPath <TextAsset>(csvPath);

            if (textAsset == null)
            {
                Debug.LogError("Not found : " + csvPath);
                return;
            }

            string directoryPath = CCLogic.GetFullPath(settingPath, s.codeDestination);

            if (!Directory.Exists(directoryPath))
            {
                Debug.LogError("Not found directory: " + directoryPath);
                return;
            }

            CsvData csv = CsvLogic.GetValidCsvData(textAsset.text, gSettings);

            if (s.isEnum)
            {
                CsvData headers  = csv.Slice(gSettings.rowIndexOfName, gSettings.rowIndexOfName + 1);
                CsvData contents = csv.Slice(gSettings.rowIndexOfEnumContentStart);
                string  code     = EnumGenerator.Generate(s.className, headers, contents, s.verbose);

                string filePath = Path.Combine(directoryPath, s.className + ".cs");
                using (StreamWriter writer = File.CreateText(filePath))
                {
                    writer.WriteLine(code);
                }

                Debug.LogFormat("Create \"{0}\"", filePath);
            }
            else
            {
                Field[] fields = CsvLogic.GetFieldsFromHeader(csv, gSettings);

                if (s.classGenerate)
                {
                    string code = ClassGenerator.GenerateClass(s.className, fields, s.IsPureClass);

                    string filePath = Path.Combine(directoryPath, s.className + ".cs");
                    using (StreamWriter writer = File.CreateText(filePath))
                    {
                        writer.WriteLine(code);
                    }

                    Debug.LogFormat("Create \"{0}\"", filePath);
                }

                if (s.tableClassGenerate)
                {
                    int[] keyIndexes = ClassGenerator.FindKeyIndexes(s, fields);

                    string[] keys = s.keys;
                    Field[]  key  = null;
                    if (keyIndexes.Length > 0)
                    {
                        List <Field> keyFieldList = new List <Field>();

                        for (int i = 0; i < keyIndexes.Length; i++)
                        {
                            keyFieldList.Add(fields[keyIndexes[i]]);
                        }

                        key = keyFieldList.ToArray();
                    }

                    string code = ClassGenerator.GenerateTableClass(s, s.TableClassName, key);

                    string filePath = Path.Combine(directoryPath, s.TableClassName + ".cs");
                    using (StreamWriter writer = File.CreateText(filePath))
                    {
                        writer.WriteLine(code);
                    }

                    Debug.LogFormat("Create \"{0}\"", filePath);
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
コード例 #11
0
ファイル: CreateAssetsJob.cs プロジェクト: akagik/KoheiUtils
 public CreateAssetsJob(ConvertSetting settings)
 {
     this.settings = settings;
 }
コード例 #12
0
ファイル: AssetsGenerator.cs プロジェクト: akagik/KoheiUtils
 public AssetsGenerator(ConvertSetting _setting, Field[] _fields, CsvData _content)
 {
     setting = _setting;
     fields  = _fields;
     content = _content;
 }