Version: Unity 6.0 (6000.0)
言語 : 日本語
SliderInt
TabView

Tab

Tab 要素は、TabView 内の 1 つのタブを表します。ウィンドウまたはメニューで、タブを使用して関連コンテンツをグループ化できます。

タブを閉じられるようにする

タブを閉じられるようにするには、closable プロパティを true に設定します。タブが閉じられる場合は、閉じるアイコンがタブに表示されます。閉じるアイコンをユーザーが選択すると、タブは閉じます。

タブにアイコンを追加する

タブにアイコンを追加して、視覚的により魅力的にすることができます。テクスチャ、レンダーテクスチャ、スプライト、ベクトルなど、プロジェクト内にある画像アセットをアイコンにすることができます。画像アセットの参照方法については、アセット を参照してください。

UI Builder でタブにアイコンを追加するには、以下のいずれかを行います。

  • タブの Inspector パネルで、Icon Image ドロップダウンリストからアイコンを選択します。
  • Assets ウィンドウから、タブの Inspector パネルにある Icon Image フィールドにアイコンをドラッグします。

UXML でタブのアイコンを追加するには、以下のように画像のソースを icon-image 属性に追加します。

<ui:Tab name="Tab" text="Tab text" icon-image="/path/to/image-file.png" />

C# でタブのアイコンを追加するには、以下のように画像ソースを iconImage プロパティに割り当てます。

Tab myTab = new Tab();
var TabIconImage = Resources.Load<Texture2D>("image-file");

myTab.text = "Tab text";
myTab.iconImage = TabIconImage;

以下の UXML 例では、タブを含む TabView を作成します。

<UXML xmlns="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
    <TabView>
       <Tab label="UXML Tab A">
           <Label text="UXML tab: This is some content for the first Tab." />
       </Tab>
       <Tab label="UXML Tab B">
           <Label text="UXML tab: This is some content for the second Tab." />
       </Tab>
    </TabView>
</UXML>

以下の C# の例では、TabView とそのタブのカスタマイズ可能な機能の一部を示しています。

/// <sample>
// Create a TabView with Tabs that only contains a label.
var csharpTabViewWithLabels = new TabView() { style = { marginTop = 15 } }; // marginTop not required, only for demonstration purposes.
var tabOne = new Tab("One");
tabOne.Add(new Label("Tab with labels only: This is some content for the first Tab.") { style = { marginTop = 10 } });
csharpTabViewWithLabels.Add(tabOne);
var tabTwo = new Tab("Two");
tabTwo.Add(new Label("Tab with labels only: This is some content for the second Tab.") { style = { marginTop = 10 } });
csharpTabViewWithLabels.Add(tabTwo);
container.Add(csharpTabViewWithLabels);

// Create a TabView with Tabs that only contains an icon.
var csharpTabViewWithIcons = new TabView() { style = { marginTop = 15 } }; // marginTop not required, only for demonstration purposes.
var tabIconConnect = new Tab(EditorGUIUtility.FindTexture("CloudConnect"));
tabIconConnect.Add(new Label("Tab with icons only: This is some content for the first Tab.") { style = { marginTop = 10 } });
csharpTabViewWithIcons.Add(tabIconConnect);
var tabIconStore = new Tab(EditorGUIUtility.FindTexture("Asset Store"));
tabIconStore.Add(new Label("Tab with icons only: This is some content for the second Tab.") { style = { marginTop = 10 } });
csharpTabViewWithIcons.Add(tabIconStore);
container.Add(csharpTabViewWithIcons);

// Create a TabView with Tabs that only contains an icon and a label.
var csharpTabViewWithIconsAndLabels = new TabView() { style = { marginTop = 15 } }; // marginTop not required, only for demonstration purposes.
var tabConnect = new Tab("Connect", EditorGUIUtility.FindTexture("CloudConnect"));
tabConnect.Add(new Label("Tab with an icon and a labels: This is some content for the first Tab.") { style = { marginTop = 10 } });
csharpTabViewWithIconsAndLabels.Add(tabConnect);
var tabStore = new Tab("Store", EditorGUIUtility.FindTexture("Asset Store"));
tabStore.Add(new Label("Tab with an icon and a labels: This is some content for the second Tab.") { style = { marginTop = 10 } });
csharpTabViewWithIconsAndLabels.Add(tabStore);
container.Add(csharpTabViewWithIconsAndLabels);

// Create a TabView that allows re-ordering of the tabs.
var csharpReorderableTabView = new TabView() { reorderable = true, style = { marginTop = 10 } }; // marginTop not required, only for demonstration purposes.
var tabA = new Tab("Tab A");
tabA.Add(new Label("Reorderable tabs: This is some content for Tab A") { style = { marginTop = 10 } });
csharpReorderableTabView.Add(tabA);
var tabB = new Tab("Tab B");
tabB.Add(new Label("Reorderable tabs: This is some content for Tab B") { style = { marginTop = 10 } });
csharpReorderableTabView.Add(tabB);
var tabC = new Tab("Tab C");
tabC.Add(new Label("Reorderable tabs: This is some content for Tab C") { style = { marginTop = 10 } });
csharpReorderableTabView.Add(tabC);
container.Add(csharpReorderableTabView);

// Create a TabView with closeable tabs.
var closeTabInfoLabel = new Label($"Last tab closed: None");
void UpdateLabel(string newLabel) => closeTabInfoLabel.text = $"Last tab closed: {newLabel}";
var cSharpCloseableTabs = new TabView() { style = { marginTop = 10 } }; // marginTop not required, only for demonstration purposes.
var closeableTabA = new Tab("Title A") { closeable = true };
closeableTabA.closed += (tab) => { UpdateLabel(tab.label); };
closeableTabA.Add(new Label("Closeable tabs: This is some content for Tab A") { style = { marginTop = 10 } });
cSharpCloseableTabs.Add(closeableTabA);
var closeableTabB = new Tab("Title B") { closeable = true };
closeableTabB.closed += (tab) => { UpdateLabel(tab.label); };
closeableTabB.Add(new Label("Closeable tabs: This is some content for Tab B") { style = { marginTop = 10 } });
cSharpCloseableTabs.Add(closeableTabB);
var closeableTabC = new Tab("Title C") { closeable = true };
closeableTabC.closed += (tab) => { UpdateLabel(tab.label); };
closeableTabC.Add(new Label("Closeable tabs: This is some content for Tab C") { style = { marginTop = 10 } });
cSharpCloseableTabs.Add(closeableTabC);
container.Add(cSharpCloseableTabs);
container.Add(closeTabInfoLabel);

// Create a TabView and apply custom styling to specific areas of their tabs.
var csharpCustomStyledTabView = new TabView() { style = { marginTop = 15 }, classList = { "some-styled-class" }}; // marginTop not required, only for demonstration purposes.
var customStyledTabOne = new Tab("One");
customStyledTabOne.Add(new Label("Custom styled tabs: This is some content for the first Tab."));
csharpCustomStyledTabView.Add(customStyledTabOne);
var customStyledTabTwo = new Tab("Two");
customStyledTabTwo.Add(new Label("Custom styled tabs: This is some content for the second Tab."));
csharpCustomStyledTabView.Add(customStyledTabTwo);
container.Add(csharpCustomStyledTabView);
/// </sample>

この例を Unity でライブ体験するには、Window > UI Toolkit > Samples の順に移動します。

その他の例は、以下のドキュメントを参照してください。

-タブ付きメニューの作成

C# の基本クラスと名前空間

C# クラス: Tab
名前空間: UnityEngine.UIElements
基本クラス: VisualElement

メンバー UXML 属性

この要素は以下のメンバー属性を持ちます。

名前 説明
closeable boolean タブを閉じられる機能を追加するプロパティ。

デフォルト値は false です。この値を true に設定すると、ユーザーはタブビューでタブを閉じることができます。
icon-image Object タブのヘッダーのアイコンを設定します。
label string タブのヘッダーのラベルを設定します。

継承された UXML 属性

この要素は基本クラスから以下の属性を継承します。

名前 説明
focusable boolean 要素がフォーカス可能である場合は true。
tabindex int フォーカスリング内でフォーカス可能な対象をソートするために使用される整数。0 以上の値に設定する必要があります。

この要素は VisualElement から以下の属性も継承します。

名前 説明
content-container string 子要素はそれに追加されますが、通常は要素自体と同じです。
data-source Object この VisualElement にデータソースを割り当て、継承されたデータソースをオーバーライドします。このデータソースはすべての子に継承されます。
data-source-path string データソースから値へのパス。
data-source-type System.Type この VisualElement に割り当て可能なデータソースのタイプ。

この情報は、設計時に有効なデータソースを指定できない場合に、データソースパスフィールドを補完するヒントとして UI Builder でのみ使用されます。
language-direction UIElements.LanguageDirection 要素のテキストの向きを示します。値は要素の子に伝播されます。

languageDirection を RTL に設定すると、テキストの反転と改行/折り返しの適切な処理による、右から左へ (RTL) の基本サポートが追加されます。ただし、包括的な RTL サポートは提供されません。これには、文字の並べ替えを含むテキストシェーピングと OpenType フォント機能のサポートが必要になるためです。将来のアップデートでは、言語、スクリプト、フォント機能の仕様を処理するための追加の API を含む、包括的な RTL サポートが予定されています。

このプロパティの RTL 機能を拡張するには、Unity Asset Store で入手可能なサードパーティ製のプラグインを探し、ITextElementExperimentalFeatures.renderedText を利用してください。
name string この VisualElement の名前。

このプロパティを使用して、特定の要素を対象とする USS セレクターを記述します。要素には一意の名前を付けるのが標準的です。
picking-mode UIElements.PickingMode mouseEvents または IPanel.Pick クエリの間にこの要素を選択 (ピック) できるかどうかを決定します。
style string VisualElement スタイルの値を設定します。
tooltip string ユーザーが要素をマウスオーバーした後、わずかな時間、情報ボックス内に表示するテキスト。これはエディター UI でのみサポートされます。
usage-hints UIElements.UsageHints VisualElement の高レベルの使用パターンを指定するヒント値の組み合わせ。このプロパティは、VisualElement がまだ Panel の一部でない場合にのみ設定できます。Panel の一部になると、このプロパティは事実上読み取り専用となり、変更しようとすると例外がスローされます。適切な UsageHints を指定することで、予想される使用パターンに基づいて、特定の操作をどのように処理するか、または高速化するかについて、システムがより適切な判断を下すようになります。これらのヒントは動作や視覚的な結果には影響しませんが、パネルとその中の要素の全体的なパフォーマンスにのみ影響することに注意してください。常に適切な UsageHints を指定することを考慮することをお勧めしますが、特定の条件下 (例えば、ターゲットプラットフォームのハードウェア制限など) では、いくつかの UsageHints が内部的に無視される可能性があることに留意してください。
view-data-key string ビューデータの永続性 (ツリーの展開状態、スクロール位置、ズームレベルなど) に使用されます。

このキーは、ビューデータストアからビューデータを保存およびロードするために使用されます。このキーを設定しないと、関連する VisualElement の永続性が無効になります。詳細については、ビューデータの永続化を参照してください。

USS クラス

以下の表は、すべての C# パブリックプロパティ名と、それに関連する USS セレクターのリストです。

C# プロパティ USS セレクター 説明
ussClassName .unity-tab この方の要素の USS クラス名。
tabHeaderUssClassName .unity-tab__header この型のヘッダーの USS クラス名。
tabHeaderImageUssClassName .unity-tab__header-image ヘッダー内のアイコンの USS クラス名。
tabHeaderEmptyImageUssClassName .unity-tab__header-image--empty 値が null の場合の、ヘッダー内のアイコンの USS クラス名。
tabHeaderStandaloneImageUssClassName .unity-tab__header-image--standalone ラベルが空または null の場合の、ヘッダー内のアイコンの USS クラス名。
tabHeaderLabelUssClassName .unity-tab__header-label ヘッダーのラベルの USS クラス名。
tabHeaderEmptyLabeUssClassName .unity-tab__header-label--empty ラベルが空または null の場合の、ヘッダーのラベルの USS クラス名。
tabHeaderUnderlineUssClassName .unity-tab__header-underline ヘッダーのアクティブ状態の下線の USS クラス名。
contentUssClassName .unity-tab__content-container この型のコンテナ要素の USS クラス名。
draggingUssClassName .unity-tab--dragging この型のドラッグ状態の USS クラス名。
reorderableUssClassName .unity-tab__reorderable 並べ替え可能なタブ要素の USS クラス名。
reorderableItemHandleUssClassName .unity-tab__reorderable-handle 並べ替え可能なタブのドラッグハンドルの USS クラス名。
reorderableItemHandleBarUssClassName .unity-tab__reorderable-handle-bar 並べ替え可能なタブのドラッグハンドルバーの USS クラス名。
closeableUssClassName .unity-tab__header__closeable 閉じることができるタブの USS クラス名。
closeButtonUssClassName .unity-tab__close-button 閉じることができるタブの閉じるボタンの USS クラス名。
disabledUssClassName .unity-disabled ローカルで無効にされた要素の USS クラス名。

Inspector または UI Toolkit Debugger の Matching Selectors セクション を使用して、階層のすべてのレベルで VisualElement のコンポーネントに影響する USS セレクターを確認することもできます。

追加リソース

SliderInt
TabView