Module
You can transform a class to a module usable in this plugin either by inheriting from ModuleBehaviour or implementing the IModule interface
. The default approach is to inherit from ModuleBehaviour which provides a default implementation of the IModule interface that you can override if you need to. If you already inherit from a class other than MonoBehaviour, you can implement the IModule interface and the ModularBehaviour will find it during its initialization stage.
Initializing your module
public class ModuleA : ModuleBehaviour {
// Override the default InitModule function
public override async Task InitModule() {
// Do stuff in it, (reading a file, loading hundred of megabytes, fetching some data from the web)
await Task.Delay(1000);
}
}
Dependencies
You can add dependencies using attributes and access them anywhere in your class
// You can add dependencies using the RequireModule attribute
[RequireModule(typeof(ModuleB), typeof(ModuleC))]
// You can also specify optionnal dependencies to be initialized before this module if they exist
[RequireOptionnalModule(typeof(ModuleD))]
public class ModuleA : ModuleBehaviour {
public override Task InitModule() {
// If you need to access a module, use the Owner variable, which is a reference to the ModularBehaviour that initialized this module
var moduleB = Owner.GetModule<ModuleB>();
moduleB.DoStuff();
return Task.Completed;
}
}
Shutdown
A module can get shutdonw on two occasions: during an initialization error or during a normal shutdown. Either way you get the isError variable as a parameter to allow you to deal with the two situations.
public class ModuleA : ModuleBehaviour {
public override void ShutdownModule(bool isError) {
// Cleanup
}
}