Module Controller helps you piece your Character Controllers, Vehicle Controllers, and others into smaller modular pieces (aka Modules). This helps you keep your scripts more focused and makes it easier to modify and add new features.
- Clone or download the repository.
- Copy ModuleController folder from Plugins folder to your project.
- Take a look at the included Demos to see examples of how you can introduce a bit more modularity into your Character Controllers and such.
- Done!
Developed in Unity 2020.3.23f1, but I don't see why it wouldn't work in any Unity version.
- Create new scripts for your Module Controller (named FooModuleController, for example) and your Module base class (named AbstractFooModule, for example).
- If your classes are MonoBehaviours, you can inherit from ModuleControllerBehaviour and ModuleBehaviour, which are also MonoBehaviours and include all the needed boilerplate code. Alternatively, you can implement IModuleController and IModule interfaces to customize them further.
- In your Module Controller script, add
SetupModules();
to your Start function andUpdateModules(Time.deltaTime);
to your Update or FixedUpdate function. - Make new scripts for your Modules (named FooBarModule, FooBazModule, etc) and make them inherit from your Module base class. You can override your module's SetupModule function and add
Debug.Log($"Hello {GetType().Name}");
to confirm that they are setup. - Make a new GameObject and add your new Module Controller and Module scripts to it.
- Press play!
A basic FPS Character Controller with modular abilities.
3rd Person Character Controller with simple IK.
Vehicle Controller with multiple Module Controllers and submodules.
- Modules can also be Module Controllers and have their own submodules. Just implement IModuleController in your Module, add all the necessary boilerplate code and make scripts for its Modules.
- Adding and removing Modules during runtime is currently not implemented.