Foldout は UI の折りたたみ可能なセクションです。Foldout のヘッダーをクリックすると、その中に含まれる要素を表示したり隠したりします。
Foldout は以下の要素を持ちます。
Foldout のコンテナに要素を加えることができ、表示/非表示機能は自動的に機能します。
以下の UI Document は、コンテナ内に 2 つのボタンを持つ Foldout を作成します。2 つのボタンは、Foldout をトグルすると表示/非表示されます。
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<ui:Foldout text="Foldout" name="MyFoldout" value="true">
<ui:Button text="First item" />
<ui:Button text="Second item" />
</ui:Foldout>
</ui:UXML>
Foldout とその Toggle サブ要素は、Change イベント に応答します。Toggle は、Foldout コンテナを隠したり、表示したりします。
Foldout をブーリアン変数にバインドしたり、INotifyValueChanged<bool>
を通じてその値にアクセスしたりすることができます。
以下の C# コードスニペットでは、Foldout を作成し、Foldout が展開されているかどうかを確認します。
// Create a new foldout, add two elements to it and add it to the container
var cSharpFoldout = new Foldout {text = "Elements"};
cSharpFoldout.Add(new Label("Indented Label"));
cSharpFoldout.Add(new Slider("Indented Slider", 0, 100));
container.Add(cSharpFoldout);
cSharpFoldout.RegisterValueChangedCallback(e =>
{
// Check whether the foldout is expanded
if (cSharpFoldout.value)
{
Debug.Log("Foldout is expanded");
}
else
{
Debug.Log("Foldout is collapsed");
}
});
C# クラス: Foldout
名前空間: UnityEngine.UIElements
基本クラス: BindableElement
この要素は以下のメンバー属性を持ちます。
名前 | 型 | 説明 |
---|---|---|
text |
string |
トグルのラベルのテキストです。 |
value |
boolean |
これは Foldout のトグルの状態です。Foldout が開いていてコンテンツが表示されている場合は true、閉じていてコンテンツが隠れている場合は false です。 |
この要素は基本クラスから以下の属性を継承します。
名前 | 型 | 説明 |
---|---|---|
binding-path |
string |
バインドされるべきターゲットプロパティのパス。 |
focusable |
boolean |
要素がフォーカス可能である場合は true。 |
tabindex |
int |
フォーカスリング内でフォーカス可能なものをソートするために使用される整数。0 以上であることが必要です。 |
この要素は、VisualElement
から以下の属性も継承します。
名前 | 型 | 説明 |
---|---|---|
content-container |
string |
子要素はそれに追加されますが、通常は要素自体と同じです。 |
name |
string |
この VisualElement の名前。 このプロパティを使用して、特定の要素を対象とする USS セレクターを記述します。要素には一意の名前を付けるのが標準的です。 |
picking-mode |
UIElements.PickingMode |
mouseEvents または IPanel.Pick クエリの間にこの要素を選択 (ピック) できるかどうかを決定します。 |
style |
string |
この要素のスタイルオブジェクトへの参照。 C# でこのオブジェクトに書き込まれた USS ファイルまたはインラインスタイルから計算されたデータが含まれます。 |
toolbar |
string |
ユーザーが要素をマウスオーバーした後、わずかな時間、情報ボックス内に表示するテキスト。これはエディター UI でのみサポートされます。 |
usage-hints |
UIElements.UsageHints |
VisualElement の高レベルの使用パターンを指定するヒント値の組み合わせ。このプロパティは、VisualElement がまだ Panel の一部でない場合にのみ設定できます。Panel の一部になると、このプロパティは事実上読み取り専用となり、変更しようとすると例外がスローされます。適切な UsageHints を指定することで、予想される使用パターンに基づいて、特定の操作をどのように処理するか、または高速化するかについて、システムがより適切な判断を下すようになります。これらのヒントは動作や視覚的な結果には影響しませんが、パネルとその中の要素の全体的なパフォーマンスにのみ影響することに注意してください。常に適切なUsageHints を指定することを考慮することをお勧めしますが、特定の条件下 (例えば、ターゲットプラットフォームのハードウェア制限など) では、いくつかの UsageHints が内部的に無視される可能性があることに留意してください。 |
view-data-key |
string |
ビューデータの永続性 (ツリーの展開状態、スクロール位置、ズームレベルなど) に使用されます。 これは、ビューデータストアからビューデータを保存/ロードするために使用されるキーです。このキーを設定しないと、この VisualElement の永続性が無効になります。 |
以下の表は、すべての C# パブリックプロパティ名と、それに関連する USS セレクターのリストです。
C# プロパティ | USS セレクター | 説明 |
---|---|---|
ussClassName |
.unity-foldout |
Foldout 要素の USS クラス名。 Unity はこの USS クラスをすべての Foldout インスタンスに加えます。このクラスに適用されるスタイルは、ビジュアルツリーでスタイルシートの横または下に位置するすべての Foldout に影響します。 |
toggleUssClassName |
.unity-foldout__toggle |
Foldout 要素の Toggle サブ要素の USS クラス名。 Unity はこの USS クラスをすべての Foldout 要素の Toggle サブ要素に加えます。このクラスに適用されるスタイルは、ビジュアルツリーでスタイルシートの横または下に位置するすべての Toggle サブ要素に影響します。 |
contentUssClassName |
.unity-foldout__content |
Foldout 内の content 要素の USS クラス名。 Unity はこの USS クラスを、表示または非表示にする要素を持つ VisualElement に加えます。このクラスに適用されるスタイルは、ビジュアルツリー内のスタイルシートの横または下に位置するすべての foldout コンテナに影響します。 |
inputUssClassName |
.unity-foldout__input |
Foldout 内の Label 要素の USS クラス名です。 Unity はこの USS クラスを Toggle input 要素を含む VisualElement に加えます。このクラスに適用されるスタイルは、ビジュアルツリーのスタイルシートの横または下にあるすべての foldout コンテナに影響します。 |
checkmarkUssClassName |
unity-toggle__checkmark |
Foldout 内の Label 要素の USS クラス名です。 Unity は、すべての Foldout の Toggle サブ要素のチェックマークを表す VisualElement にこの USS クラスを加えます。このクラスに適用されるスタイルは、ビジュアルツリーのスタイルシートの横または下にあるすべての折りたたみコンテナに影響します。 |
textUssClassName |
.unity-foldout__text |
Foldout 内の Label 要素の USS クラス名です。 Unity はこの USS クラスをすべての Foldout の Toggle サブ要素の Label に加えます。このクラスに適用されるスタイルは、ビジュアルツリーのスタイルシートの横または下に位置するすべての foldout コンテナに影響します。 |
disabledUssClassName |
.unity-disabled |
ローカルで無効にされた要素の USS クラス名。 |
また、Inspector や UI Toolkit Debugger の Matching Selectors セクション を使用して、どの USS セレクターが 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.