AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
ARLocationConfigInspector.cs
1 using System.Collections.Generic;
2 using UnityEngine;
3 using UnityEditor;
4 // ReSharper disable InconsistentNaming
5 
6 namespace ARLocation
7 {
8 
13  [CustomEditor(typeof(ARLocationConfig))]
14  public class ARLocationConfigInspector : Editor
15  {
16 
17  SerializedProperty p_EarthRadiusInKM;
18  SerializedProperty p_EarthEquatorialRadius;
19  SerializedProperty p_EarthFirstEccentricitySquared;
20  SerializedProperty p_UseVuforia;
21  SerializedProperty p_UseCustomGeoCalculator;
22  SerializedProperty p_InitialGroundHeightGuess;
23  SerializedProperty p_VuforiaGroundHitTestDistance;
24  private SerializedProperty p_MinGroundHeight;
25  private SerializedProperty p_MaxGroundHeight;
26  private SerializedProperty p_GroundHeightSmoothingFactor;
27 
28  DefineSymbolsManager defineSymbolsManager;
29 
30  const string ARGPS_USE_VUFORIA = "ARGPS_USE_VUFORIA";
31  const string ARGPS_USE_NATIVE_LOCATION = "ARGPS_USE_NATIVE_LOCATION";
32  const string ARGPS_USE_CUSTOM_GEO_CALC = "ARGPS_USE_CUSTOM_GEO_CALC";
33 
34  Dictionary<string, string> defineSymbolProps = new Dictionary<string, string> {
35  {ARGPS_USE_VUFORIA, "UseVuforia"},
36  {ARGPS_USE_NATIVE_LOCATION, "UseNativeLocationModule"}
37  };
38 
39  private void OnEnable()
40  {
41  p_EarthRadiusInKM = serializedObject.FindProperty("EarthMeanRadiusInKM");
42  p_EarthEquatorialRadius = serializedObject.FindProperty("EarthEquatorialRadiusInKM");
43  p_EarthFirstEccentricitySquared = serializedObject.FindProperty("EarthFirstEccentricitySquared");
44  p_UseVuforia = serializedObject.FindProperty("UseVuforia");
45  p_UseCustomGeoCalculator = serializedObject.FindProperty("UseCustomGeoCalculator");
46  p_InitialGroundHeightGuess = serializedObject.FindProperty("InitialGroundHeightGuess");
47  p_VuforiaGroundHitTestDistance = serializedObject.FindProperty("VuforiaGroundHitTestDistance");
48  p_MinGroundHeight = serializedObject.FindProperty("MinGroundHeight");
49  p_MaxGroundHeight = serializedObject.FindProperty("MaxGroundHeight");
50  p_GroundHeightSmoothingFactor = serializedObject.FindProperty("GroundHeightSmoothingFactor");
51 
52  defineSymbolsManager = new DefineSymbolsManager(new[]
53  {
54  BuildTargetGroup.iOS,
55  BuildTargetGroup.Android
56  });
57  }
58 
59  private void UpdateDefineSymbolsFromPlayerSettings()
60  {
61  defineSymbolsManager.UpdateFromBuildSettings();
62 
63  foreach (var item in defineSymbolProps)
64  {
65  if (item.Value == "UseVuforia")
66  {
67 #if !UNITY_2019_3_OR_NEWER
68 #if UNITY_2019_2
69  var value = defineSymbolsManager.Has(item.Key) && PlayerSettings.vuforiaEnabled;
70 #else
71  var value = defineSymbolsManager.Has(item.Key) && PlayerSettings.GetPlatformVuforiaEnabled(BuildTargetGroup.Android) && PlayerSettings.GetPlatformVuforiaEnabled(BuildTargetGroup.iOS);
72 #endif
73  UpdateDefineSymbolProp(item.Value, value);
74 #endif
75  }
76  else
77  {
78  UpdateDefineSymbolProp(item.Value, defineSymbolsManager.Has(item.Key));
79  }
80  }
81 
82  serializedObject.ApplyModifiedProperties();
83  }
84 
85  private void UpdateDefineSymbolProp(string propName, bool value)
86  {
87  var prop = serializedObject.FindProperty(propName);
88 
89  if (prop == null)
90  {
91  return;
92  }
93 
94  prop.boolValue = value;
95  }
96 
97 
98  public override void OnInspectorGUI()
99  {
100  serializedObject.Update();
101 
102  UpdateDefineSymbolsFromPlayerSettings();
103 
104  defineSymbolsManager.UpdateFromBuildSettings();
105 
106 
107  EditorGUILayout.HelpBox("AR+GPS Location " + ARLocationConfig.Version, MessageType.None, true);
108  EditorGUILayout.PropertyField(p_EarthRadiusInKM);
109  EditorGUILayout.PropertyField(p_EarthEquatorialRadius);
110  EditorGUILayout.PropertyField(p_EarthFirstEccentricitySquared);
111  EditorGUILayout.PropertyField(p_InitialGroundHeightGuess);
112  EditorGUILayout.PropertyField(p_MinGroundHeight);
113  EditorGUILayout.PropertyField(p_MaxGroundHeight);
114  EditorGUILayout.PropertyField(p_GroundHeightSmoothingFactor);
115  EditorGUILayout.PropertyField(p_VuforiaGroundHitTestDistance);
116  EditorGUILayout.PropertyField(p_UseVuforia);
117  EditorGUILayout.PropertyField(p_UseCustomGeoCalculator);
118 
119 
120  if (p_UseVuforia.boolValue)
121  {
122 #if UNITY_2019_3_OR_NEWER
123  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);
124 #endif
125  // EditorGUILayout.HelpBox("So that Vuforia works correctly, please enable the 'Track Device Pose' option in the Vuforia configuration, and set the tracking" +
126  // " mode to 'POSITIONAL'.", MessageType.Warning);
127  EditorGUILayout.HelpBox(
128  "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);
129  }
130 
131 
132  if (GUILayout.Button("Open Documentation"))
133  {
134  Application.OpenURL("https://docs.unity-ar-gps-location.com");
135  }
136 
137  var config = (ARLocationConfig)target;
138 
139  UpdateDefineSymbolPropConfig(config.UseVuforia, p_UseVuforia.boolValue, ARGPS_USE_VUFORIA);
140 
141  UpdateVuforiaPlayerSettings(config.UseVuforia, p_UseVuforia.boolValue);
142 
143  UpdateDefineSymbolPropConfig(config.UseCustomGeoCalculator, p_UseCustomGeoCalculator.boolValue, ARGPS_USE_CUSTOM_GEO_CALC);
144 
145  serializedObject.ApplyModifiedProperties();
146  }
147 
148  private void UpdateVuforiaPlayerSettings(bool oldValue, bool newValue)
149  {
150  if (newValue == oldValue)
151  {
152  return;
153  }
154 
155 #if !UNITY_2019_3_OR_NEWER
156 #if UNITY_2019_2
157  if (newValue)
158  {
159  PlayerSettings.vuforiaEnabled = true;
160  }
161  else
162  {
163  PlayerSettings.vuforiaEnabled = false;
164  }
165 #else
166  if (newValue)
167  {
168  PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.Android, true);
169  PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.iOS, true);
170  }
171  else
172  {
173  PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.Android, false);
174  PlayerSettings.SetPlatformVuforiaEnabled(BuildTargetGroup.iOS, false);
175  }
176 #endif
177 #endif
178 
179  }
180 
181  private void UpdateDefineSymbolPropConfig(bool oldValue, bool newValue, string symbol)
182  {
183  if (newValue == oldValue) return;
184 
185  if (newValue)
186  {
187  defineSymbolsManager.Add(symbol);
188  }
189  else
190  {
191  defineSymbolsManager.Remove(symbol);
192  }
193 
194  defineSymbolsManager.ApplyToBuildSettings();
195  }
196  }
197 }
DefineSymbolsManager
Utility class that manages Define Symbols for a given set of build targets.
Definition: DefineSymbolsManager.cs:8
ARLocation.ARLocationConfigInspector
Inspector for the ARLocationConfig. This inspector is the main configuration interface for the AR+GPS...
Definition: ARLocationConfigInspector.cs:15
ARLocation.ARLocationConfig
This scriptable object holds the global configuration data for the AR + GPS Location plugin.
Definition: ARLocationConfig.cs:12
ARLocation
Definition: ARLocationConfigInspector.cs:7