unity-observer-pattern
Unity Observer Pattern (Reactive Properties)
A powerful implementation of the Observer pattern that turns standard variables into "Smart Properties." Includes full Inspector support and Edit-mode tooling based on the "Generic Observer" architecture.
Core Features
- Hybrid Path: Works with standard C# listeners (Pro Path) AND UnityEvents (Designer/Light Path).
- Implicit Casting: Seamless syntax allows
int x = myObservableInt;(no more.Valueboilerplate). - Editor Persistence: Programmatically wire persistent calls in Edit Mode that save to scene/prefab.
- Diagnostic Logging: Built-in structured logging for tracking event flows.
Core Files (Max 3)
Observable.cs.txt: The core generic wrapper with implicit casting and built-in editor wiring.ObservableEditorTools.cs.txt: Advanced reflection hacks for clearing persistent UnityEvents.ObservableExample.cs.txt: Concrete example demonstrating UI binding and lifecycle management.
Usage
Option A: The Light Path (Inspector)
- Define a field:
public Observable<int> health;. - In Unity Inspector, drag your UI method into the
On Value Changedlist.
Option B: The Pro Path (Code)
health.AddListener( val => Debug.Log( val ) );
health.Value = 50; // Automatically triggers notification
Option C: Implicit Usage
int currentHealth = health; // Works automatically via implicit operator
Cleanup
Always call RemoveListener or Dispose in OnDisable to prevent memory leaks.
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-ui-data-binding
Implementation of MVVM-style Data Binding for Unity UI Toolkit using the [CreateProperty] attribute and BindableProperty wrappers.
9