public static void GeneratePathScript() { AssetDatabase.SaveAssets(); IOExtension.CreateDirIfNotExists(EditorPathManager.DefaultPathScriptGenerateForder); string[] fullPathFileNames = Directory.GetFiles(EditorPathManager.DefaultPathConfigGenerateForder, "*PathDefine.asset", SearchOption.AllDirectories); foreach (string fullPathFileName in fullPathFileNames) { Debug.Log(fullPathFileName); if (!fullPathFileName.EndsWith(".meta")) { Debug.Log("gen: " + fullPathFileName); PathConfig config = AssetDatabase.LoadAssetAtPath <PathConfig> (fullPathFileName); PTNamespaceDefine nameSpace = new PTNamespaceDefine(); nameSpace.Name = string.IsNullOrEmpty(config.NameSpace) ? "QFramework" : config.NameSpace; nameSpace.FileName = config.name + ".cs"; nameSpace.GenerateDir = string.IsNullOrEmpty(config.ScriptGeneratePath) ? EditorPathManager.DefaultPathScriptGenerateForder : IOExtension.CreateDirIfNotExists("Assets/" + config.ScriptGeneratePath); var classDefine = new PTClassDefine(); classDefine.Comment = config.Description; classDefine.Name = config.name; nameSpace.Classes.Add(classDefine); Debug.Log(nameSpace.GenerateDir); foreach (var pathItem in config.List) { if (!string.IsNullOrEmpty(pathItem.Name)) { var variable = new PTVariable(PTAccessLimit.Private, PTCompileType.Const, PTTypeDefine.String, "m_" + pathItem.Name, pathItem.Path); classDefine.Variables.Add(variable); var property = new PTProperty(PTAccessLimit.Public, PTCompileType.Static, PTTypeDefine.String, pathItem.Name, pathItem.PropertyGetCode, pathItem.Description); classDefine.Properties.Add(property); } } PTCodeGenerator.Generate(nameSpace); EditorUtility.SetDirty(config); Resources.UnloadAsset(config); } } AssetDatabase.SaveAssets(); }
public static void GenPathAssetFile() { AssetDatabase.SaveAssets(); PathConfig data = null; IOExtension.CreateDirIfNotExists(EditorPathManager.DefaultPathConfigGenerateForder); string newConfigPath = IOEditorPathConfig.IOGeneratorPath + "/NewPathConfig.asset"; data = AssetDatabase.LoadAssetAtPath <PathConfig>(newConfigPath); if (data == null) { data = ScriptableObject.CreateInstance <PathConfig>(); AssetDatabase.CreateAsset(data, newConfigPath); } EditorUtility.SetDirty(data); AssetDatabase.SaveAssets(); }
public static void Generate(PTNamespaceDefine nameSpace) { IOExtension.CreateDirIfNotExists(nameSpace.GenerateDir); var compileUnit = new CodeCompileUnit(); var codeNameSpace = new CodeNamespace(nameSpace.Name); compileUnit.Namespaces.Add(codeNameSpace); foreach (var classDefine in nameSpace.Classes) { var codeType = new CodeTypeDeclaration(classDefine.Name); codeNameSpace.Types.Add(codeType); AddDocumentComment(codeType.Comments, classDefine.Comment); foreach (var variable in classDefine.Variables) { AddVariable(codeType, variable); } foreach (var property in classDefine.Properties) { AddProperty(codeType, property); } } var provider = new CSharpCodeProvider(); var options = new CodeGeneratorOptions(); options.BlankLinesBetweenMembers = false; // options.BracingStyle = "Block"; options.BracingStyle = "C"; StreamWriter writer = new StreamWriter(File.Open(Path.GetFullPath(nameSpace.GenerateDir + Path.DirectorySeparatorChar + nameSpace.FileName), FileMode.Create)); provider.GenerateCodeFromCompileUnit(compileUnit, writer, options); writer.Close(); AssetDatabase.Refresh(); }