WorldTrackerEditor.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditor.SceneManagement;
  6. namespace Imagine.WebAR.Editor
  7. {
  8. [CustomEditor(typeof(WorldTracker))]
  9. public class WorldTrackerEditor : UnityEditor.Editor
  10. {
  11. WorldTracker _target;
  12. bool showKeyboardCameraControls = false;
  13. private void OnEnable()
  14. {
  15. _target = (WorldTracker)target;
  16. }
  17. public override void OnInspectorGUI()
  18. {
  19. //base.OnInspectorGUI();
  20. var trackerCamProp = serializedObject.FindProperty("trackerCamera");
  21. EditorGUILayout.PropertyField(trackerCamProp);
  22. var modeProp = serializedObject.FindProperty("mode");
  23. EditorGUILayout.PropertyField(modeProp);
  24. if (_target.mode == WorldTracker.TrackingMode.MODE_3DOF)
  25. {
  26. EditorGUI.indentLevel++;
  27. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  28. ;
  29. var rssProp = serializedObject.FindProperty("s3dof");
  30. //rssProp.isExpanded = true;
  31. EditorGUILayout.PropertyField(rssProp, new GUIContent("3DOF Settings"));
  32. EditorGUILayout.EndHorizontal();
  33. EditorGUI.indentLevel--;
  34. }
  35. else if (_target.mode == WorldTracker.TrackingMode.MODE_3DOF_ORBIT)
  36. {
  37. EditorGUI.indentLevel++;
  38. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  39. ;
  40. var rssProp = serializedObject.FindProperty("s3dof_orbit");
  41. //rssProp.isExpanded = true;
  42. EditorGUILayout.PropertyField(rssProp, new GUIContent("3DOF Orbit Settings"));
  43. EditorGUILayout.EndHorizontal();
  44. EditorGUI.indentLevel--;
  45. }
  46. else if (_target.mode == WorldTracker.TrackingMode.MODE_6DOF)
  47. {
  48. EditorGUI.indentLevel++;
  49. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  50. ;
  51. var ttsProp = serializedObject.FindProperty("s6dof");
  52. //ttsProp.isExpanded = true;
  53. EditorGUILayout.PropertyField(ttsProp, new GUIContent("6DOF Settings"));
  54. EditorGUILayout.EndHorizontal();
  55. EditorGUI.indentLevel--;
  56. }
  57. var planeModeProp = serializedObject.FindProperty("planeMode");
  58. EditorGUILayout.PropertyField(planeModeProp);
  59. EditorGUILayout.Space(20);
  60. EditorGUILayout.PropertyField(serializedObject.FindProperty("mainObject"));
  61. EditorGUILayout.PropertyField(serializedObject.FindProperty("cameraStartHeight"));
  62. var useCompassProp = serializedObject.FindProperty("useCompass");
  63. EditorGUILayout.PropertyField(useCompassProp, new GUIContent("Use Compass (Experimental)"));
  64. if(useCompassProp.boolValue){
  65. EditorGUILayout.HelpBox("Note: Experimental compass feature has not been widely tested on all mobile browsers.\nSome browsers need up to 20 seconds to properly initialize the compass", MessageType.Warning);
  66. if(modeProp.intValue == (int)WorldTracker.TrackingMode.MODE_6DOF){
  67. EditorGUILayout.HelpBox("UseCompass does not have an effect in 6DOF mode", MessageType.Warning);
  68. }
  69. }
  70. EditorGUILayout.Space(20);
  71. var usePlacementIndicatorProp = serializedObject.FindProperty("usePlacementIndicator");
  72. EditorGUILayout.PropertyField(usePlacementIndicatorProp);
  73. if(usePlacementIndicatorProp.boolValue){
  74. EditorGUI.indentLevel++;
  75. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  76. ;
  77. var psProp = serializedObject.FindProperty("placementIndicatorSettings");
  78. //psProp.isExpanded = true;
  79. EditorGUILayout.PropertyField(psProp, new GUIContent("Placement Indicator Settings"));
  80. EditorGUILayout.EndVertical();
  81. EditorGUI.indentLevel--;
  82. }
  83. else{
  84. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  85. EditorGUILayout.LabelField("Your main object will auto-placed");
  86. EditorGUILayout.EndVertical();
  87. }
  88. EditorGUILayout.Space(20);
  89. var esProp = serializedObject.FindProperty("eventSettings");
  90. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  91. EditorGUI.indentLevel++;
  92. EditorGUILayout.PropertyField(esProp, new GUIContent("Event Settings"));
  93. EditorGUI.indentLevel--;
  94. EditorGUILayout.EndVertical();
  95. EditorGUILayout.Space(20);
  96. EditorGUI.BeginChangeCheck();
  97. var useGeoLocationProp = serializedObject.FindProperty("useGeolocation");
  98. EditorGUILayout.PropertyField(useGeoLocationProp, new GUIContent("Use Geolocation (Experimental)"));
  99. if(useGeoLocationProp.boolValue){
  100. if(!useCompassProp.boolValue){
  101. EditorGUILayout.HelpBox("It is recommended to enable UseCompass with UseGeolocation", MessageType.Warning);
  102. }
  103. if(modeProp.intValue == (int)WorldTracker.TrackingMode.MODE_6DOF){
  104. EditorGUILayout.HelpBox("Geolocation does not work properly in 6DOF mode. Use 3DOF instead!", MessageType.Warning);
  105. }
  106. EditorGUI.indentLevel++;
  107. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  108. var gsProp = serializedObject.FindProperty("geolocationSettings");
  109. //psProp.isExpanded = true;
  110. EditorGUILayout.PropertyField(gsProp, new GUIContent("Geolocation Settings"));
  111. EditorGUILayout.EndVertical();
  112. EditorGUI.indentLevel--;
  113. }
  114. if(EditorGUI.EndChangeCheck()){
  115. //add remove geolocationScenes
  116. var scenePath = EditorSceneManager.GetActiveScene().path;
  117. var geolocationScenes = WorldTrackerGlobalSettings.Instance.geolocationScenes;
  118. if(useGeoLocationProp.boolValue){
  119. //add
  120. if(!geolocationScenes.Contains(scenePath))
  121. geolocationScenes.Add(scenePath);
  122. }
  123. else{
  124. if(geolocationScenes.Contains(scenePath))
  125. geolocationScenes.Remove(scenePath);
  126. }
  127. EditorUtility.SetDirty(WorldTrackerGlobalSettings.Instance);
  128. }
  129. EditorGUILayout.Space();
  130. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  131. EditorGUILayout.PropertyField(serializedObject.FindProperty("debugStartLat"));
  132. EditorGUILayout.PropertyField(serializedObject.FindProperty("debugStartLon"));
  133. EditorGUILayout.EndVertical();
  134. EditorGUILayout.Space();
  135. //keyboard camera controls
  136. showKeyboardCameraControls = EditorGUILayout.Toggle ("Show Keyboard Camera Controls", showKeyboardCameraControls);
  137. if(showKeyboardCameraControls){
  138. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  139. EditorGUILayout.LabelField("W", "Move Forward (Z)");
  140. EditorGUILayout.LabelField("S", "Move Backward (Z)");
  141. EditorGUILayout.LabelField("A", "Move Left (X)");
  142. EditorGUILayout.LabelField("D", "Move Right (X)");
  143. EditorGUILayout.LabelField("R", "Move Up (Y)");
  144. EditorGUILayout.LabelField("F", "Move Down (Y)");
  145. EditorGUILayout.Space();
  146. EditorGUILayout.LabelField("Up Arrow", "Tilt Up (along X-Axis)");
  147. EditorGUILayout.LabelField("Down Arrow", "Tilt Down (along X-Axis)");
  148. EditorGUILayout.LabelField("Left Arrow", "Tilt Left (along Y-Axis)");
  149. EditorGUILayout.LabelField("Right Arrow", "Tilt Right (Along Y-Axis)");
  150. EditorGUILayout.LabelField("Period", "Tilt Clockwise (Along Z-Axis)");
  151. EditorGUILayout.LabelField("Comma", "Tilt Counter Clockwise (Along Z-Axis)");
  152. EditorGUILayout.Space(40);
  153. EditorGUILayout.PropertyField(serializedObject.FindProperty("debugCamMoveSensitivity"));
  154. EditorGUILayout.PropertyField(serializedObject.FindProperty("debugCamTiltSensitivity"));
  155. EditorGUILayout.EndVertical();
  156. }
  157. serializedObject.ApplyModifiedProperties();
  158. }
  159. void OnSceneGUI(){
  160. if(serializedObject.FindProperty("useGeolocation").boolValue){
  161. var radius = serializedObject.FindProperty("geolocationSettings").FindPropertyRelative("activationRadius").floatValue;
  162. Handles.color = new Color(1,1,0,0.05f);
  163. Handles.DrawSolidDisc(Vector3.zero, Vector3.up, radius);
  164. }
  165. }
  166. }
  167. }