Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TreeViewHelpers.cs 1.4KB

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