unity-ui-data-binding
Unity UI Toolkit Data Binding
Connect your game data (Model) to your interface (View) using modern high-performance data binding. This skill leverages Unity's unity.properties system to eliminate "Update" loop logic for UI updates.
Core Features
- BindableProperty: A wrapper class that uses
[CreateProperty]to expose values to the UI Toolkit binding engine. - MVVM (Model-View-ViewModel): Separates raw game data from UI-formatted data using a ViewModel mediator.
- Reactive Synchronization: UI elements update automatically when the underlying property value changes (or is polled by the engine).
- C# Based Binding: Set up complex bindings programmatically without relying on the UI Builder's inspector fields.
Core Files (Max 3)
BindableProperty.cs.txt: Generic property wrapper for data sources.BindingExample.cs.txt: Practical example showing a Coin display and Health bar bound to a ViewModel.
Usage
1. Define the ViewModel
Initialize BindableProperty fields that return formatted data from your model.
public BindableProperty<string> HealthText { get; }
HealthText = BindableProperty<string>.Bind(() => $"HP: {model.hp}/{model.maxHp}");
2. Set the Data Source
Assign your ViewModel to the dataSource property of your root VisualElement.
root.dataSource = myViewModel;
3. Establish the Binding
Use SetBinding on specific elements to link their properties (text, value, style) to paths in the ViewModel.
label.SetBinding("text", "HealthText.Value");
Key Principle
Always use one-way binding (ToTarget) for displays and two-way binding only for inputs (checkboxes, text fields). This keeps the "Source of Truth" in your Model.
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-observer-pattern
Reactive Property system for Unity. Decouples data from UI and logic using observable wrappers and UnityEvents.
8