11using System.Reflection;
12using System.Collections.Generic;
31 [AttributeUsage(AttributeTargets.Method, AllowMultiple =
false)]
42 private static List<LeapPreferenceItem> _leapPreferenceItems =
null;
44 private struct LeapPreferenceItem {
45 public Action drawPreferenceGui;
49 private static void ensurePreferenceItemsLoaded() {
50 if (_leapPreferenceItems !=
null) {
54 _leapPreferenceItems =
new List<LeapPreferenceItem>();
56 var assemblies = AppDomain.CurrentDomain.GetAssemblies();
57 foreach (var type
in assemblies.SelectMany(a => a.GetTypes())) {
58 foreach (var method
in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)) {
59 var attributes = method.GetCustomAttributes(typeof(
LeapPreferences), inherit:
true);
60 if (attributes.Length == 0) {
65 _leapPreferenceItems.Add(
new LeapPreferenceItem() {
66 drawPreferenceGui = () => {
67 EditorGUILayout.LabelField(attribute.header, EditorStyles.boldLabel);
68 using (
new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
69 method.Invoke(
null,
null);
71 EditorGUILayout.Space();
72 EditorGUILayout.Space();
73 EditorGUILayout.Space();
80 _leapPreferenceItems.Sort((a, b) => a.attribute.order.CompareTo(b.attribute.order));
83 #if UNITY_2018_3_OR_NEWER
85 private class LeapMotionSettingsProvider : SettingsProvider {
86 public LeapMotionSettingsProvider(
string path, SettingsScope scopes = SettingsScope.User)
90 public override void OnGUI(
string searchContext) {
96 static SettingsProvider GetSettingsProvider()
98 return new LeapMotionSettingsProvider(
"Preferences/Leap Motion");
101 [PreferenceItem(
"Leap Motion")]
103 public static void DrawPreferencesGUI() {
104 ensurePreferenceItemsLoaded();
106 foreach (var item
in _leapPreferenceItems) {
107 item.drawPreferenceGui();
This attribute is used to add items to the Leap Motion preferences window. This allows each module to...
LeapPreferences(string header, int order)