SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
9.6 KiB

4 years ago
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEditor;
  4. // ReSharper disable InconsistentNaming
  5. namespace ARLocation
  6. {
  7. /// <summary>
  8. /// Inspector for the ARLocationConfig. This inspector is the main configuration
  9. /// interface for the AR+GPS Location plugin.
  10. /// </summary>
  11. [CustomEditor(typeof(ARLocationConfig))]
  12. public class ARLocationConfigInspector : Editor
  13. {
  14. SerializedProperty p_EarthRadiusInKM;
  15. SerializedProperty p_DistanceFunction;
  16. SerializedProperty p_UseVuforia;
  17. SerializedProperty p_InitialGroundHeightGuess;
  18. SerializedProperty p_VuforiaGroundHitTestDistance;
  19. private SerializedProperty p_MinGroundHeight;
  20. private SerializedProperty p_MaxGroundHeight;
  21. private SerializedProperty p_GroundHeightSmoothingFactor;
  22. DefineSymbolsManager defineSymbolsManager;
  23. const string ARGPS_USE_VUFORIA = "ARGPS_USE_VUFORIA";
  24. const string ARGPS_USE_NATIVE_LOCATION = "ARGPS_USE_NATIVE_LOCATION";
  25. Dictionary<string, string> defineSymbolProps = new Dictionary<string, string> {
  26. {ARGPS_USE_VUFORIA, "UseVuforia"},
  27. {ARGPS_USE_NATIVE_LOCATION, "UseNativeLocationModule"}
  28. };
  29. private void OnEnable()
  30. {
  31. p_EarthRadiusInKM = serializedObject.FindProperty("EarthRadiusInKM");
  32. p_DistanceFunction = serializedObject.FindProperty("DistanceFunction");
  33. p_UseVuforia = serializedObject.FindProperty("UseVuforia");
  34. p_InitialGroundHeightGuess = serializedObject.FindProperty("InitialGroundHeightGuess");
  35. p_VuforiaGroundHitTestDistance = serializedObject.FindProperty("VuforiaGroundHitTestDistance");
  36. p_MinGroundHeight = serializedObject.FindProperty("MinGroundHeight");
  37. p_MaxGroundHeight = serializedObject.FindProperty("MaxGroundHeight");
  38. p_GroundHeightSmoothingFactor = serializedObject.FindProperty("GroundHeightSmoothingFactor");
  39. defineSymbolsManager = new DefineSymbolsManager(new[]
  40. {
  41. BuildTargetGroup.iOS,
  42. BuildTargetGroup.Android
  43. });
  44. }
  45. private void UpdateDefineSymbolsFromPlayerSettings()
  46. {
  47. defineSymbolsManager.UpdateFromBuildSettings();
  48. foreach (var item in defineSymbolProps)
  49. {
  50. if (item.Value == "UseVuforia")
  51. {
  52. #if !UNITY_2019_3_OR_NEWER
  53. #if UNITY_2019_2
  54. var value = defineSymbolsManager.Has(item.Key) && PlayerSettings.vuforiaEnabled;
  55. #else
  56. var value = defineSymbolsManager.Has(item.Key) && PlayerSettings.GetPlatformVuforiaEnabled(BuildTargetGroup.Android) && PlayerSettings.GetPlatformVuforiaEnabled(BuildTargetGroup.iOS);
  57. #endif
  58. UpdateDefineSymbolProp(item.Value, value);
  59. #endif
  60. }
  61. else
  62. {
  63. UpdateDefineSymbolProp(item.Value, defineSymbolsManager.Has(item.Key));
  64. }
  65. }
  66. serializedObject.ApplyModifiedProperties();
  67. }
  68. private void UpdateDefineSymbolProp(string propName, bool value)
  69. {
  70. var prop = serializedObject.FindProperty(propName);
  71. if (prop == null)
  72. {
  73. return;
  74. }
  75. prop.boolValue = value;
  76. }
  77. public override void OnInspectorGUI()
  78. {
  79. serializedObject.Update();
  80. UpdateDefineSymbolsFromPlayerSettings();
  81. defineSymbolsManager.UpdateFromBuildSettings();
  82. EditorGUILayout.HelpBox("AR+GPS Location " + ARLocationConfig.Version, MessageType.None, true);
  83. EditorGUILayout.PropertyField(p_EarthRadiusInKM);
  84. EditorGUILayout.PropertyField(p_DistanceFunction);
  85. EditorGUILayout.PropertyField(p_InitialGroundHeightGuess);
  86. EditorGUILayout.PropertyField(p_MinGroundHeight);
  87. EditorGUILayout.PropertyField(p_MaxGroundHeight);
  88. EditorGUILayout.PropertyField(p_GroundHeightSmoothingFactor);
  89. EditorGUILayout.PropertyField(p_VuforiaGroundHitTestDistance);
  90. EditorGUILayout.PropertyField(p_UseVuforia);
  91. if (p_UseVuforia.boolValue)
  92. {
  93. #if UNITY_2019_3_OR_NEWER
  94. EditorGUILayout.HelpBox("Make sure that Vuforia is instaled in the Package Manager Window. On Android, also make sure that the 'ARCore XR Plugin' is not installed.", MessageType.Info);
  95. #endif
  96. // EditorGUILayout.HelpBox("So that Vuforia works correctly, please enable the 'Track Device Pose' option in the Vuforia configuration, and set the tracking" +
  97. // " mode to 'POSITIONAL'.", MessageType.Warning);
  98. EditorGUILayout.HelpBox(
  99. "Note that the regular sample scenes do not work with Vuforia. You can download a project with Vuforia samples at https://github.com/dmbfm/unity-ar-gps-location-issues/releases/tag/v3.1.1", MessageType.Warning);
  100. }
  101. if (GUILayout.Button("Compare Distance Functions (Check console output)"))
  102. {
  103. DistanceFunctionsTest();
  104. }
  105. if (GUILayout.Button("Open Documentation"))
  106. {
  107. Application.OpenURL("https://docs.unity-ar-gps-location.com");
  108. }
  109. var config = (ARLocationConfig)target;
  110. UpdateDefineSymbolPropConfig(config.UseVuforia, p_UseVuforia.boolValue, ARGPS_USE_VUFORIA);
  111. UpdateVuforiaPlayerSettings(config.UseVuforia, p_UseVuforia.boolValue);
  112. serializedObject.ApplyModifiedProperties();
  113. }
  114. private void UpdateVuforiaPlayerSettings(bool oldValue, bool newValue)
  115. {
  116. if (newValue == oldValue)
  117. {
  118. return;
  119. }
  120. #if !UNITY_2019_3_OR_NEWER
  121. #if UNITY_2019_2
  122. if (newValue)
  123. {
  124. PlayerSettings.vuforiaEnabled = true;
  125. }
  126. else
  127. {
  128. PlayerSettings.vuforiaEnabled = false;
  129. }
  130. #else
  131. if (newValue)
  132. {
  133. PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.Android, true);
  134. PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.iOS, true);
  135. }
  136. else
  137. {
  138. PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.Android, false);
  139. PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.iOS, false);
  140. }
  141. #endif
  142. #endif
  143. }
  144. private void UpdateDefineSymbolPropConfig(bool oldValue, bool newValue, string symbol)
  145. {
  146. if (newValue == oldValue) return;
  147. if (newValue)
  148. {
  149. defineSymbolsManager.Add(symbol);
  150. }
  151. else
  152. {
  153. defineSymbolsManager.Remove(symbol);
  154. }
  155. defineSymbolsManager.ApplyToBuildSettings();
  156. }
  157. private void DistanceFunctionsTest()
  158. {
  159. var l1 = new Location(-23.591636, -46.661714);
  160. var l2 = new Location(-23.591661, -46.661695);
  161. var refValue = 3.380432468;
  162. var distHaversine = Location.HaversineDistance(l1, l2);
  163. var distSpherical = Location.PlaneSphericalDistance(l1, l2);
  164. var distFCC = Location.PlaneEllipsoidalFccDistance(l1, l2);
  165. Debug.Log("Comparing short distance calculations...");
  166. Debug.Log("Location 1 = " + l1 + " Location 2 = " + l2);
  167. Debug.Log("Reference distance = " + refValue);
  168. Debug.Log("Haversine distance = " + distHaversine + " (Delta = " + System.Math.Abs(refValue - distHaversine) + ")");
  169. Debug.Log("Plane Spehrical distance = " + distSpherical + " (Delta = " + System.Math.Abs(refValue - distSpherical) + ")");
  170. Debug.Log("Plane Ellipsoidal FCC distance = " + distFCC + " (Delta = " + System.Math.Abs(refValue - distFCC) + ")");
  171. l2 = new Location(-23.593587, -46.660772);
  172. refValue = 236.504492294;
  173. distHaversine = Location.HaversineDistance(l1, l2);
  174. distSpherical = Location.PlaneSphericalDistance(l1, l2);
  175. distFCC = Location.PlaneEllipsoidalFccDistance(l1, l2);
  176. Debug.Log("Comparing mid distance calculations...");
  177. Debug.Log("Location 1 = " + l1 + " Location 2 = " + l2);
  178. Debug.Log("Reference distance = " + refValue);
  179. Debug.Log("Haversine distance = " + distHaversine + " (Delta = " + System.Math.Abs(refValue - distHaversine) + ")");
  180. Debug.Log("Plane Spehrical distance = " + distSpherical + " (Delta = " + System.Math.Abs(refValue - distSpherical) + ")");
  181. Debug.Log("Plane Ellipsoidal FCC distance = " + distFCC + " (Delta = " + System.Math.Abs(refValue - distFCC) + ")");
  182. l2 = new Location(-23.606148, -46.653571);
  183. refValue = 1809.410855428;
  184. distHaversine = Location.HaversineDistance(l1, l2);
  185. distSpherical = Location.PlaneSphericalDistance(l1, l2);
  186. distFCC = Location.PlaneEllipsoidalFccDistance(l1, l2);
  187. Debug.Log("Comparing long distance calculations...");
  188. Debug.Log("Location 1 = " + l1 + " Location 2 = " + l2);
  189. Debug.Log("Reference distance = " + refValue);
  190. Debug.Log("Haversine distance = " + distHaversine + " (Delta = " + System.Math.Abs(refValue - distHaversine) + ")");
  191. Debug.Log("Plane Spehrical distance = " + distSpherical + " (Delta = " + System.Math.Abs(refValue - distSpherical) + ")");
  192. Debug.Log("Plane Ellipsoidal FCC distance = " + distFCC + " (Delta = " + System.Math.Abs(refValue - distFCC) + ")");
  193. }
  194. }
  195. }