-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFmodParameterDropdownAttribute.cs
72 lines (56 loc) · 2.47 KB
/
FmodParameterDropdownAttribute.cs
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
public class FmodParameterDropdownAttribute : Attribute
{
public readonly string EventPathResolver;
public FmodParameterDropdownAttribute(string eventPathResolver)
{
EventPathResolver = eventPathResolver;
}
}
public class FmodParameterDropdownAttributeDrawer : OdinAttributeDrawer<FmodParameterDropdownAttribute, string>
{
private ValueResolver<string> eventPathResolver;
protected override void Initialize()
{
this.eventPathResolver = ValueResolver.Get<string>(this.Property, this.Attribute.EventPathResolver);
}
protected override void DrawPropertyLayout(GUIContent label)
{
if (this.eventPathResolver.HasError) this.eventPathResolver.DrawError();
else
{
GUILayout.BeginHorizontal();
var width = 15f;
if (label != null) width += GUIHelper.BetterLabelWidth;
var results = OdinSelector<string>.DrawSelectorDropdown(label ?? GUIContent.none, GUIContent.none,
CreateSelector, GUIStyle.none, GUILayoutOptions.Width(width));
if (results != null) ValueEntry.SmartValue = results.First();
if (Event.current.type == EventType.Repaint)
{
var position = GUILayoutUtility.GetLastRect().AlignRight(15f);
position.y += 4f;
SirenixGUIStyles.PaneOptions.Draw(position, GUIContent.none, 0);
}
GUILayout.BeginVertical();
CallNextDrawer(null);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
}
private OdinSelector<string> CreateSelector(Rect buttonRect)
{
var eventInstance = FMODUnity.RuntimeManager.CreateInstance(eventPathResolver.GetValue());
eventInstance.getDescription(out var description);
description.getParameterDescriptionCount(out var parameterDescriptionCount);
var parameters = new List<string>();
for (var i = 0; i < parameterDescriptionCount; i++)
{
description.getParameterDescriptionByIndex(i, out var parameterDescription);
parameters.Add(parameterDescription.name);
}
var selector = new GenericSelector<string>(parameters);
buttonRect.xMax = GUIHelper.GetCurrentLayoutRect().xMax;
selector.EnableSingleClickToSelect();
selector.ShowInPopup(buttonRect);
return selector;
}
}