Profile Editor
An editable profile screen with an avatar, toggles, and colour-tinted option groups.
Overview
This example demonstrates avatar display, image processing, and color theme selection working together in a profile customization screen. A CircularImageButton shows the user’s avatar; a GrayscaleImage control displays a sample gradient image that can be toggled between full color and black-and-white via a ToggleButton; a five-color ColorToggleGroup lets the user pick a theme color and reflects the selection as a swatch and label.
Controls Featured
- CircularImageButton — circular masked image with an optional tap action; used as the profile avatar
- GrayscaleImage — image control that can render in full color or desaturated grayscale; toggled at runtime to demonstrate the effect
- ColorToggleGroup — mutually exclusive group of
ColorToggleButtonitems; manages single-selection across its children - ColorToggleButton — individual colored circle button that forms part of the
ColorToggleGroup - ToggleButton — two-state toggle control; switches the
GrayscaleImagebetween color and grayscale modes
Scene Setup
- Create a new Unity scene.
- Add an empty GameObject named
ProfileEditorDemoto the scene hierarchy. - Add a
UIDocumentcomponent to the GameObject. - Create a
PanelSettingsasset (Assets > Create > UI Toolkit > Panel Settings) and configure it:- Scale Mode: Scale With Screen Size
- Reference Resolution: 1080 × 1920
- Screen Match Mode: Match Width Or Height, blended toward Height
- Assign the
PanelSettingsasset to theUIDocumentcomponent’s Panel Settings field. - Add the
ProfileEditorDemoMonoBehaviour (found inExamples~/ProfileEditor/) to the same GameObject. - Press Play.
What to Expect
The screen is divided into three vertical sections:
Avatar row — a CircularImageButton displays a placeholder avatar image. Tapping it would typically open a picker; in this demo it logs a message to the Console.
Image preview row — a GrayscaleImage shows a sample gradient image in full color by default. A ToggleButton labeled “B&W” sits beside it. Toggling it on desaturates the image to grayscale; toggling it off restores full color.
Color theme row — a ColorToggleGroup containing five ColorToggleButton items (pastel red, orange, yellow, green, and blue) is displayed horizontally. Tapping a color:
- Marks that
ColorToggleButtonas selected (visually distinct ring or scale). - Updates a color swatch
VisualElementand a text label below the group to reflect the chosen color name.
Only one color may be active at a time; selecting a new color automatically deselects the previous one.
Key Code Patterns
Reacting to ColorToggleGroup selection changes and toggling the grayscale effect:
// ColorToggleGroup fires OnColorSelected with the chosen Color value
_colorGroup.OnColorSelected += color =>
{
_swatchElement.style.backgroundColor = color;
};
// ToggleButton fires OnClicked; read IsSelected for the new state
_grayscaleToggle.OnClicked += () =>
{
_sampleImage.GreyscaleEnabled = _grayscaleToggle.IsSelected;
};