AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
XboxControllerInputSourceEditor.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEditor;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity.InputModule
9 {
10  [CustomEditor(typeof(XboxControllerInputSource))]
11  public class XboxControllerInputSourceEditor : Editor
12  {
13  private SerializedProperty horizontalAxisProperty;
14  private SerializedProperty verticalAxisProperty;
15  private SerializedProperty submitButtonProperty;
16  private SerializedProperty cancelButtonProperty;
17  private SerializedProperty customMappingsProperty;
18 
19  private static bool useCustomMapping;
20 
21  private void OnEnable()
22  {
23  horizontalAxisProperty = serializedObject.FindProperty("horizontalAxis");
24  verticalAxisProperty = serializedObject.FindProperty("verticalAxis");
25  submitButtonProperty = serializedObject.FindProperty("submitButton");
26  cancelButtonProperty = serializedObject.FindProperty("cancelButton");
27  customMappingsProperty = serializedObject.FindProperty("mapping");
28  }
29 
30  public override void OnInspectorGUI()
31  {
32  serializedObject.Update();
33  EditorGUILayout.Space();
34 
35  EditorGUILayout.LabelField("Event System Overrides", new GUIStyle("Label") { fontStyle = FontStyle.Bold });
36 
37  EditorGUI.indentLevel++;
38 
39  EditorGUILayout.PropertyField(horizontalAxisProperty);
40  EditorGUILayout.PropertyField(verticalAxisProperty);
41  EditorGUILayout.PropertyField(submitButtonProperty);
42  EditorGUILayout.PropertyField(cancelButtonProperty);
43 
44  EditorGUI.indentLevel--;
45  EditorGUILayout.Space();
46 
47  EditorGUI.BeginChangeCheck();
48 
49  useCustomMapping = EditorGUILayout.Toggle("Use Custom Mapping", useCustomMapping);
50 
51  if (EditorGUI.EndChangeCheck())
52  {
53  customMappingsProperty.arraySize = Enum.GetNames(typeof(XboxControllerMappingTypes)).Length;
54 
55  for (int i = 0; i < customMappingsProperty.arraySize; i++)
56  {
57  customMappingsProperty.GetArrayElementAtIndex(i).FindPropertyRelative("Type").enumValueIndex = i;
58  customMappingsProperty.GetArrayElementAtIndex(i).FindPropertyRelative("Value").stringValue = string.Empty;
59  }
60  }
61 
62  if (useCustomMapping)
63  {
64  ShowList(customMappingsProperty);
65  }
66 
67  serializedObject.ApplyModifiedProperties();
68  }
69 
70  private static void ShowList(SerializedProperty list)
71  {
72  EditorGUILayout.Space();
73 
74  list.isExpanded = true;
75  EditorGUI.indentLevel++;
76 
77  for (int i = 0; i < list.arraySize; i++)
78  {
79  EditorGUILayout.BeginHorizontal();
80  list.GetArrayElementAtIndex(i).FindPropertyRelative("Type").enumValueIndex = i;
81  EditorGUILayout.LabelField(((XboxControllerMappingTypes)i).ToString());
82  list.GetArrayElementAtIndex(i).FindPropertyRelative("Value").stringValue =
83  EditorGUILayout.TextField(list.GetArrayElementAtIndex(i).FindPropertyRelative("Value").stringValue);
84  EditorGUILayout.EndHorizontal();
85  }
86 
87  EditorGUI.indentLevel--;
88  }
89  }
90 }
XboxControllerMappingTypes
Xbox Controller axis and button types.