Table of Contents

Module Generator

Generate modules from the Unity editor -- no manual boilerplate. The generator creates the Module Pattern.


Generate Module (Plain C#)

Menu: Pixel Engine / Generate Module

  1. A dialog prompts for the module name
  2. Pick a target folder
  3. Generates {Name}.cs with the full Module Pattern

What It Creates

A plain C# class implementing the 4-struct architecture:

  • readonly struct Configuration : IConfiguration with Default field
  • readonly struct Reference : IReference with Default field
  • struct State : IState with public fields (external reads get copy)
  • class Components : IComponents
  • Backing fields with expression-body properties
  • SetConfiguration(in Configuration) with in keyword
  • Constructor overloads, Init(), Dispose()
  • Event placeholders

See Module Pattern for the full generated code.


Generate Module Component (MonoBehaviour)

Menu: Pixel Engine / Generate Module Component

Same flow, but generates the MonoBehaviour variant:

  • struct Configuration : IConfiguration (not readonly -- Inspector needs mutability)
  • struct Reference : IReference
  • [SerializeField] private Inspector fields
  • ref readonly property returns for Configuration/Reference
  • Awake() -> Init(), OnDestroy() -> Dispose()
  • Event placeholders

See Module Pattern for the full generated code.


When to Use Which

Generate Module Generate Module Component
Use when Logic-only, no scene presence Needs Inspector, lives on a GameObject
Lifecycle Manual Init() / Dispose() Awake() / OnDestroy()
Config/Ref readonly struct, constructor-injected, in keyword struct, [SerializeField] private, ref readonly

Programmatic Usage

The generator is a static class you can call from your own editor tools:

using PixelEngine.Editor;

// Generate a plain C# module
ModuleGenerator.GenerateModule("WeaponSystem", "Assets/Scripts/Runtime/");

// Generate a MonoBehaviour module
ModuleGenerator.GenerateModuleComponent("WeaponSystemComponent", "Assets/Scripts/Runtime/");

See Also