Version: 2023.2+
この例では、カスタムコントロールを作成し、Vector API を使用してビジュアル要素にビジュアルコンテンツを描画する方法を示します。
この例では、ローディングバーの代わりに進行状況を表示するカスタムコントロールを作成します。進捗インジケーターは、パーセンテージを表示するラベルの周囲に、部分的に塗りつぶされた輪で進捗値を表示します。0 から 100 までの値で表示され、それにより輪がどの程度塗りつぶされるかが決定されます。
You can find the completed files that this example creates in this GitHub repository.
このガイドは、Unity エディター、UI Toolkit、および C# スクリプトに精通している開発者を対象としています。始める前に、以下をよく理解してください。
RadialProgress ビジュアル要素を定義する C# スクリプトとカスタムメッシュを定義する C# スクリプトを作成します。USS ファイルでビジュアル要素をスタイルを設定します。
radial-progress というフォルダーを作成し、ファイルを保存します。radial-progressフォルダーに、以下のコンテンツを持つ RadialProgress.cs という名の C#スクリプトを作成します。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 という名前の UI Document を作成します。RadialProgressExample.uxml をダブルクリックして UI Builder で開きます。RadialProgress.uss as the existing USS.radial-progress と入力します。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: