Version: 2023.2+
This example demonstrates how to create custom controls and use the Vector API to draw visual content onto a visual element.
This example creates a custom control that displays progress, as an alternative to a loading bar. The progress indicator displays a progress value in a partially filled ring around a label that displays the percentage. It supports a value between 0 and 100, which determines how much of the ring is filled.
You can find the completed files that this example creates in this GitHub repository.
This guide is for developers familiar with the Unity Editor, UI Toolkit, and C# scripting. Before you start, get familiar with the following:
Create a C# script to define a RadialProgress
visual element and a C# script to define the custom mesh. Style the visual element with a USS file.
radial-progress
to store your files.radial-progress
folder, create a C# script named RadialProgress.cs
with the following content:Create a USS file named RadialProgress.uss
with the following content:
Use UI Builder to add the control and apply the USS stylesheet. Test the control with different Progress
values.
RadialProgressExample.uxml
.RadialProgressExample.uxml
to open it in the UI Builder.RadialProgress.uss
as the existing USS.radial-progress
in the Name box.Create a C# MonoBehaviour script to update the Progress
property of the control with dynamic values for demo purposes. In the radial-progress
folder, create a C# MonoBehaviour named RadialProgressComponent.cs
with the following content: