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