AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
MixedRealityTeleportEditor.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 UnityEditor;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule
8 {
9  [CustomEditor(typeof(MixedRealityTeleport))]
10  public class MixedRealityTeleportEditor : Editor
11  {
12  private readonly GUIContent verticalRotationLabel = new GUIContent("Vertical Rotation", "Used to check the Horizontal Rotation and the intent of the user to rotate in that direction");
13 
14  private static MixedRealityTeleport mixedRealityTeleport;
15 
16  private static SerializedProperty teleportMakerPrefab;
17  private static SerializedProperty useCustomMappingProperty;
18 
19  private static SerializedProperty stayOnTheFloorProperty;
20  private static SerializedProperty enableTeleportProperty;
21  private static SerializedProperty enableStrafeProperty;
22  private static SerializedProperty strafeAmountProperty;
23  private static SerializedProperty enableRotationProperty;
24  private static SerializedProperty rotationSizeProperty;
25 
26  private static SerializedProperty leftThumbstickXProperty;
27  private static SerializedProperty leftThumbstickYProperty;
28  private static SerializedProperty rightThumbstickXProperty;
29  private static SerializedProperty rightThumbstickYProperty;
30 
31  private static SerializedProperty horizontalStrafeProperty;
32  private static SerializedProperty forwardMovementProperty;
33  private static SerializedProperty horizontalRotationProperty;
34  private static SerializedProperty verticalRotationProperty;
35 
36  private static bool useCustomMapping;
37  private static bool mappingOverride;
38 
39  private void OnEnable()
40  {
41  mixedRealityTeleport = (MixedRealityTeleport)target;
42 
43  teleportMakerPrefab = serializedObject.FindProperty("teleportMarker");
44  useCustomMappingProperty = serializedObject.FindProperty("useCustomMapping");
45 
46  enableTeleportProperty = serializedObject.FindProperty("EnableTeleport");
47  enableStrafeProperty = serializedObject.FindProperty("EnableStrafe");
48  strafeAmountProperty = serializedObject.FindProperty("StrafeAmount");
49  enableRotationProperty = serializedObject.FindProperty("EnableRotation");
50  rotationSizeProperty = serializedObject.FindProperty("RotationSize");
51 
52  stayOnTheFloorProperty = serializedObject.FindProperty("StayOnTheFloor");
53 
54  leftThumbstickXProperty = serializedObject.FindProperty("LeftThumbstickX");
55  leftThumbstickYProperty = serializedObject.FindProperty("LeftThumbstickY");
56  rightThumbstickXProperty = serializedObject.FindProperty("RightThumbstickX");
57  rightThumbstickYProperty = serializedObject.FindProperty("RightThumbstickY");
58 
59  horizontalStrafeProperty = serializedObject.FindProperty("HorizontalStrafe");
60  forwardMovementProperty = serializedObject.FindProperty("ForwardMovement");
61  horizontalRotationProperty = serializedObject.FindProperty("HorizontalRotation");
62  verticalRotationProperty = serializedObject.FindProperty("VerticalRotation");
63 
64 
65  }
66 
67  public override void OnInspectorGUI()
68  {
69  serializedObject.Update();
70 
71  useCustomMapping = useCustomMappingProperty.boolValue;
72 
73  EditorGUILayout.LabelField("Teleport Options", new GUIStyle("Label") { fontStyle = FontStyle.Bold });
74 
75  EditorGUILayout.PropertyField(enableTeleportProperty, new GUIContent("Enable Teleport"));
76  EditorGUILayout.PropertyField(enableStrafeProperty, new GUIContent("Enable Strafe"));
77  EditorGUILayout.PropertyField(strafeAmountProperty, new GUIContent("Strafe Amount"));
78 
79  EditorGUILayout.PropertyField(enableRotationProperty, new GUIContent("Enable Rotation"));
80  EditorGUILayout.PropertyField(rotationSizeProperty, new GUIContent("Rotation Amount"));
81 
82  EditorGUILayout.PropertyField(stayOnTheFloorProperty, new GUIContent("Stay on the floor"));
83 
84  EditorGUILayout.PropertyField(teleportMakerPrefab);
85 
86 
87  EditorGUILayout.LabelField("Teleport Controller Mappings", new GUIStyle("Label") { fontStyle = FontStyle.Bold });
88 
89  // Use custom mappings if users have already edited their axis mappings
90  if (!mappingOverride &&
91  (mixedRealityTeleport.LeftThumbstickX != InputMappingAxisUtility.CONTROLLER_LEFT_STICK_HORIZONTAL && mixedRealityTeleport.LeftThumbstickX != string.Empty ||
92  mixedRealityTeleport.LeftThumbstickY != InputMappingAxisUtility.CONTROLLER_LEFT_STICK_VERTICAL && mixedRealityTeleport.LeftThumbstickY != string.Empty ||
93  mixedRealityTeleport.RightThumbstickX != InputMappingAxisUtility.CONTROLLER_RIGHT_STICK_HORIZONTAL && mixedRealityTeleport.RightThumbstickX != string.Empty ||
94  mixedRealityTeleport.RightThumbstickY != InputMappingAxisUtility.CONTROLLER_RIGHT_STICK_VERTICAL && mixedRealityTeleport.RightThumbstickY != string.Empty))
95  {
96  useCustomMapping = true;
97  }
98 
99  EditorGUI.BeginChangeCheck();
100 
101  useCustomMapping = EditorGUILayout.Toggle("Use Custom Mappings", useCustomMapping);
102 
103  if (EditorGUI.EndChangeCheck())
104  {
105  mappingOverride = !useCustomMapping;
106  }
107 
108  useCustomMappingProperty.boolValue = useCustomMapping;
109 
110  if (useCustomMapping)
111  {
112  EditorGUILayout.PropertyField(leftThumbstickXProperty, new GUIContent("Horizontal Strafe"));
113  EditorGUILayout.PropertyField(leftThumbstickYProperty, new GUIContent("Forward Movement"));
114  EditorGUILayout.PropertyField(rightThumbstickXProperty, new GUIContent("Horizontal Rotation"));
115  EditorGUILayout.PropertyField(rightThumbstickYProperty, new GUIContent(verticalRotationLabel));
116  }
117  else
118  {
119  EditorGUILayout.PropertyField(horizontalStrafeProperty, new GUIContent("Horizontal Strafe"));
120  EditorGUILayout.PropertyField(forwardMovementProperty, new GUIContent("Forward Movement"));
121  EditorGUILayout.PropertyField(horizontalRotationProperty, new GUIContent("Horizontal Rotation"));
122  EditorGUILayout.PropertyField(verticalRotationProperty, new GUIContent("Verizontal Rotation"));
123  }
124 
125  serializedObject.ApplyModifiedProperties();
126  }
127  }
128 }
Script teleports the user to the location being gazed at when Y was pressed on a Gamepad.
Utility class for Unity's Input Manager Mappings. Input from all types should be defined here for use...