/// <summary> /// 添加变量 /// </summary> static void AddVariable(CodeTypeDeclaration codeType, QVariable variable) { CodeMemberField nameField = new CodeMemberField(); AddDocumentComment(nameField.Comments, variable.Comment); switch (variable.AccessLimit) { case QAccessLimit.Public: nameField.Attributes = MemberAttributes.Public; break; case QAccessLimit.Private: nameField.Attributes = MemberAttributes.Private; break; } switch (variable.CompileType) { case QCompileType.Const: nameField.Attributes |= MemberAttributes.Const; break; case QCompileType.Static: nameField.Attributes |= MemberAttributes.Static; break; } nameField.Name = variable.Name; nameField.Type = variable.Type; nameField.InitExpression = new CodePrimitiveExpression(variable.Value); codeType.Members.Add(nameField); }
public static void GeneratePathScript() { AssetDatabase.SaveAssets(); IOUtils.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); QNamespaceDefine nameSpace = new QNamespaceDefine(); nameSpace.Name = string.IsNullOrEmpty(config.NameSpace) ? "QFramework" : config.NameSpace; nameSpace.FileName = config.name + ".cs"; nameSpace.GenerateDir = string.IsNullOrEmpty(config.ScriptGeneratePath) ? EditorPathManager.DefaultPathScriptGenerateForder : IOUtils.CreateDirIfNotExists("Assets/" + config.ScriptGeneratePath); var classDefine = new QClassDefine(); 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 QVariable(QAccessLimit.Private, QCompileType.Const, QTypeDefine.String, "m_" + pathItem.Name, pathItem.Path); classDefine.Variables.Add(variable); var property = new QProperty(QAccessLimit.Public, QCompileType.Static, QTypeDefine.String, pathItem.Name, pathItem.PropertyGetCode, pathItem.Description); classDefine.Properties.Add(property); } } QCodeGenerator.Generate(nameSpace); EditorUtility.SetDirty(config); Resources.UnloadAsset(config); } } AssetDatabase.SaveAssets(); }
public static void Generate(string ns, List <AssetBundleInfo> assetBundleInfos, string projectTag = null) { QNamespaceDefine nameSpace = new QNamespaceDefine(); nameSpace.Name = ns; nameSpace.GenerateDir = ABEditorPathConfig.ABCodeGeneratePath; nameSpace.FileName = "QAssets.cs"; for (int i = 0; i < assetBundleInfos.Count; i++) { AssetBundleInfo assetBundleInfo = assetBundleInfos [i]; string className = assetBundleInfo.name; string bundleName = className.Substring(0, 1).ToUpper() + className.Substring(1); className = className.Substring(0, 1).ToUpper() + className.Substring(1).Replace("/", "_").Replace("@", "_").Replace("!", "_"); if (!string.IsNullOrEmpty(projectTag)) { className = className.Replace("_project_" + projectTag, ""); bundleName = bundleName.Replace("_project_" + projectTag, ""); } className = className.ToUpper(); QClassDefine classDefine = new QClassDefine(); nameSpace.Classes.Add(classDefine); classDefine.Name = className; QVariable variable = new QVariable(QAccessLimit.Public, QCompileType.Const, QTypeDefine.String, "BUNDLE_NAME", bundleName.ToUpperInvariant()); classDefine.Variables.Add(variable); foreach (var asset in assetBundleInfo.assets) { string content = Path.GetFileNameWithoutExtension(asset).ToUpperInvariant(); QVariable assetVariable = new QVariable(QAccessLimit.Public, QCompileType.Const, QTypeDefine.String, content.Replace("@", "_").Replace("!", "_"), content); classDefine.Variables.Add(assetVariable); } } QCodeGenerator.Generate(nameSpace); }