mcpField
U
unity-mvc-pattern

unity-mvc-pattern

github.com/muharremtozanDevelopment1755 installsUpdated 22w ago
Repository

About unity-mvc-pattern

A Unity MVC/MVP skill for developers separating game data, visuals, and presentation logic. It provides observable collections, passive views, presenter lifecycle wiring, and an MMO hotbar example.

Key features

  1. 01ObservableList change notifications
  2. 02Passive MonoBehaviour views
  3. 03Presenter-mediated binding
  4. 04MMO hotbar example

Use cases

  1. 01Build inventory interfaces
  2. 02Implement skill trees or settings UI
  3. 03Separate game state from visuals

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/muharremtozan/unity-agent-skills --skill unity-mvc-pattern

After installing, type/unity-mvc-patternin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/code/
GenericPresenter.cs.txt
MMOHotbarExample.cs.txt
ObservableList.cs.txt

Details

From the project README

Unity MVC / MVP Pattern

This skill implements the architectural principle of "Separation of Concerns." It divides your code into three distinct layers: Model (Data), View (Visuals), and Presenter (Logic bridge).

Core Features

  1. ObservableList: A reactive collection that notifies listeners (the View) when data changes.
  2. Passive View: Views are MonoBehaviours that only care about HOW to display data, not WHERE it comes from.
  3. Mediated Logic: The Presenter handles the "Wiring" and lifecycle, keeping Data and Visuals completely decoupled.
  4. MMO Hotbar Pattern: A concrete implementation of the multi-slot observable layout described in the reference text.

Core Files (Max 3)

  • ObservableList.cs.txt: Generic collection wrapper with structural change notifications.
  • GenericPresenter.cs.txt: Base class for creating M-V-P relationships without boilerplate.
  • MMOHotbarExample.cs.txt: Practical application showing data flowing from a Model to a UI view.

Usage

1. The Model (Data)

Contains your state using Observable<T> or ObservableList<T>. It does not know about Unity UI.

2. The View (Visuals)

A MonoBehaviour that exposes public methods for updating its state (e.g., SetHealth(float val)).

3. The Presenter (Bridge)
public class MyPresenter : Presenter<MyModel, MyView> {
    protected override void Bind() {
        model.health.OnChanged += view.SetHealth;
    }
}

When to Use

Use this pattern for complex UI (Inventories, Skill Trees, Settings) or high-level game managers where logic and visuals are likely to change independently.

Comments

Markdown supported