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