Skip to content

Commit

Permalink
Fixed simulated hand data provider Tracked Hand Pose list rendering (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Nov 23, 2020
1 parent f399d17 commit 61c775b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ namespace XRTK.Editor.Profiles.InputSystem.Controllers
[CustomEditor(typeof(BaseHandControllerDataProviderProfile), true, isFallback = true)]
public class BaseMixedRealityHandControllerDataProviderProfileInspector : BaseMixedRealityControllerDataProviderProfileInspector
{
private static readonly GUIContent handTrackingSettingsFoldoutHeader = new GUIContent("Hand Tracking Settings");

private SerializedProperty renderingMode;
private SerializedProperty handPhysicsEnabled;
private SerializedProperty useTriggers;
private SerializedProperty boundsMode;
private SerializedProperty trackedPoses;

private bool showHandTrackingSettings = true;
private static readonly GUIContent handTrackingSettingsFoldoutHeader = new GUIContent("Hand Tracking Settings");

private ReorderableList poseProfilesList;
private int currentlySelectedPoseElement;
Expand Down Expand Up @@ -50,7 +51,10 @@ public override void OnInspectorGUI()

serializedObject.Update();

showHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showHandTrackingSettings, handTrackingSettingsFoldoutHeader, true);
EditorGUILayout.Space();

showHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showHandTrackingSettings, handTrackingSettingsFoldoutHeader);

if (showHandTrackingSettings)
{
EditorGUI.indentLevel++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
using XRTK.Definitions.Controllers.Hands;
using XRTK.Definitions.Controllers.Simulation.Hands;
using XRTK.Editor.Extensions;

Expand All @@ -22,6 +24,8 @@ public class SimulatedHandControllerDataProviderProfileInspector : SimulatedCont
private SerializedProperty handPoseAnimationSpeed;

private bool showSimulatedHandTrackingSettings = true;
private ReorderableList poseProfilesList;
private int currentlySelectedPoseElement;

protected override void OnEnable()
{
Expand All @@ -34,6 +38,15 @@ protected override void OnEnable()

trackedPoses = serializedObject.FindProperty(nameof(trackedPoses));

poseProfilesList = new ReorderableList(serializedObject, trackedPoses, true, false, true, true)
{
elementHeight = EditorGUIUtility.singleLineHeight * 1.5f
};
poseProfilesList.drawHeaderCallback += PoseProfilesList_DrawHeaderCallback;
poseProfilesList.drawElementCallback += PoseProfilesList_DrawConfigurationOptionElement;
poseProfilesList.onAddCallback += PoseProfilesList_OnConfigurationOptionAdded;
poseProfilesList.onRemoveCallback += PoseProfilesList_OnConfigurationOptionRemoved;

handPoseAnimationSpeed = serializedObject.FindProperty(nameof(handPoseAnimationSpeed));
}

Expand All @@ -45,7 +58,8 @@ public override void OnInspectorGUI()

EditorGUILayout.Space();

showSimulatedHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showSimulatedHandTrackingSettings, SimulatedHandSettingsFoldoutHeader, true);
showSimulatedHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showSimulatedHandTrackingSettings, SimulatedHandSettingsFoldoutHeader);

if (showSimulatedHandTrackingSettings)
{
EditorGUI.indentLevel++;
Expand All @@ -64,9 +78,8 @@ public override void OnInspectorGUI()
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Tracked Hand Poses");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(trackedPoses, true);
poseProfilesList.DoLayoutList();
EditorGUILayout.Space();
EditorGUI.indentLevel--;

Expand All @@ -81,5 +94,50 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
}
}

private void PoseProfilesList_DrawHeaderCallback(Rect rect)
{
EditorGUI.LabelField(rect, "Tracked Hand Poses");
}

private void PoseProfilesList_DrawConfigurationOptionElement(Rect rect, int index, bool isActive, bool isFocused)
{
if (isFocused)
{
currentlySelectedPoseElement = index;
}

rect.height = EditorGUIUtility.singleLineHeight;
rect.y += 3;
var poseDataProperty = trackedPoses.GetArrayElementAtIndex(index);
var selectedPoseData = EditorGUI.ObjectField(rect, poseDataProperty.objectReferenceValue, typeof(HandControllerPoseProfile), false) as HandControllerPoseProfile;

if (selectedPoseData != null)
{
selectedPoseData.ParentProfile = ThisProfile;
}

poseDataProperty.objectReferenceValue = selectedPoseData;
}

private void PoseProfilesList_OnConfigurationOptionAdded(ReorderableList list)
{
trackedPoses.arraySize += 1;
var index = trackedPoses.arraySize - 1;

var mappingProfileProperty = trackedPoses.GetArrayElementAtIndex(index);
mappingProfileProperty.objectReferenceValue = null;
serializedObject.ApplyModifiedProperties();
}

private void PoseProfilesList_OnConfigurationOptionRemoved(ReorderableList list)
{
if (currentlySelectedPoseElement >= 0)
{
trackedPoses.DeleteArrayElementAtIndex(currentlySelectedPoseElement);
}

serializedObject.ApplyModifiedProperties();
}
}
}

0 comments on commit 61c775b

Please sign in to comment.