using System.Collections.Generic; using UnityEditor.IMGUI.Controls; using UnityEngine; namespace UnityEditor.AddressableAssets.GUI.Adapters { /// /// An abstract adapter layer over Unity's that allows working with /// while supporting both legacy and generic TreeView APIs. /// Implementors should provide root and row-building logic using the adapter types and override /// capability methods (rename, parenting, multi-select, search) as needed. /// public abstract class TreeViewAdapter : #if UNITY_6000_2_OR_NEWER TreeView #else TreeView #endif { /// /// Initializes a new instance of with the specified tree state. /// /// The adapter-wrapped used to maintain UI state. public TreeViewAdapter(TreeViewStateAdapter state) : base(state) { } /// /// Initializes a new instance of with the specified tree state and header. /// /// The adapter-wrapped used to maintain UI state. /// A multi-column header to display columns in the tree view. public TreeViewAdapter(TreeViewStateAdapter state, MultiColumnHeader multiColumnHeader) : base(state, multiColumnHeader) { } /// /// Determines whether multiple items can be selected simultaneously. /// /// The item being considered for selection. /// True if multi-selection is allowed; otherwise, false. protected virtual bool CanMultiSelect(TreeViewItemAdapter item) { return false; } /// /// Determines whether the given item should be included when a search filter is applied. /// /// The item to test against the search filter. /// The current search string. /// True if the item matches the search criteria; otherwise, false. protected virtual bool DoesItemMatchSearch(TreeViewItemAdapter item, string search) { return false; } /// /// Determines whether the specified item can be renamed. /// /// The item to evaluate for renaming. /// True if the item can be renamed; otherwise, false. protected virtual bool CanRenameAdapter(TreeViewItemAdapter item) { return false; } /// /// Determines whether the specified item can act as a parent to other items. /// /// The item to evaluate as a potential parent. /// True if the item can be a parent; otherwise, false. protected virtual bool CanBeParentAdapter(TreeViewItemAdapter item) { return false; } /// /// Handles the end of a rename operation. /// /// Arguments describing the rename operation and result. protected override void RenameEnded(RenameEndedArgs args) { base.RenameEnded(args); } /// /// Constructs and returns the root item using the adapter type. /// Implementors should create the root and set up its hierarchy. /// /// The root adapter item. protected abstract TreeViewItemAdapter BuildRootAdapter(); /// /// Builds the visible row list from the provided root adapter item. /// This default implementation forwards to the base TreeView's row builder /// and casts items to . /// /// The root adapter item. /// A list of visible adapter rows. protected virtual IList BuildRowsAdapter(TreeViewItemAdapter root) { var results = new List(); foreach (var row in base.BuildRows(root)) { results.Add(row as TreeViewItemAdapter); } return results; } #if UNITY_6000_2_OR_NEWER /// protected override bool CanMultiSelect(TreeViewItem item) { return CanMultiSelect(item as TreeViewItemAdapter); } /// protected override IList> BuildRows(TreeViewItem root) { var rows = BuildRowsAdapter(root as TreeViewItemAdapter); var results = new List>(); foreach (var row in rows) results.Add(row); return results; } /// protected override TreeViewItem BuildRoot() { return BuildRootAdapter(); } /// protected override bool DoesItemMatchSearch(TreeViewItem item, string search) { return DoesItemMatchSearch(item as TreeViewItemAdapter, search); } /// protected override bool CanRename(TreeViewItem item) { return CanRenameAdapter(item as TreeViewItemAdapter); } /// protected override bool CanBeParent(TreeViewItem item) { return CanBeParentAdapter(item as TreeViewItemAdapter); } #else /// protected override bool CanMultiSelect(TreeViewItem item) { return CanMultiSelect(item as TreeViewItemAdapter); } /// protected override IList BuildRows(TreeViewItem root) { var rows = BuildRowsAdapter(root as TreeViewItemAdapter); var results = new List(); foreach (var row in rows) results.Add(row); return results; } /// protected override TreeViewItem BuildRoot() { return BuildRootAdapter(); } /// protected override bool DoesItemMatchSearch(TreeViewItem item, string search) { return DoesItemMatchSearch(item as TreeViewItemAdapter, search); } /// protected override bool CanRename(TreeViewItem item) { return CanRenameAdapter(item as TreeViewItemAdapter); } /// protected override bool CanBeParent(TreeViewItem item) { return CanBeParentAdapter(item as TreeViewItemAdapter); } #endif } }