Skip to content

Commit cdac0a7

Browse files
authored
Merge pull request #1138 from leapmotion/feat-screentop
[RELEASE] UnityModules 4.7.1 - ScreenTop Compatibility
2 parents 37b0364 + 053e0aa commit cdac0a7

File tree

22 files changed

+3651
-1025
lines changed

22 files changed

+3651
-1025
lines changed

Assets/Plugins/LeapMotion/Core/Editor/CustomEditorBase.cs

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ protected override void OnEnable() {
3030
}
3131

3232
public class CustomEditorBase : Editor {
33-
protected Dictionary<string, Action<SerializedProperty>> _specifiedDrawers;
33+
protected Dictionary<string, Action<SerializedProperty >> _specifiedDrawers;
3434
protected Dictionary<string, List<Action<SerializedProperty>>> _specifiedDecorators;
3535
protected Dictionary<string, List<Action<SerializedProperty>>> _specifiedPostDecorators;
36-
protected Dictionary<string, List<Func<bool>>> _conditionalProperties;
37-
protected List<string> _deferredProperties;
36+
protected Dictionary<string, List<Func<bool>>> _conditionalProperties;
37+
protected Dictionary<string, List<string>> _foldoutProperties;
38+
protected Dictionary<string, bool> _foldoutStates;
39+
protected List <string > _deferredProperties;
3840
protected bool _showScriptField = true;
3941

4042
private bool _canCallSpecifyFunctions = false;
43+
private GUIStyle _boldFoldoutStyle;
4144

4245
protected List<SerializedProperty> _modifiedProperties = new List<SerializedProperty>();
4346

@@ -180,6 +183,37 @@ protected void deferProperty(string propertyName) {
180183
_deferredProperties.Insert(0, propertyName);
181184
}
182185

186+
/// <summary>
187+
/// Condition the drawing of a property based on the status of a foldout drop-down.
188+
/// </summary>
189+
protected void addPropertyToFoldout(string propertyName, string foldoutName, bool foldoutStartOpen = false) {
190+
throwIfNotInOnEnable("addPropertyToFoldout");
191+
192+
if (!validateProperty(propertyName)) { return; }
193+
194+
List<string> list;
195+
if (!_foldoutProperties.TryGetValue(foldoutName, out list)) {
196+
list = new List<string>();
197+
_foldoutProperties[foldoutName] = list;
198+
}
199+
_foldoutProperties[foldoutName].Add(propertyName);
200+
_foldoutStates [foldoutName] = foldoutStartOpen;
201+
}
202+
203+
/// <summary>
204+
/// Check whether a property is inside of a foldout drop-down.
205+
/// </summary>
206+
protected bool isInFoldout(string propertyName) {
207+
bool isInFoldout = false;
208+
foreach (var foldout in _foldoutProperties) {
209+
foreach (string property in foldout.Value) {
210+
if (property.Equals(propertyName)) { isInFoldout = true; break; }
211+
}
212+
if (isInFoldout) { break; }
213+
}
214+
return isInFoldout;
215+
}
216+
183217
protected void drawScriptField(bool disable = true) {
184218
var scriptProp = serializedObject.FindProperty("m_Script");
185219
EditorGUI.BeginDisabledGroup(disable);
@@ -195,11 +229,13 @@ protected virtual void OnEnable() {
195229
throw new Exception("Cleaning up an editor of type " + GetType() + ". Make sure to always destroy your editors when you are done with them!");
196230
}
197231

198-
_specifiedDrawers = new Dictionary<string, Action<SerializedProperty>>();
199-
_specifiedDecorators = new Dictionary<string, List<Action<SerializedProperty>>>();
232+
_specifiedDrawers = new Dictionary<string, Action<SerializedProperty>>();
233+
_specifiedDecorators = new Dictionary<string, List<Action<SerializedProperty>>>();
200234
_specifiedPostDecorators = new Dictionary<string, List<Action<SerializedProperty>>>();
201-
_conditionalProperties = new Dictionary<string, List<Func<bool>>>();
202-
_deferredProperties = new List<string>();
235+
_conditionalProperties = new Dictionary<string, List<Func<bool>>>();
236+
_foldoutProperties = new Dictionary<string, List<string>>();
237+
_foldoutStates = new Dictionary<string, bool>();
238+
_deferredProperties = new List<string>();
203239
_canCallSpecifyFunctions = true;
204240
}
205241

@@ -216,6 +252,12 @@ protected bool validateProperty(string propertyName) {
216252
* Individual properties can be specified to have custom drawers.
217253
*/
218254
public override void OnInspectorGUI() {
255+
// OnInspectorGUI is the first time "EditorStyles" can be accessed
256+
if (_boldFoldoutStyle == null) {
257+
_boldFoldoutStyle = new GUIStyle(EditorStyles.foldout);
258+
_boldFoldoutStyle.fontStyle = FontStyle.Bold;
259+
}
260+
219261
_canCallSpecifyFunctions = false;
220262

221263
_modifiedProperties.Clear();
@@ -228,7 +270,8 @@ public override void OnInspectorGUI() {
228270
continue;
229271
}
230272

231-
if (_deferredProperties.Contains(iterator.name)) {
273+
if (_deferredProperties.Contains(iterator.name) ||
274+
isInFoldout(iterator.name)) {
232275
continue;
233276
}
234277

@@ -240,7 +283,28 @@ public override void OnInspectorGUI() {
240283
}
241284

242285
foreach (var deferredProperty in _deferredProperties) {
243-
drawProperty(serializedObject.FindProperty(deferredProperty));
286+
if (!isInFoldout(deferredProperty)) {
287+
drawProperty(serializedObject.FindProperty(deferredProperty));
288+
}
289+
}
290+
291+
foreach (var foldout in _foldoutProperties) {
292+
_foldoutStates[foldout.Key] =
293+
EditorGUILayout.Foldout(_foldoutStates[foldout.Key], foldout.Key, _boldFoldoutStyle);
294+
if (_foldoutStates[foldout.Key]) {
295+
// Draw normal priority properties first
296+
foreach (var property in foldout.Value) {
297+
if (!_deferredProperties.Contains(property)) {
298+
drawProperty(serializedObject.FindProperty(property));
299+
}
300+
}
301+
// Draw deferred properties second
302+
foreach (var property in foldout.Value) {
303+
if (_deferredProperties.Contains(property)) {
304+
drawProperty(serializedObject.FindProperty(property));
305+
}
306+
}
307+
}
244308
}
245309

246310
serializedObject.ApplyModifiedProperties();

Assets/Plugins/LeapMotion/Core/Editor/LeapServiceProviderEditor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ protected override void OnEnable() {
5656
(int)LeapServiceProvider.PhysicsExtrapolationMode.Manual,
5757
"_physicsExtrapolationTime");
5858

59+
deferProperty("_serverNameSpace");
5960
deferProperty("_workerThreadProfiling");
61+
62+
if (!(LeapServiceProvider is LeapXRServiceProvider)) {
63+
addPropertyToFoldout("_trackingOptimization", "Advanced Options");
64+
}
65+
addPropertyToFoldout("_workerThreadProfiling", "Advanced Options");
66+
addPropertyToFoldout("_serverNameSpace" , "Advanced Options");
6067
}
6168

6269
private void frameOptimizationWarning(SerializedProperty property) {

Assets/Plugins/LeapMotion/Core/Editor/LeapXRServiceProviderEditor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ protected override void OnEnable() {
3434
.FindProperty("_deviceOffsetMode")
3535
.enumValueIndex == 2; },
3636
"_deviceOrigin");
37+
38+
addPropertyToFoldout("_deviceOffsetMode" , "Advanced Options");
39+
addPropertyToFoldout("_temporalWarpingMode" , "Advanced Options");
40+
addPropertyToFoldout("_customWarpAdjustment", "Advanced Options");
41+
addPropertyToFoldout("_deviceOffsetYAxis" , "Advanced Options");
42+
addPropertyToFoldout("_deviceOffsetZAxis" , "Advanced Options");
43+
addPropertyToFoldout("_deviceTiltXAxis" , "Advanced Options");
44+
addPropertyToFoldout("_deviceOrigin" , "Advanced Options");
45+
addPropertyToFoldout("_preCullCamera" , "Advanced Options");
46+
addPropertyToFoldout("_updateHandInPrecull" , "Advanced Options");
3747
}
3848

3949
private void decorateAllowManualTimeAlignment(SerializedProperty property) {

0 commit comments

Comments
 (0)