コード例 #1
0
        public static void CreateEnum(string enumName, string nameSpace, IEnumerable <string> entries, string filepath = "", bool allowOverride = true)
        {
            var entriesList = entries.ToList();

            if (entriesList.Count == 0)
            {
                return;
            }
            string path = FileStrings.ASSETS_GENERATED_ENUM +
                          (filepath == ""? FileStrings.S : FileStrings.S + filepath + FileStrings.S) +
                          enumName +
                          FileStrings.SCRIPTS_FILE_EXTENSION;

            EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS, FileStrings.GENERATED);
            EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS_GENERATED, FileStrings.ENUM);

            if (filepath != "")
            {
                EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS_GENERATED_ENUM, filepath);
            }

            if (!allowOverride)
            {
                if (File.Exists(path))
                {
                    return;
                }
            }
            using (var outfile = new StreamWriter(path))
            {
                outfile.WriteLine("#if {0}_DEFINE", enumName);
                outfile.WriteLine("//");
                outfile.WriteLine("//It is not recommende to edit this file, as there are no checks on if the user has changed it.");
                outfile.WriteLine("//THIS FILE IS OVER WITTEN REGUADLESS OF CHANGES, EDIT THIS IN THE EDITOR IT WAS GENERATED FROM");
                outfile.WriteLine("//");
                outfile.WriteLine("namespace Generated.{0}{1}", nameSpace, " {");
                outfile.WriteLine("\t/// <summary>");
                outfile.WriteLine("\t///This is an auto generated enum, created in the Unity editor, please don't edit.");
                outfile.WriteLine("\t///It will be overwritten on next change in the editor.");
                outfile.WriteLine("\t///</summary>");

                outfile.WriteLine("\tpublic enum " + enumName + " {");

                foreach (string str in entriesList)
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        outfile.WriteLine("\t\t{0},", str);
                    }
                }

                outfile.WriteLine("\t}");
                outfile.WriteLine("}");
                outfile.WriteLine("#endif");
            }             //File written

            DefineManager.AddDefine(enumName + "_DEFINE");

            AssetDatabase.Refresh();
        }
コード例 #2
0
        public static void CreateStaticClass(string className, IEnumerable <StaticDataType> entries, string filepath = "", bool allowOverride = true)
        {
            var entriesList = entries.ToList();
            var path        = FileStrings.ASSETS_GENERATED_STATICCLASS +
                              (filepath == ""? FileStrings.S : FileStrings.S + filepath + FileStrings.S) +
                              className +
                              FileStrings.SCRIPTS_FILE_EXTENSION;

            EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS, FileStrings.GENERATED);
            EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS_GENERATED, FileStrings.STATICCLASS);

            if (filepath != "")
            {
                EditorHelpers.CreateAndCheckFolder(FileStrings.ASSETS_GENERATED_STATICCLASS, filepath);
            }

            if (!allowOverride)
            {
                if (File.Exists(path))
                {
                    return;
                }
            }
            using (var outfile = new StreamWriter(path))
            {
                outfile.WriteLine("//");
                outfile.WriteLine("//It is not recommended to edit this file, as there are no checks on if the user has changed it.");
                outfile.WriteLine("//THIS FILE IS OVER WITTEN REGUADLESS OF CHANGES, EDIT THIS IN THE EDITOR IT WAS GENERATED FROM");
                outfile.WriteLine("//");
                outfile.WriteLine("namespace Generated{");
                outfile.WriteLine("\t/// <summary>");
                outfile.WriteLine("\t///This is an auto generated static class, created in the Unity editor, please don't edit.");
                outfile.WriteLine("\t///It will be overwritten on next change in the editor.");
                outfile.WriteLine("\t///</summary>");
                outfile.WriteLine("\tpublic static class " + className + " {");

                foreach (var str in entriesList)
                {
                    if (!String.IsNullOrEmpty(str.Name))
                    {
                        outfile.WriteLine("\t\t public static {0} {1};", TypeToString[str.Type], str);
                    }
                }

                outfile.WriteLine("\t}");
                outfile.WriteLine("}");
            }             //File written

            DefineManager.AddDefine(className + "_DEFINE");

            AssetDatabase.Refresh();
        }