Luna UI provides a theming system through the UIColor, UIColorName, and UIColorValue classes. This system generates USS class names for consistent color styling across your UI.
The UIColor system maps color names and values to USS class names following a utility-first approach similar to Tailwind CSS. It supports backgrounds, borders, text, and image tints.
Available color names:
| Semantic | Description |
|---|---|
| BASE | Base theme color |
| PRIMARY | Primary accent color |
| SECONDARY | Secondary accent color |
| Gray Scale | |
|---|---|
| SLATE | Blue-gray tones |
| GRAY | Neutral gray |
| ZINC | Cool gray |
| NEUTRAL | True neutral |
| STONE | Warm gray |
| Colors | |
|---|---|
| RED | Red |
| ORANGE | Orange |
| AMBER | Amber/Gold |
| YELLOW | Yellow |
| LIME | Lime green |
| GREEN | Green |
| EMERALD | Emerald green |
| TEAL | Teal |
| CYAN | Cyan |
| SKY | Sky blue |
| BLUE | Blue |
| INDIGO | Indigo |
| VIOLET | Violet |
| PURPLE | Purple |
| FUCHSIA | Fuchsia/Magenta |
| PINK | Pink |
| ROSE | Rose |
| Special | |
|---|---|
| TRANSPARENT | Transparent color |
Color intensity values (50-950):
| Value | Description |
|---|---|
| V_50 | Lightest |
| V_100 | Very light |
| V_200 | Light |
| V_300 | Light-medium |
| V_400 | Medium-light |
| V_500 | Medium (default) |
| V_600 | Medium-dark |
| V_700 | Dark |
| V_800 | Very dark |
| V_900 | Darkest |
| V_950 | Near black |
Combines a color name and value to generate USS class names.
public UIColor() // Default: SLATE-50
public UIColor(UIColorName name, UIColorValue value)| Method | Returns | Example Output |
|---|---|---|
| GetUssClassBG() | Background class | bg-blue-500 |
| GetUssClassBorder() | Border class | border-blue-500 |
| GetUssClassText() | Text class | text-blue-500 |
| GetUssClassImageTint() | Tint class | tint-blue-500 |
| GetColor(VisualElement) | Unity Color | Reads from USS variables |
using UnityEngine;
using UnityEngine.UIElements;
using CupkekGames.Luna;
public class ColorExample : MonoBehaviour
{
[SerializeField] private UIColor _buttonColor = new UIColor(UIColorName.PRIMARY, UIColorValue.V_500);
private void Start()
{
var button = _uiDocument.rootVisualElement.Q<Button>("MyButton");
// Apply background color class
button.AddToClassList(_buttonColor.GetUssClassBG());
// Apply border color class
button.AddToClassList(_buttonColor.GetUssClassBorder());
}
}public void SetButtonState(Button button, bool isActive)
{
// Remove old classes
button.RemoveFromClassList(_inactiveColor.GetUssClassBG());
button.RemoveFromClassList(_activeColor.GetUssClassBG());
// Add new class based on state
var color = isActive ? _activeColor : _inactiveColor;
button.AddToClassList(color.GetUssClassBG());
}To get the actual Unity Color value from USS variables:
UIColor myColor = new UIColor(UIColorName.BLUE, UIColorValue.V_500);
// Element must be in the hierarchy for custom styles to be resolved
Color actualColor = myColor.GetColor(myElement);This reads from the USS custom property --color-{name}-{value}.
The system generates classes following this pattern:
| Type | Pattern | Example |
|---|---|---|
| Background | bg-{name}-{value} | bg-primary-500 |
| Border | border-{name}-{value} | border-red-600 |
| Text | text-{name}-{value} | text-slate-100 |
| Tint | tint-{name}-{value} | tint-green-400 |
For TRANSPARENT, the value is omitted:
bg-transparentborder-transparenttext-transparenttint-transparentColors are defined as USS custom properties:
:root {
/* Primary colors */
--color-primary-50: #eff6ff;
--color-primary-100: #dbeafe;
--color-primary-200: #bfdbfe;
--color-primary-300: #93c5fd;
--color-primary-400: #60a5fa;
--color-primary-500: #3b82f6;
--color-primary-600: #2563eb;
--color-primary-700: #1d4ed8;
--color-primary-800: #1e40af;
--color-primary-900: #1e3a8a;
--color-primary-950: #172554;
/* Blue colors */
--color-blue-50: #eff6ff;
/* ... */
}
/* Background utility classes */
.bg-primary-500 {
background-color: var(--color-primary-500);
}
.bg-blue-600 {
background-color: var(--color-blue-600);
}
/* Border utility classes */
.border-red-500 {
border-color: var(--color-red-500);
}
/* Text utility classes */
.text-slate-100 {
color: var(--color-slate-100);
}
/* Image tint utility classes */
.tint-green-400 {
-unity-background-image-tint-color: var(--color-green-400);
}UIColor is serializable and works in the Unity Inspector:
public class MyComponent : MonoBehaviour
{
[SerializeField] private UIColor _backgroundColor;
[SerializeField] private UIColor _borderColor;
[SerializeField] private UIColor _textColor;
}using UnityEngine;
using UnityEngine.UIElements;
using CupkekGames.Luna;
public class ThemedButton : MonoBehaviour
{
[SerializeField] private UIColor _normalBg = new UIColor(UIColorName.PRIMARY, UIColorValue.V_500);
[SerializeField] private UIColor _hoverBg = new UIColor(UIColorName.PRIMARY, UIColorValue.V_600);
[SerializeField] private UIColor _pressedBg = new UIColor(UIColorName.PRIMARY, UIColorValue.V_700);
[SerializeField] private UIColor _textColor = new UIColor(UIColorName.SLATE, UIColorValue.V_50);
private void Start()
{
var button = _uiDocument.rootVisualElement.Q<Button>("ThemedButton");
// Apply base styles
button.AddToClassList(_normalBg.GetUssClassBG());
button.AddToClassList(_textColor.GetUssClassText());
// Handle hover/press states in USS or via events
button.RegisterCallback<MouseEnterEvent>(e => {
button.RemoveFromClassList(_normalBg.GetUssClassBG());
button.AddToClassList(_hoverBg.GetUssClassBG());
});
button.RegisterCallback<MouseLeaveEvent>(e => {
button.RemoveFromClassList(_hoverBg.GetUssClassBG());
button.AddToClassList(_normalBg.GetUssClassBG());
});
}
}Settings
Theme
Light
Contrast
Material
Dark
Dim
Material Dark
System
Sidebar(Light & Contrast only)
Font Family
DM Sans
Wix
Inclusive Sans
AR One Sans
Direction