After adding Modula to your project, it’s time to make your first module!

Making example behaviour

Step 1 - create new main script that supports modules:

  • Create new MonoBehaviour script
  • use namespace Modula
  • change inheritance to ModularBehaviour
using Modula;


public class ModularExample : ModularBehaviour
{

}

Step 2 - create your first module

  • Create new MonoBehaviour script
  • use namespace Modula
  • change inheritance to Module
using Modula;


public class ExampleModule : Module
{

}

Step 3 - add support for ExampleModule in ModularExample

  • Get back to your behaviour script
  • Override AvailableModules field
public class ModularExample : ModularBehaviour
{
    public override TypeList AvailableModules { get; } 
        = new TypeList()
        .Add(typeof(ExampleModule));
}

Step 4 - create GameObject for your new behaviour

  • in Unity, go to Hierarchy window > “+” > Create Empty
  • select the created object
  • click “Add Component” > ModularExample

Done! now you can add or remove your module in Inspector window by clicking “Add ExampleModule” / “Remove”

Result

result image