Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


TreeView

The TreeView is an IMGUI control that lets you create tree views, list views and multi-column tables for Editor tools.
Read time 9 minutesLast updated 6 days ago

Definition

Warning
Removed. TreeView is now deprecated. You can likely now use TreeView\<int\> instead and not think more about it. But if you were using that identifier to store InstanceID data, you should instead opt to upgrade your TreeViews to use TreeView\<InstanceID\> to get the proper typing.
public abstract class TreeView : TreeViewInternal

Remarks

It is customizable with regards to row content rendering, dragging logic, selection logic, searching, sorting and renaming of items. To ensure consistency between TreeViews the following features are not customizable: Foldout arrow rendering, selection rendering, drag markers rendering.
A good place to start is TreeView.BuildRoot.

Constructors

Constructor

Description

TreeView(UnityEditor.IMGUI.Controls.TreeViewState)The TreeView is always constructed with a state object and optionally a multi-column header object if a header is needed.
TreeView(UnityEditor.IMGUI.Controls.TreeViewState,UnityEditor.IMGUI.Controls.MultiColumnHeader)The TreeView is always constructed with a state object and optionally a multi-column header object if a header is needed.

Properties

Property

Description

getNewSelectionOverrideRegister a callback to this field to override how the TreeView handles selection changes in response to keys and mouse clicks.
hoveredItemUse this property to detect which TreeViewItem the mouse cursor is currently hovering over in the TreeView. This property is only valid if the enableItemHovering property has been set to true.
rootItemThe hidden root item of the TreeView (it is never rendered).
stateThe state of the TreeView (expanded state, selection, scroll etc.)

Methods

Method

Description

AddExpandedRowsAdds the expanded rows of the full tree to the input list. Only use this method if a full tree was built in BuildRoot.
BeginRenameShows the rename overlay for a TreeViewItem.
BuildRootAbstract method that is required to be implemented. By default this method should create the full tree of TreeViewItems and return the root.
BuildRowsOverride this method to take control of how the rows are generated.
CanBeParentOverride this method to control which items are allowed to be parents.
CanChangeExpandedStateOverride this method to control whether an item can be expanded or collapsed by key or mouse.
CanMultiSelectOverride this method to control whether the item can be part of a multiselection.
CanRenameOverride this method to control whether the item can be renamed using a keyboard shortcut or when clicking an already selected item.
CanStartDragThis function is called whenever a TreeViewItem is clicked and dragged. It returns false by default.
DoesItemMatchSearchOverride this function to extend or change the search behavior.
FindItemFinds a TreeViewItem by an ID.
FindRowOfItemReturns the row of the given TreeViewItem.
FindRowsUseful for converting from TreeViewItem IDs to TreeViewItems using the current rows.
GetContentIndentReturns the horizontal content offset for an item. This is where the content should begin (after the foldout arrow).
GetCustomRowHeightOverride to control individual row heights.
GetFoldoutIndentReturns the horizontal foldout offset for an item. This is where the foldout arrow is rendered.
GetRenameRectOverride this method if custom GUI handling are used in TreeView.RowGUI. This method for controls where the rename overlay appears.
GetRowsThis is the list of TreeViewItems that have been built in TreeView.BuildRows.
HandleDragAndDropOverride this function to control the drag and drop behavior of the TreeView.
RowGUIOverride this method to add custom GUI content for the rows in the TreeView.
SelectionClickUse this method in TreeView.RowGUI to peform the logic of a mouse click.

Static Methods

Method

Description

CreateChildListForCollapsedParentCreates a dummy TreeViewItem list. Useful when overriding TreeView.BuildRows to prevent building a full tree of items.
IsChildListForACollapsedParentUtility method for checking if the
childList
is identical to the one returned by the TreeView.CreateChildListForCollapsedParent method.
SetupDepthsFromParentsAndChildrenUtility method using the depth of the input TreeViewItem to set the correct depths for all its descendant TreeViewItems.
SetupParentsAndChildrenFromDepthsUtility method for initializing all the parent and children properties of the rows using the order and the depths values that have been set.

Structs

Struct

Description

TreeView.CanStartDragArgsMethod arguments for the TreeView.CanStartDrag virtual method.
TreeView.DragAndDropArgsMethod arguments for the TreeView.HandleDragAndDrop virtual method.
TreeView.RowGUIArgsMethod arguments for the virtual method TreeView.RowGUI.

Delegates

Delegate

Description

TreeView.GetNewSelectionFunctionA callback which determines how TreeView handles selection changes in response to keys and mouse clicks.

Inheritance

Inherited Members