예제 #1
0
        static void ImportCsv(
            string csvPath, string dataName, string dataPath,
            Func <string, Type> dataTypeGetter
            )
        {
            AltoLog.Info($"Master data csv update detected : { csvPath }");

            string destDataPath = $"{ dataPath }{ dataName }.asset";
            var    data         = AssetDatabase.LoadMainAssetAtPath(destDataPath);

            if (data == null)
            {
                AltoLog.Error($"Master data ScriptableObject not exist : { destDataPath }");
                return;
            }

            var type = dataTypeGetter(dataName);

            if (type == null)
            {
                AltoLog.Error($"Type reflection failed : { dataName }");
                return;
            }
            MethodInfo method = type.GetMethod("Import");

            if (method == null)
            {
                AltoLog.Error($"Method reflection failed");
                return;
            }

            var csvLines = LoadCsvFile(csvPath);

            method.Invoke(data, new object[] { csvLines });

            EditorUtility.SetDirty(data);
            AssetDatabase.SaveAssets();
            AltoLog.Success($"Master data import succeeded : { dataName }");
        }
        //----------------------------------------------------------------------
        // public
        //----------------------------------------------------------------------

        public void Generate()
        {
            if (!Directory.Exists(outputDirPath))
            {
                Directory.CreateDirectory(outputDirPath);
            }

            string outPath = $"{ outputDirPath }/{ outputFileName }";

            AltoLog.FW($"Generate Code : { outPath }");
            using (var fileStream = File.Open(outPath, FileMode.Create, FileAccess.Write))
            {
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    var stringBuilder = new StringBuilder();
                    WriteOuter(stringBuilder);
                    streamWriter.Write(stringBuilder.ToString());
                }
            }

            AssetDatabase.Refresh();
            AltoLog.Success("Generate Code Completed.");
        }