ビジュアルツリーは、ウィンドウ内のすべてのビジュアル要素を含みます。これは visual element (ビジュアル要素) と呼ばれる軽量のノードで作られたオブジェクトグラフです。
これらのノードは、C#ヒープ上で手動、または UXML テンプレートファイルから UXML アセットをロードすることによって、割り当てられます。
各ノードには、レイアウト情報、描画と再描画オプション、ノードがイベントに反応する方法が含まれます。
VisualElement
は、ビジュアルツリー内のすべてのノードの共通基本クラスです。VisualElement
基本クラスには、スタイル、レイアウトデータ、ローカルの変換、イベントハンドラーなどのプロパティが含まれています。
VisualElement
には、特別なコントロールなどの、追加の動作と機能を定義するいくつかのサブクラスがあります。VisualElement
は子要素を持つ場合もあります。
You are not required to derive from the VisualElement
base class to work with elements. You can customize the look and behavior of a VisualElement
through stylesheets and event callbacks.
ビジュアルツリーのルートオブジェクトはパネルと呼ばれます。新しい要素はパネルに接続するまで無視されます。既存の要素に要素を加えて、ユーザーインターフェースをパネルに設定できます。
VisualElement
がパネルに接続されているかどうかを検証するには、この要素の panel
プロパティをテストします。ビジュアル要素が接続されていない場合、テストは null
を返します。
新しい要素を UnityEditor.UIElements
名前空間のコンテナオブジェクトの rootVisualElement
要素を持つツリーに追加します。
ビジュアルツリーの要素は次の順序で描画されます。
描画順を変える唯一の方法は VisualElement
オブジェクトを親の中で並べ替えることです。
異なる座標系は以下のように定義されます。
レイアウトシステムは各要素の VisualElement.layout
プロパティ (Rect
型) を計算します。
layout.position
は親の座標空間に相対的なピクセルとして表現されます。layout.position
に直接値を指定することもできますが、スタイルシートとレイアウトシステムを使用して要素を配置することを推奨します。
各 VisualElement
には、親に相対的な要素の位置を決定する layout.transform
プロパティ (ITransform
型) もあります。
VisualElement.layout.position
と VisualElement.layout.transform
プロパティはローカル座標系と親座標系間の変換方法を定義します。
VisualElementExtensions
静的クラスは以下の拡張メソッドを提供し、座標系間の点と矩形を変換します。
WorldToLocal
は、Panel
空間の Vector2
または Rect
を要素内の参照に変換します。LocalToWorld
は Vector2
または Rect
を Panel
空間参照に変換します。ChangeCoordinatesTo
は要素のローカル空間の Vector2
または Rect
を別の要素のローカル空間に変換します。例えば、上の画像で、ツリーは以下のように配置されます。
Panel
(パネル)
DockArea
と呼ばれ、“Coordinates” とラベル付けされます)VisualElement
はルートの動作をします (“rootVisualContainer” と呼ばれます)
VisualElement
は、ボタンの親の動作します (“赤いコンテナ”)。
Button
パネルの観点からは以下のとおりです。
position
プロパティ (layout
プロパティで定義) は (100, 100) に設定されます。なぜなら、その親 (ルートコンテナ) に相対的だからです。position
プロパティ (layout
プロパティで定義) は (0, 0) に設定されます。なぜなら、その親 (赤いコンテナ) に相対的だからです。要素の原点は左上の角です。
worldBound
プロパティを使用すると、VisualElement
のウィンドウ空間座標を取得し、その一連の親子関係の変換と位置を考慮することができます。
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.