A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR
2using System;
3using UnityEditor.IMGUI.Controls;
4
5namespace UnityEngine.InputSystem.Editor
6{
7 /// <summary>
8 /// Extension methods for working with tree views.
9 /// </summary>
10 /// <seealso cref="TreeView"/>
11 internal static class TreeViewHelpers
12 {
13 public static TItem TryFindItemInHierarchy<TItem>(this TreeViewItem item)
14 where TItem : TreeViewItem
15 {
16 while (item != null)
17 {
18 if (item is TItem result)
19 return result;
20 item = item.parent;
21 }
22
23 return null;
24 }
25
26 public static bool IsParentOf(this TreeViewItem parent, TreeViewItem child)
27 {
28 if (parent == null)
29 throw new ArgumentNullException(nameof(parent));
30 if (child == null)
31 throw new ArgumentNullException(nameof(child));
32
33 do
34 {
35 child = child.parent;
36 }
37 while (child != null && child != parent);
38 return child != null;
39 }
40
41 public static void ExpandChildren(this TreeView treeView, TreeViewItem item)
42 {
43 if (!item.hasChildren)
44 return;
45
46 foreach (var child in item.children)
47 treeView.SetExpanded(child.id, true);
48 }
49 }
50}
51#endif // UNITY_EDITOR