UI Toolkit の最も基本的な構成要素はビジュアル要素です。このビジュアル要素は、親子関係を持つ階層ツリー内で順番付けされます。このツリーはビジュアルツリーと呼ばれます。
下の図は、ビジュアルツリーの簡略化した例と、UI Toolkit でのレンダリング結果を示しています。
図中のルートは、エディター UI では EditorWindow.rootVisualElement
を、ランタイム UI では UIDocument.rootVisualElement
を表します。
VisualElement クラスは、ビジュアルツリーのすべてのノードの基本になります。VisualElement
基本クラスは、スタイル、レイアウトデータ、イベントハンドラーなどのプロパティを含んでいます。ビジュアル要素は、子や子孫のビジュアル要素を持つことができます。例えば、上の図では、最初の Box
ビジュアル要素は、 Label
、Checkbox
、Slider
の 3 つの子ビジュアル要素を持っています。
インラインスタイルとスタイルシートを使って、ビジュアル要素の外観をカスタマイズできます。また、イベントコールバックを使ってビジュアル要素の動作を変更することもできます。
VisualElement
は、コントロールなどの追加の動作や機能を定義するサブクラスに派生します。UI Toolkit には、特殊な動作をするさまざまなビルトインのコントロールが含まれています。コントロールは、グラフィカルユーザーインターフェース (GUI) の要素です。例えば、以下のようなものがビルトインコントロールとして用意されています。
コントロールには、コントロールのビジュアルと、コントロールを操作して対話するためのスクリプト化されたロジックが含まれます。単一のビジュアル要素で構成することも、複数のビジュアル要素を組み合わせることもできます。例えば、トグルコントロールには 3 つの要素があります。
トグルコントロールの実装では、コントロールの動作を定義します。トグルの状態が true か false かの内部値を持っています。このロジックは、値が変化するときに、チェックマーク画像の可視性を変化させます。
ビジュアル要素を組み合わせたり、その動作を変更して カスタムコントロール を作成することもできます。
コントロールを UI で使用するには、ビジュアルツリーに追加します。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.