private static string[] GenerateCode() { Type painterInterface = PainterType == PAINTER_TYPE_GEOMETRY_TEXTURE ? typeof(IGTexturePainter) : PainterType == PAINTER_TYPE_FOLIAGE ? typeof(IGFoliagePainter) : PainterType == PAINTER_TYPE_OBJECT ? typeof(IGObjectPainter) : null; //Declare it TypeDeclaration d = new TypeDeclaration.Builder() .SetAccessModifier(AccessModifier.PUBLIC) .SetIsStatic(false) .SetInheritance(Inheritance.DEFAULT) .SetScope(Scope.CLASS) .SetName(PainterName.RemoveSpecialCharacters()) .SetInterfaces(painterInterface) .Build(); //Import regularly used namespaces, just call a Using(...) if you need more UsingNode un = new UsingNode() .Using("UnityEngine") .Using("System.Collections") .Using("System.Collections.Generic") .Using("Pinwheel.Griffin") .Using("Pinwheel.Griffin.PaintTool"); //Import the base class namespace to simplify its name in the declaration string if (d.baseClass != null) { un.Using(d.baseClass.Namespace); } //The same for interfaces if (d.implementedInterface.HasElement()) { for (int i = 0; i < d.implementedInterface.Count; ++i) { un.Using(d.implementedInterface[i].Namespace); } } //Give it a hint to determine type names TypeAlias.SetUsingNode(un); List <string> code = new List <string>(); //Implement the type TypeNode tn = new TypeNode() .Declare(d) .Implement(code); //Put the new type into the namespace //NamespaceNode nn = new NamespaceNode() // .SetName("CustomPainter") // .SetTypes(tn); //Put everything into a script ScriptNode sn = new ScriptNode() .SetCompilationDirective("GRIFFIN") .SetUsing(un) //.SetNamespace(nn) .SetTypes(tn); //also set type in case namespace is empty //Now make the code look awesome CodeFormatter formatter = new CodeFormatter(); formatter.addSpaceAfterUsings = true; formatter.addSpaceBetweenMethods = true; formatter.bracketStyle = CodeFormatter.OpenCurlyBracketStyle.NewLine; string[] script = formatter.Format(sn); return(script); //phew... }
private static string[] GenerateCode() { //Declare it TypeDeclaration d = new TypeDeclaration.Builder() .SetAccessModifier(AccessModifier.PUBLIC) .SetIsStatic(true) .SetInheritance(Inheritance.DEFAULT) .SetScope(Scope.CLASS) .SetName(ExtensionName.RemoveSpecialCharacters()) .Build(); //Import regularly used namespaces, just call a Using(...) if you need more UsingNode un = new UsingNode() .Using("UnityEngine") .Using("System.Collections") .Using("System.Collections.Generic") .Using("UnityEditor"); //Import the base class namespace to simplify its name in the declaration string if (d.baseClass != null) { un.Using(d.baseClass.Namespace); } //The same for interfaces if (d.implementedInterface.HasElement()) { for (int i = 0; i < d.implementedInterface.Count; ++i) { un.Using(d.implementedInterface[i].Namespace); } } //Give it a hint to determine type names TypeAlias.SetUsingNode(un); List <string> code = new List <string>(); //add basic function for an extension code.Add(GetExtensionNameCode()); code.Add(GetPublisherNameCode()); code.Add(GetDescriptionCode()); code.Add(GetVersionCode()); code.Add(GetOpenUserGuideCode()); code.Add(GetOpenSupportLinkCode()); code.Add(GetButtonMethodCode()); code.Add(GetOnGUICode()); //Implement the type TypeNode tn = new TypeNode() .Declare(d) .Implement(code); //Put the new type into the namespace NamespaceNode nn = new NamespaceNode() .SetName(string.Format("{0}.GriffinExtension", PublisherName.RemoveSpecialCharacters())) .SetTypes(tn); //Put everything into a script ScriptNode sn = new ScriptNode() .SetCompilationDirective("GRIFFIN && UNITY_EDITOR") .SetUsing(un) .SetNamespace(nn) .SetTypes(tn); //also set type in case namespace is empty //Now make the code look awesome CodeFormatter formatter = new CodeFormatter(); formatter.addSpaceAfterUsings = true; formatter.addSpaceBetweenMethods = true; formatter.bracketStyle = CodeFormatter.OpenCurlyBracketStyle.NewLine; string[] script = formatter.Format(sn); return(script); //phew... }