Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MultiLevelDataSource.cs 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #if UNITY_EDITOR
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace UnityEngine.InputSystem.Editor
  5. {
  6. internal class MultiLevelDataSource : AdvancedDropdownDataSource
  7. {
  8. private string[] m_DisplayedOptions;
  9. internal string[] displayedOptions
  10. {
  11. set { m_DisplayedOptions = value; }
  12. }
  13. private string m_Label = "";
  14. internal string label
  15. {
  16. set { m_Label = value; }
  17. }
  18. internal MultiLevelDataSource()
  19. {
  20. }
  21. public MultiLevelDataSource(string[] displayOptions)
  22. {
  23. m_DisplayedOptions = displayOptions;
  24. }
  25. protected override AdvancedDropdownItem FetchData()
  26. {
  27. var rootGroup = new AdvancedDropdownItem(m_Label);
  28. m_SearchableElements = new List<AdvancedDropdownItem>();
  29. for (int i = 0; i < m_DisplayedOptions.Length; i++)
  30. {
  31. var menuPath = m_DisplayedOptions[i];
  32. var paths = menuPath.Split('/');
  33. AdvancedDropdownItem parent = rootGroup;
  34. for (var j = 0; j < paths.Length; j++)
  35. {
  36. var path = paths[j];
  37. if (j == paths.Length - 1)
  38. {
  39. var element = new MultiLevelItem(path, menuPath);
  40. element.elementIndex = i;
  41. parent.AddChild(element);
  42. m_SearchableElements.Add(element);
  43. continue;
  44. }
  45. var groupPathId = paths[0];
  46. for (int k = 1; k <= j; k++)
  47. groupPathId += "/" + paths[k];
  48. var group = parent.children.SingleOrDefault(c => ((MultiLevelItem)c).stringId == groupPathId);
  49. if (group == null)
  50. {
  51. group = new MultiLevelItem(path, groupPathId);
  52. parent.AddChild(group);
  53. }
  54. parent = group;
  55. }
  56. }
  57. return rootGroup;
  58. }
  59. class MultiLevelItem : AdvancedDropdownItem
  60. {
  61. internal string stringId;
  62. public MultiLevelItem(string path, string menuPath) : base(path)
  63. {
  64. stringId = menuPath;
  65. id = menuPath.GetHashCode();
  66. }
  67. public override string ToString()
  68. {
  69. return stringId;
  70. }
  71. }
  72. }
  73. }
  74. #endif // UNITY_EDITOR