UI Builder¶
Introduction¶
The Balancy UI Builder is a powerful visual tool for creating custom user interfaces using HTML, CSS, and JavaScript. With the recent addition of the Prefab & Component System, you can now build complex, reusable UI elements with script behaviors - similar to Unity's GameObject and MonoBehaviour pattern.
Key Features¶
- Visual Editor: Drag-and-drop interface with real-time preview
- Prefab System: Create reusable UI templates with unlimited nesting
- Component-Based Architecture: Attach script behaviors to elements like Unity
- Built-in Templates: Ready-to-use components for shops, offers, and rewards
- Automatic Integration: Seamless connection to Balancy backend data
- Cross-Platform: Works on web, mobile, and desktop
Documentation Sections¶
Getting Started¶
- UI Builder Basics - Interface overview, tools, and workflows
- Working with Views - Creating and managing views
Prefabs & Components System¶
- Prefabs & Components - Unity-like system for reusable UI elements
- Built-in Scripts - Ready-to-use components for common UI patterns
API Reference¶
- Balancy JavaScript API - Complete API documentation
- Data Attributes - Declarative UI configuration
- Events System - Lifecycle and interaction events
Templates¶
- Visual Templates - Built-in templates and how to use them
What Changed?¶
The UI Builder has evolved from a single global script approach to a component-based architecture:
Before (Global Script):
// One large script managing everything
function main() {
// Manually query elements
const buyButton = document.getElementById('buy-btn');
const priceText = document.getElementById('price');
// Wire up logic
buyButton.onclick = () => { /* ... */ };
updatePrice();
}
Now (Component-Based):
// Small, focused scripts attached to elements
class BuyButton extends balancy.ElementBehaviour {
// @serialize {element}
priceText = null;
awake() {
this.element.addEventListener('click', () => this.buy());
}
buy() { /* ... */ }
}
Benefits:
- Reusability: Create prefabs once, use everywhere
- Maintainability: Small, focused scripts are easier to understand
- Composition: Build complex UIs from simple building blocks
- Designer-Friendly: Artists can assemble UIs without touching code
Quick Start¶
- Open UI Builder: Go to Assets → Views → Select a view → Open
- Add Elements: Drag components from the right panel
- Attach Scripts: Select element → Settings tab → Add Script Component
- Configure Parameters: Set element references and values in the inspector
- Save & Test: Use "Play UI" button to test in Demo App
Next Steps¶
- Learn Prefabs & Components to understand the new system
- Explore Built-in Scripts to see what's available
- Check Templates for ready-to-use examples
- Reference Balancy API for complete JavaScript documentation