Advanced
Change region name
If you need to change the region's name
#region Prebuild
#endregion
[Prebuild("MyPrebuild", typeof(Example), typeof(Example2))]
public class MyClass {
...
}
#region MyPrebuild
#endregion
Script links
It is possible to create links between files. With links you can reference a script in another scriptInfo. For example, if you have two classes : MyClient and MyServer and you must know MyClient script when MyServer methods generation.
Create links in your custom Prebuild class:
public class MyNetworkAttribute : PrebuildAttribute {
public MyNetworkAttribute() : base(typeof(MyNetworkPack)) {}
public MyNetworkAttribute(string region) : base(region, typeof(MyNetworkPack)) {}
public override bool AddReference(ScriptInfos scriptInfo1, ScriptInfos scriptInfo2) {
return
scriptInfo1.FilePath.Replace("Client.cs", "Server.cs") == scriptInfo2.FilePath
||
scriptInfo2.FilePath.Replace("Client.cs", "Server.cs") == scriptInfo1.FilePath
;
}
}
Now, scripts are linked
public override string GetContent(System.Reflection.FieldInfo fieldInfo, ScriptInfos scriptInfo, uint fieldID, uint elementUID) {
HasReference(scriptInfo); // return true if this script has references to other scripts
scriptInfo.References; // List<ScriptInfos>
scriptInfo.References[0].WriteContent("// hello"); // you can write in other referenced scripts
}
See ScriptInfos
for more functions.
Add arguments on attribute
You can easily add arguments in your custom attribute
[AttributeUsage(AttributeTargets.Method)]
public sealed class Example2Attribute : InheritPrebuildAttribute {
public string LogThat = "";
public Example2Attribute(string logThat = "Nothing") {
LogThat = logThat;
}
public override string GetContent(System.Reflection.MethodInfo methodInfo, ScriptInfos scriptInfo, uint methID, uint elementUID) {
return PrebuildAttribute.BaseMethod("void", methodInfo, "Logger" + methodInfo.Name, CreateMyMethodContent());
}
string CreateMyMethodContent() {
return PrebuildAttribute.Template(" Debug.Log(\"${logThat}\");",
"logThat", LogThat
);
}
}
[Example2("Hey hey hey")]
Vector2 Test2(float a, float b) {
return new Vector2(a, b);
}
#region Prebuild
private void LoggerTest2(float a, float b) {
Debug.Log("Hey hey hey");
}
#endregion
Before/After
You can generate code on start/end of a script pass.
// Call 1 time by script before all GetContent
public virtual string Before(ScriptInfos scriptInfo) { return ""; }
public virtual string GetContent(...) { return ""; }
// Call 1 time by script after all GetContent
public virtual string After(ScriptInfos scriptInfo) { return ""; }