Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit 3f98664

Browse files
updated inspector to use new bold foldout property drawer (#162)
* updated inspector to use new bold foldout property drawer * fixed accessors
1 parent fa113fc commit 3f98664

8 files changed

Lines changed: 179 additions & 121 deletions

File tree

Features/UX/Scripts/Pointers/LinePointer.cs

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEngine;
5+
using UnityEngine.Serialization;
56
using XRTK.Definitions.Physics;
67
using XRTK.Utilities.Lines.DataProviders;
78
using XRTK.Utilities.Lines.Renderers;
@@ -14,24 +15,66 @@ namespace XRTK.SDK.UX.Pointers
1415
public class LinePointer : BaseControllerPointer
1516
{
1617
[SerializeField]
17-
protected Gradient LineColorSelected = new Gradient();
18+
[FormerlySerializedAs("LineColorSelected")]
19+
private Gradient lineColorSelected = new Gradient();
20+
21+
protected Gradient LineColorSelected
22+
{
23+
get => lineColorSelected;
24+
set => lineColorSelected = value;
25+
}
1826

1927
[SerializeField]
20-
protected Gradient LineColorValid = new Gradient();
28+
[FormerlySerializedAs("LineColorValid")]
29+
private Gradient lineColorValid = new Gradient();
30+
31+
protected Gradient LineColorValid
32+
{
33+
get => lineColorValid;
34+
set => lineColorValid = value;
35+
}
2136

2237
[SerializeField]
23-
protected Gradient LineColorInvalid = new Gradient();
38+
[FormerlySerializedAs("LineColorInvalid")]
39+
private Gradient lineColorInvalid = new Gradient();
40+
41+
protected Gradient LineColorInvalid
42+
{
43+
get => lineColorInvalid;
44+
set => lineColorInvalid = value;
45+
}
2446

2547
[SerializeField]
26-
protected Gradient LineColorNoTarget = new Gradient();
48+
[FormerlySerializedAs("LineColorNoTarget")]
49+
private Gradient lineColorNoTarget = new Gradient();
50+
51+
protected Gradient LineColorNoTarget
52+
{
53+
get => lineColorNoTarget;
54+
set => lineColorNoTarget = value;
55+
}
2756

2857
[SerializeField]
29-
protected Gradient LineColorLockFocus = new Gradient();
58+
[FormerlySerializedAs("LineColorLockFocus")]
59+
private Gradient lineColorLockFocus = new Gradient();
60+
61+
protected Gradient LineColorLockFocus
62+
{
63+
get => lineColorLockFocus;
64+
set => lineColorLockFocus = value;
65+
}
3066

3167
[Range(2, 50)]
3268
[SerializeField]
69+
[FormerlySerializedAs("LineCastResolution")]
3370
[Tooltip("This setting has a high performance cost. Values above 20 are not recommended.")]
34-
protected int LineCastResolution = 10;
71+
private int lineCastResolution = 10;
72+
73+
protected int LineCastResolution
74+
{
75+
get => lineCastResolution;
76+
set => lineCastResolution = value;
77+
}
3578

3679
[SerializeField]
3780
private BaseMixedRealityLineDataProvider lineBase;
@@ -57,8 +100,6 @@ public BaseMixedRealityLineRenderer[] LineRenderers
57100
set => lineRenderers = value;
58101
}
59102

60-
private Vector3 syncedPosition;
61-
62103
private void CheckInitialization()
63104
{
64105
if (lineBase == null)
@@ -137,9 +178,9 @@ public override void OnPreRaycast()
137178
}
138179

139180
// Make sure our array will hold
140-
if (Rays == null || Rays.Length != LineCastResolution)
181+
if (Rays == null || Rays.Length != lineCastResolution)
141182
{
142-
Rays = new RayStep[LineCastResolution];
183+
Rays = new RayStep[lineCastResolution];
143184
}
144185

145186
var stepSize = 1f / Rays.Length;
@@ -181,20 +222,20 @@ public override void OnPostRaycast()
181222
if (Result.CurrentPointerTarget != null)
182223
{
183224
clearWorldLength = Result.RayDistance;
184-
lineColor = IsSelectPressed ? LineColorSelected : LineColorValid;
225+
lineColor = IsSelectPressed ? lineColorSelected : lineColorValid;
185226
}
186227
else
187228
{
188229
clearWorldLength = PointerExtent;
189-
lineColor = IsSelectPressed ? LineColorSelected : LineColorNoTarget;
230+
lineColor = IsSelectPressed ? lineColorSelected : lineColorNoTarget;
190231
}
191232

192233
if (IsFocusLocked)
193234
{
194-
lineColor = LineColorLockFocus;
235+
lineColor = lineColorLockFocus;
195236
}
196237

197-
int maxClampLineSteps = LineCastResolution;
238+
int maxClampLineSteps = lineCastResolution;
198239

199240
for (var i = 0; i < lineRenderers.Length; i++)
200241
{

Features/UX/Scripts/Pointers/TeleportPointer.cs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using UnityEngine;
6+
using UnityEngine.Serialization;
67
using XRTK.Definitions.InputSystem;
78
using XRTK.Definitions.Physics;
89
using XRTK.EventDatum.Input;
@@ -57,15 +58,36 @@ public class TeleportPointer : LinePointer
5758
private float upDirectionThreshold = 0.2f;
5859

5960
[SerializeField]
60-
protected Gradient LineColorHotSpot = new Gradient();
61+
[FormerlySerializedAs("LineColorHotSpot")]
62+
private Gradient lineColorHotSpot = new Gradient();
63+
64+
protected Gradient LineColorHotSpot
65+
{
66+
get => lineColorHotSpot;
67+
set => lineColorHotSpot = value;
68+
}
6169

6270
[SerializeField]
71+
[FormerlySerializedAs("ValidLayers")]
6372
[Tooltip("Layers that are considered 'valid' for navigation")]
64-
protected LayerMask ValidLayers = Physics.DefaultRaycastLayers;
73+
private LayerMask validLayers = Physics.DefaultRaycastLayers;
74+
75+
protected LayerMask ValidLayers
76+
{
77+
get => validLayers;
78+
set => validLayers = value;
79+
}
6580

6681
[SerializeField]
82+
[FormerlySerializedAs("InvalidLayers")]
6783
[Tooltip("Layers that are considered 'invalid' for navigation")]
68-
protected LayerMask InvalidLayers = Physics.IgnoreRaycastLayer;
84+
private LayerMask invalidLayers = Physics.IgnoreRaycastLayer;
85+
86+
protected LayerMask InvalidLayers
87+
{
88+
get => invalidLayers;
89+
set => invalidLayers = value;
90+
}
6991

7092
private Vector2 currentInputPosition = Vector2.zero;
7193

@@ -75,7 +97,7 @@ public class TeleportPointer : LinePointer
7597

7698
private bool canMove = false;
7799

78-
private bool isTeleportSystemEnabled => MixedRealityToolkit.IsInitialized &&
100+
private bool IsTeleportSystemEnabled => MixedRealityToolkit.IsInitialized &&
79101
MixedRealityToolkit.HasActiveProfile &&
80102
MixedRealityToolkit.Instance.ActiveProfile.IsTeleportSystemEnabled;
81103

@@ -95,7 +117,7 @@ protected Gradient GetLineGradient(TeleportSurfaceResult targetResult)
95117
case TeleportSurfaceResult.Invalid:
96118
return LineColorInvalid;
97119
case TeleportSurfaceResult.HotSpot:
98-
return LineColorHotSpot;
120+
return lineColorHotSpot;
99121
default:
100122
throw new ArgumentOutOfRangeException(nameof(targetResult), targetResult, null);
101123
}
@@ -104,7 +126,7 @@ protected Gradient GetLineGradient(TeleportSurfaceResult targetResult)
104126
#region IMixedRealityPointer Implementation
105127

106128
/// <inheritdoc />
107-
public override bool IsInteractionEnabled => !IsTeleportRequestActive && teleportEnabled && isTeleportSystemEnabled;
129+
public override bool IsInteractionEnabled => !IsTeleportRequestActive && teleportEnabled && IsTeleportSystemEnabled;
108130

109131
/// <inheritdoc />
110132
public override float PointerOrientation
@@ -161,7 +183,7 @@ public override void OnPostRaycast()
161183
if (Result.CurrentPointerTarget != null)
162184
{
163185
// Check if it's in our valid layers
164-
if (((1 << Result.CurrentPointerTarget.layer) & ValidLayers.value) != 0)
186+
if (((1 << Result.CurrentPointerTarget.layer) & validLayers.value) != 0)
165187
{
166188
// See if it's a hot spot
167189
if (TeleportHotSpot != null && TeleportHotSpot.IsActive)
@@ -177,7 +199,7 @@ public override void OnPostRaycast()
177199
: TeleportSurfaceResult.Invalid;
178200
}
179201
}
180-
else if (((1 << Result.CurrentPointerTarget.layer) & InvalidLayers) != 0)
202+
else if (((1 << Result.CurrentPointerTarget.layer) & invalidLayers) != 0)
181203
{
182204
TeleportSurfaceResult = TeleportSurfaceResult.Invalid;
183205
}
@@ -240,7 +262,7 @@ public override void OnPostRaycast()
240262
public override void OnInputChanged(InputEventData<Vector2> eventData)
241263
{
242264
// Don't process input if we've got an active teleport request in progress.
243-
if (IsTeleportRequestActive || !isTeleportSystemEnabled) { return; }
265+
if (IsTeleportRequestActive || !IsTeleportSystemEnabled) { return; }
244266

245267
if (eventData.SourceId == InputSourceParent.SourceId &&
246268
eventData.Handedness == Handedness &&

Inspectors/Input/Handlers/ControllerPoseSynchronizerInspector.cs

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,30 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using UnityEditor;
5+
using UnityEngine;
56
using XRTK.Definitions.Utilities;
7+
using XRTK.Inspectors.Extensions;
68
using XRTK.SDK.Input.Handlers;
79

810
namespace XRTK.SDK.Inspectors.Input.Handlers
911
{
1012
[CustomEditor(typeof(ControllerPoseSynchronizer))]
1113
public class ControllerPoseSynchronizerInspector : Editor
1214
{
13-
private const string SynchronizationSettingsKey = "XRTK_Inspector_SynchronizationSettingsFoldout";
15+
private readonly GUIContent synchronizationSettings = new GUIContent("Synchronization Settings");
1416
private static readonly string[] HandednessLabels = { "Left", "Right" };
1517

16-
private static bool synchronizationSettingsFoldout = true;
17-
18-
private SerializedProperty handedness;
1918
private SerializedProperty useSourcePoseData;
2019
private SerializedProperty poseAction;
20+
private SerializedProperty handedness;
2121

2222
protected bool DrawHandednessProperty = true;
2323

2424
protected virtual void OnEnable()
2525
{
26-
synchronizationSettingsFoldout = SessionState.GetBool(SynchronizationSettingsKey, synchronizationSettingsFoldout);
27-
handedness = serializedObject.FindProperty("handedness");
28-
useSourcePoseData = serializedObject.FindProperty("useSourcePoseData");
29-
poseAction = serializedObject.FindProperty("poseAction");
26+
useSourcePoseData = serializedObject.FindProperty(nameof(useSourcePoseData));
27+
poseAction = serializedObject.FindProperty(nameof(poseAction));
28+
handedness = serializedObject.FindProperty(nameof(handedness));
3029
}
3130

3231
public override void OnInspectorGUI()
@@ -35,40 +34,34 @@ public override void OnInspectorGUI()
3534

3635
EditorGUILayout.Space();
3736
EditorGUI.BeginChangeCheck();
38-
synchronizationSettingsFoldout = EditorGUILayout.Foldout(synchronizationSettingsFoldout, "Synchronization Settings", true);
3937

40-
if (EditorGUI.EndChangeCheck())
38+
if (useSourcePoseData.FoldoutWithBoldLabelPropertyField(synchronizationSettings))
4139
{
42-
SessionState.SetBool(SynchronizationSettingsKey, synchronizationSettingsFoldout);
43-
}
40+
EditorGUI.indentLevel++;
4441

45-
if (!synchronizationSettingsFoldout) { return; }
46-
47-
EditorGUI.indentLevel++;
42+
if (!useSourcePoseData.boolValue)
43+
{
44+
EditorGUILayout.PropertyField(poseAction);
45+
}
4846

49-
if (DrawHandednessProperty)
50-
{
51-
var currentHandedness = (Handedness)handedness.enumValueIndex;
52-
var handIndex = currentHandedness == Handedness.Right ? 1 : 0;
47+
if (DrawHandednessProperty)
48+
{
49+
var currentHandedness = (Handedness)handedness.enumValueIndex;
50+
var handIndex = currentHandedness == Handedness.Right ? 1 : 0;
5351

54-
EditorGUI.BeginChangeCheck();
55-
var newHandednessIndex = EditorGUILayout.Popup(handedness.displayName, handIndex, HandednessLabels);
52+
EditorGUI.BeginChangeCheck();
53+
var newHandednessIndex = EditorGUILayout.Popup(handedness.displayName, handIndex, HandednessLabels);
5654

57-
if (EditorGUI.EndChangeCheck())
58-
{
59-
currentHandedness = newHandednessIndex == 0 ? Handedness.Left : Handedness.Right;
60-
handedness.enumValueIndex = (int)currentHandedness;
55+
if (EditorGUI.EndChangeCheck())
56+
{
57+
currentHandedness = newHandednessIndex == 0 ? Handedness.Left : Handedness.Right;
58+
handedness.enumValueIndex = (int)currentHandedness;
59+
}
6160
}
62-
}
63-
64-
EditorGUILayout.PropertyField(useSourcePoseData);
6561

66-
if (!useSourcePoseData.boolValue)
67-
{
68-
EditorGUILayout.PropertyField(poseAction);
62+
EditorGUI.indentLevel--;
6963
}
7064

71-
EditorGUI.indentLevel--;
7265
serializedObject.ApplyModifiedProperties();
7366
}
7467
}

0 commit comments

Comments
 (0)