unity-mvc-pattern
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
- ObservableList: A reactive collection that notifies listeners (the View) when data changes.
- Passive View: Views are MonoBehaviours that only care about HOW to display data, not WHERE it comes from.
- Mediated Logic: The Presenter handles the "Wiring" and lifecycle, keeping Data and Visuals completely decoupled.
- 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.
More from muharremtozan/unity-agent-skills
unity-so-prefab-manager
Manages the structured relationship between ScriptableObjects (Data) and Prefabs (Logic/Visuals) in Unity 6. Follows the 'SO-to-Mono' Bridge pattern to ensure instance independence (e.g., individual health for identical robots) while maintaining a clean, data-driven architecture. Use when: (1) Creating new unit/item types, (2) Wiring SO data to Prefab MonoBehaviours, (3) Resolving data-sharing bugs where changing one SO affects all instances.
16unity-fsm
Specialized skill for implementing a robust, extensible Finite State Machine in Unity using the State and Strategy patterns. Based on the pattern by Adam Myhre (3D Platformer). Use when creating complex AI, player controllers, or any system requiring structured state management.
11unity-code-reviewer
Professional Unity C# Code Reviewer. Detects anti-patterns, performance leaks, and enforces project-specific architecture.
10unity-assembly-management
Manage project boundaries using Assembly Definitions (.asmdef) for faster compile times and modular architecture. Based on the patterns by Adam Myhre. Enforces responsibility-based organization and handles Runtime/Editor/Tests splits.
9unity-event-bus
Advanced code-driven event bus with reflection-based bootstrapping. Provides zero-setup global messaging.
9unity-strategy-pattern
Implements the Strategy Pattern to encapsulate interchangeable algorithms (e.g., Spells, Attacks) using ScriptableObjects. Allows hot-swapping behavior without modifying client code. Clean Code approach.
8