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

Change requests for controller provider inspectors #526

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class SimulatedControllerDataProviderProfile : BaseMixedRealityController
{
#region General Settings

[Header("General Settings")]

[SerializeField]
[Tooltip("Simulated update frequency for tracking data in milliseconds. 0ms is every frame.")]
private double simulatedUpdateFrequency = 0;
Expand All @@ -35,8 +33,6 @@ public class SimulatedControllerDataProviderProfile : BaseMixedRealityController

#region Placement Settings

[Header("Placement Settings")]

[SerializeField]
[Tooltip("Default distance of the controller from the camera")]
private float defaultDistance = 0.5f;
Expand Down Expand Up @@ -68,8 +64,6 @@ public class SimulatedControllerDataProviderProfile : BaseMixedRealityController

#region Controls Settings

[Header("Controls Settings")]

[SerializeField]
[Tooltip("Key to toggle persistent mode for the left controller")]
private KeyCode toggleLeftPersistentKey = KeyCode.T;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor;
using UnityEngine;

namespace XRTK.Inspectors.Extensions
{
/// <summary>
/// Extensions for <see cref="EditorGUILayout"/> usage.
/// </summary>
public static class EditorGUILayoutExtensions
{
/// <summary>
/// Draws a foldout but with bold label text.
/// </summary>
/// <param name="foldout">Foldout state.</param>
/// <param name="content">Foldout label content.</param>
/// <param name="toggleOnLabelClick">Should the foldout toggle on label click?</param>
/// <returns>Returns true, if foldout unfolded.</returns>
public static bool FoldoutWithBoldLabel(bool foldout, GUIContent content, bool toggleOnLabelClick)
{
GUIStyle defaultStyle = EditorStyles.foldout;
FontStyle previousStyle = defaultStyle.fontStyle;
defaultStyle.fontStyle = FontStyle.Bold;
foldout = EditorGUILayout.Foldout(foldout, content, toggleOnLabelClick);
defaultStyle.fontStyle = previousStyle;

return foldout;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using XRTK.Inspectors.Extensions;
using XRTK.Inspectors.PropertyDrawers;
using XRTK.Providers.Controllers;
using XRTK.Extensions;
using System.Collections.Generic;

namespace XRTK.Inspectors.Profiles.InputSystem.Controllers
{
Expand All @@ -26,6 +28,12 @@ public class BaseMixedRealityControllerDataProviderProfileInspector : BaseMixedR

private ReorderableList mappingProfileList;
private int currentlySelectedElement;
private int selectedMappingsViewModeTab = 0;
private GUIStyle controllerButtonStyle;

private static readonly GUIContent controllerProfilesFoldoutHeader = new GUIContent("Controller Mapping Profiles");
private static readonly string[] viewModeToolbarOptions = new string[] { "Simple", "Advanced" };
private static readonly List<int> nullElementIndexes = new List<int>();

protected override void OnEnable()
{
Expand Down Expand Up @@ -168,17 +176,99 @@ public override void OnInspectorGUI()
{
RenderHeader("This profile defines all of the controllers and their mappings to use. Additional platform settings can also be available as well.");

showMappingProfiles = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showMappingProfiles, controllerProfilesFoldoutHeader, true);
if (showMappingProfiles)
{
EditorGUILayout.Space();
selectedMappingsViewModeTab = GUILayout.Toolbar(selectedMappingsViewModeTab, viewModeToolbarOptions);
switch (selectedMappingsViewModeTab)
{
case 0:
DrawSimpleControllerMappingProfilesView();
break;
case 1:
DrawAdvancedControllerMappingProfilesView();
break;
}
}

EditorGUILayout.Space();
}

private void DrawAdvancedControllerMappingProfilesView()
{
serializedObject.Update();
mappingProfileList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}

private void DrawSimpleControllerMappingProfilesView()
{
if (controllerButtonStyle == null)
FejZa marked this conversation as resolved.
Show resolved Hide resolved
{
controllerButtonStyle = new GUIStyle("LargeButton")
{
imagePosition = ImagePosition.ImageAbove,
fontStyle = FontStyle.Bold,
stretchHeight = true,
stretchWidth = true,
wordWrap = true,
fontSize = 10,
};
}

showMappingProfiles = EditorGUILayout.Foldout(showMappingProfiles, new GUIContent("Controller Mapping Profiles"), true);
// Clear found null element indexes from previous loop.
nullElementIndexes.Clear();

if (showMappingProfiles)
for (int i = 0; i < controllerMappingProfiles?.arraySize; i++)
{
mappingProfileList.DoLayoutList();
var targetObjectReference = controllerMappingProfiles.GetArrayElementAtIndex(i)?.objectReferenceValue;
FejZa marked this conversation as resolved.
Show resolved Hide resolved
var controllerMappingProfile = (MixedRealityControllerMappingProfile)targetObjectReference;

// In advanced mode new profile entries might have been created
// but not assigned, which leads to null entries in the mapping profiles list.
// We can safely ignore those for the simplified view but will remember the index
// to remove them later on and cleanup the list of nulls.
if (controllerMappingProfile != null)
{
var handedness = controllerMappingProfile.Handedness;

if (handedness != Handedness.Right)
{
GUILayout.BeginHorizontal();
}

var buttonContent = new GUIContent($"Edit {controllerMappingProfile.name.ToProperCase()}", ControllerMappingLibrary.GetControllerTextureScaled(controllerMappingProfile));
if (GUILayout.Button(buttonContent, controllerButtonStyle, GUILayout.Height(128f), GUILayout.MinWidth(32f), GUILayout.ExpandWidth(true)))
{
EditorApplication.delayCall += () => ControllerPopupWindow.Show(controllerMappingProfile, new SerializedObject(controllerMappingProfile).FindProperty("interactionMappingProfiles"));
FejZa marked this conversation as resolved.
Show resolved Hide resolved
}

if (handedness != Handedness.Left)
{
GUILayout.EndHorizontal();
}
}
else
{
nullElementIndexes.Add(i);
}
}

serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space();
if (nullElementIndexes.Count > 0)
{
serializedObject.Update();

for (int i = 0; i < nullElementIndexes.Count; i++)
{
// Every time we remove an element from the mapping profiles list,
// we need to reduce the null element index by the count of already removed items,
// since the list is shrinking.
controllerMappingProfiles.DeleteArrayElementAtIndex(nullElementIndexes[i] - i);
}

serializedObject.ApplyModifiedProperties();
}
}

private void DrawConfigurationOptionElement(Rect position, int index, bool isActive, bool isFocused)
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 UnityEngine;
using XRTK.Definitions.Controllers.Hands;
using XRTK.Inspectors.Extensions;

namespace XRTK.Inspectors.Profiles.InputSystem.Controllers
{
Expand All @@ -14,6 +16,9 @@ public class BaseMixedRealityHandControllerDataProviderProfileInspector : BaseMi
private SerializedProperty useTriggers;
private SerializedProperty boundsMode;

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

protected override void OnEnable()
{
base.OnEnable();
Expand All @@ -27,14 +32,29 @@ protected override void OnEnable()
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.LabelField("Hand Rendering Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handMeshingEnabled);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Hand Physics Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
EditorGUILayout.PropertyField(boundsMode);
EditorGUILayout.Space();

serializedObject.Update();

showHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showHandTrackingSettings, handTrackingSettingsFoldoutHeader, true);
if (showHandTrackingSettings)
{
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("Hand Rendering Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handMeshingEnabled);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Hand Physics Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
EditorGUILayout.PropertyField(boundsMode);
EditorGUILayout.Space();
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
}

serializedObject.ApplyModifiedProperties();
}
}
}
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 UnityEngine;
using XRTK.Definitions.Controllers.Simulation;
using XRTK.Inspectors.Extensions;

namespace XRTK.Inspectors.Profiles.InputSystem.Controllers.Simulation
{
Expand All @@ -23,6 +25,9 @@ public class SimulatedControllerDataProviderProfileInspector : BaseMixedRealityC

private SerializedProperty rotationSpeed;

private bool showSimulationSettings = true;
private static readonly GUIContent simulationSettingsFoldoutHeader = new GUIContent("Simulation Settings");

protected override void OnEnable()
{
base.OnEnable();
Expand All @@ -48,21 +53,38 @@ public override void OnInspectorGUI()

serializedObject.Update();

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(simulatedUpdateFrequency);
EditorGUILayout.PropertyField(controllerHideTimeout);
EditorGUILayout.Space();

EditorGUILayout.PropertyField(defaultDistance);
EditorGUILayout.PropertyField(depthMultiplier);
EditorGUILayout.PropertyField(jitterAmount);
EditorGUILayout.Space();

EditorGUILayout.PropertyField(toggleLeftPersistentKey);
EditorGUILayout.PropertyField(leftControllerTrackedKey);
EditorGUILayout.PropertyField(toggleRightPersistentKey);
EditorGUILayout.PropertyField(rightControllerTrackedKey);
EditorGUILayout.PropertyField(rotationSpeed);
showSimulationSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showSimulationSettings, simulationSettingsFoldoutHeader, true);
if (showSimulationSettings)
{
EditorGUI.indentLevel++;

EditorGUILayout.LabelField("General Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(simulatedUpdateFrequency);
EditorGUILayout.PropertyField(controllerHideTimeout);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Placement Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(defaultDistance);
EditorGUILayout.PropertyField(depthMultiplier);
EditorGUILayout.PropertyField(jitterAmount);
EditorGUILayout.Space();
EditorGUI.indentLevel--;

EditorGUILayout.LabelField("Controls Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(toggleLeftPersistentKey);
EditorGUILayout.PropertyField(leftControllerTrackedKey);
EditorGUILayout.PropertyField(toggleRightPersistentKey);
EditorGUILayout.PropertyField(rightControllerTrackedKey);
EditorGUILayout.PropertyField(rotationSpeed);
EditorGUI.indentLevel--;

EditorGUI.indentLevel--;

}

serializedObject.ApplyModifiedProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using UnityEditorInternal;
using UnityEngine;
using XRTK.Definitions.Controllers.Simulation.Hands;
using XRTK.Inspectors.Extensions;

namespace XRTK.Inspectors.Profiles.InputSystem.Controllers.Simulation
{
Expand All @@ -22,6 +23,10 @@ public class SimulatedHandControllerDataProviderProfileInspector : SimulatedCont
private ReorderableList poseList;
private int currentlySelectedElement;

private bool showSimulatedHandTrackingSettings = true;

private static readonly GUIContent simulatedHandSettingsFoldoutHeader = new GUIContent("Simulated Hand Tracking Settings");

protected override void OnEnable()
{
base.OnEnable();
Expand Down Expand Up @@ -55,19 +60,31 @@ public override void OnInspectorGUI()

serializedObject.Update();

EditorGUILayout.Space();
EditorGUILayout.LabelField("Hand Rendering Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handMeshingEnabled);
EditorGUILayout.LabelField("Hand Physics Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
EditorGUILayout.PropertyField(boundsMode);
EditorGUILayout.Space();

EditorGUILayout.LabelField("Hand Simulation Settings", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(handPoseAnimationSpeed);

poseList.DoLayoutList();
showSimulatedHandTrackingSettings = EditorGUILayoutExtensions.FoldoutWithBoldLabel(showSimulatedHandTrackingSettings, simulatedHandSettingsFoldoutHeader, true);
if (showSimulatedHandTrackingSettings)
{
EditorGUI.indentLevel++;
EditorGUILayout.LabelField("Hand Rendering Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handMeshingEnabled);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Hand Physics Settings");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handPhysicsEnabled);
EditorGUILayout.PropertyField(useTriggers);
EditorGUILayout.PropertyField(boundsMode);
EditorGUILayout.Space();
EditorGUI.indentLevel--;
EditorGUILayout.LabelField("Simulated Poses");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(handPoseAnimationSpeed);
poseList.DoLayoutList();
EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
}

serializedObject.ApplyModifiedProperties();
}
Expand Down