Tree View Collection
Simple GameObject driven tree view control for uGUI
Like what your seeing?
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!
Introduction
The tree view is a common GUI element that Unity simply lacks and isn't trivial to create from scratch. The Tree View Collection component simplifies this and makes it easy to manage tree views by expressing the data of the collection as GameObjects in your scene hierarchy.
Put more simply, the Tree View Collection will manage a the children of a targeted GameObject creating a Tree View UI element that is easy to create, read and manage.
Tree View Collection
This represents the collection its self and can be treated similar to a Unity uGUI Layout control though doesn't control the layout position rather this will control the parentage of the objects its managing.
To affect the position layout such as to cause child nodes to organize themselves in a vertical layout then you should use Unity's built-in features such as Vertical Layout.
Node Prototype
This is the prefab that should be instantiated to represent your nodes in your game's UI. The prototype should implement the Tree View Node component.
Root
This is the root where the Tree View Collection will create and manage nodes.
Tree View Node
This component represents the visual node as it will appear in your UI. The typical approach is to define this prototype in scene in a disabled GameObject as a template. This is a similar approach to Unity's own DropDown and its Template.
The available fields are
Tree
This should be set to the parent tree. If you use the Template approach as discribed here you can set this at development time. If you do not then you will need to set this value at run time when you instantiate the object.
Parent
This will be set by the Tree View that is controlling this node and managed as the node is moved up and down in the structure.
Content
This is the RectTransform under which the visual representation for the node its self would live e.g. the label, a toggle if you like, etc.
Collection
This is the RectTransform under which child nodes will be placed. When this node is "collapsed" this GameObject is set inactive hiding the children.