-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new interaction behaviour "SteeringWheelBehaviour" (#135)
* Add default SteeringWheelBehaviour * Complete inspector
- Loading branch information
Showing
12 changed files
with
460 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
Editor/Inspectors/LockControllerVisualizerBehaviourInspector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Reality Collective. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using RealityToolkit.Editor.Utilities; | ||
using RealityToolkit.Input.InteractionBehaviours; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine.UIElements; | ||
|
||
namespace RealityToolkit.Editor.Inspectors | ||
{ | ||
[CustomEditor(typeof(LockControllerVisualizerBehaviour), true)] | ||
public class LockControllerVisualizerBehaviourInspector : BaseInteractionBehaviourInspector | ||
{ | ||
private VisualElement inspector; | ||
private PropertyField smoothSyncPose; | ||
private PropertyField syncPositionSpeed; | ||
private PropertyField syncRotationSpeed; | ||
|
||
private const string grabOffsetPoseBindingPath = "localOffsetPose"; | ||
private const string smoothSyncPoseBindingPath = "smoothSyncPose"; | ||
private const string syncPositionSpeedBindingPath = "syncPositionSpeed"; | ||
private const string syncRotationSpeedBindingPath = "syncRotationSpeed"; | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
public override VisualElement CreateInspectorGUI() | ||
{ | ||
inspector = base.CreateInspectorGUI(); | ||
|
||
inspector.Add(new PropertyField(serializedObject.FindProperty(grabOffsetPoseBindingPath))); | ||
|
||
smoothSyncPose = new PropertyField(serializedObject.FindProperty(smoothSyncPoseBindingPath)); | ||
smoothSyncPose.RegisterCallback<ChangeEvent<bool>>(SmoothSyncPose_ValueChanged); | ||
inspector.Add(smoothSyncPose); | ||
|
||
syncPositionSpeed = new PropertyField(serializedObject.FindProperty(syncPositionSpeedBindingPath)); | ||
syncPositionSpeed.style.paddingLeft = UIElementsUtilities.DefaultInset; | ||
|
||
syncRotationSpeed = new PropertyField(serializedObject.FindProperty(syncRotationSpeedBindingPath)); | ||
syncRotationSpeed.style.paddingLeft = UIElementsUtilities.DefaultInset; | ||
|
||
UpdateSmoothSyncPoseFields(serializedObject.FindProperty(smoothSyncPoseBindingPath).boolValue); | ||
|
||
return inspector; | ||
} | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
private void OnDestroy() | ||
{ | ||
if (smoothSyncPose != null) | ||
{ | ||
smoothSyncPose.UnregisterCallback<ChangeEvent<bool>>(SmoothSyncPose_ValueChanged); | ||
} | ||
} | ||
|
||
private void SmoothSyncPose_ValueChanged(ChangeEvent<bool> changeEvent) => UpdateSmoothSyncPoseFields(changeEvent.newValue); | ||
|
||
private void UpdateSmoothSyncPoseFields(bool showFields) | ||
{ | ||
if (showFields) | ||
{ | ||
inspector.Add(syncPositionSpeed); | ||
syncPositionSpeed.PlaceInFront(smoothSyncPose); | ||
inspector.Add(syncRotationSpeed); | ||
syncRotationSpeed.PlaceInFront(syncPositionSpeed); | ||
return; | ||
} | ||
|
||
if (inspector.Contains(syncPositionSpeed)) | ||
{ | ||
inspector.Remove(syncPositionSpeed); | ||
} | ||
|
||
if (inspector.Contains(syncRotationSpeed)) | ||
{ | ||
inspector.Remove(syncRotationSpeed); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/Inspectors/LockControllerVisualizerBehaviourInspector.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) Reality Collective. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using RealityToolkit.Editor.Utilities; | ||
using RealityToolkit.Input.InteractionBehaviours; | ||
using UnityEditor; | ||
using UnityEditor.UIElements; | ||
using UnityEngine.UIElements; | ||
|
||
namespace RealityToolkit.Editor.Inspectors | ||
{ | ||
[CustomEditor(typeof(SteeringWheelBehaviour), true)] | ||
public class SteeringWheelBehaviourInspector : BaseInteractionBehaviourInspector | ||
{ | ||
private VisualElement inspector; | ||
private PropertyField resetsToNeutral; | ||
private PropertyField smoothReset; | ||
private PropertyField smoothResetDuration; | ||
|
||
private const string steeringAngleLimitBindingPath = "steeringAngleLimit"; | ||
private const string upTransformBindingPath = "upTransform"; | ||
private const string resetsToNeutralBindingPath = "resetsToNeutral"; | ||
private const string smoothResetBindingPath = "smoothReset"; | ||
private const string smoothResetDurationBindingPath = "smoothResetDuration"; | ||
private const string steeringChangedBindingPath = "SteeringChanged"; | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
public override VisualElement CreateInspectorGUI() | ||
{ | ||
inspector = base.CreateInspectorGUI(); | ||
|
||
inspector.Add(new PropertyField(serializedObject.FindProperty(steeringAngleLimitBindingPath))); | ||
inspector.Add(new PropertyField(serializedObject.FindProperty(upTransformBindingPath))); | ||
|
||
resetsToNeutral = new PropertyField(serializedObject.FindProperty(resetsToNeutralBindingPath)); | ||
resetsToNeutral.RegisterCallback<ChangeEvent<bool>>(ResetsToNeutral_ValueChanged); | ||
inspector.Add(resetsToNeutral); | ||
|
||
smoothReset = new PropertyField(serializedObject.FindProperty(smoothResetBindingPath)); | ||
smoothReset.RegisterCallback<ChangeEvent<bool>>(SmoothReset_ValueChanged); | ||
smoothReset.style.paddingLeft = UIElementsUtilities.DefaultInset; | ||
|
||
smoothResetDuration = new PropertyField(serializedObject.FindProperty(smoothResetDurationBindingPath)); | ||
smoothResetDuration.style.paddingLeft = 2 * UIElementsUtilities.DefaultInset; | ||
|
||
UpdateResetsToNeutralFields(serializedObject.FindProperty(resetsToNeutralBindingPath).boolValue); | ||
UpdateSmoothResetFields(serializedObject.FindProperty(smoothResetBindingPath).boolValue); | ||
|
||
inspector.Add(UIElementsUtilities.VerticalSpace()); | ||
inspector.Add(new PropertyField(serializedObject.FindProperty(steeringChangedBindingPath))); | ||
|
||
return inspector; | ||
} | ||
|
||
/// <summary> | ||
/// <inheritdoc/> | ||
/// </summary> | ||
private void OnDestroy() | ||
{ | ||
if (resetsToNeutral != null) | ||
{ | ||
resetsToNeutral.UnregisterCallback<ChangeEvent<bool>>(ResetsToNeutral_ValueChanged); | ||
} | ||
|
||
if (smoothReset != null) | ||
{ | ||
smoothReset.UnregisterCallback<ChangeEvent<bool>>(SmoothReset_ValueChanged); | ||
} | ||
} | ||
|
||
private void ResetsToNeutral_ValueChanged(ChangeEvent<bool> changeEvent) => UpdateResetsToNeutralFields(changeEvent.newValue); | ||
|
||
private void UpdateResetsToNeutralFields(bool showFields) | ||
{ | ||
if (showFields) | ||
{ | ||
inspector.Add(smoothReset); | ||
smoothReset.PlaceInFront(resetsToNeutral); | ||
return; | ||
} | ||
|
||
if (inspector.Contains(smoothReset)) | ||
{ | ||
inspector.Remove(smoothReset); | ||
} | ||
|
||
if (inspector.Contains(smoothResetDuration)) | ||
{ | ||
inspector.Remove(smoothResetDuration); | ||
} | ||
} | ||
|
||
private void SmoothReset_ValueChanged(ChangeEvent<bool> changeEvent) => UpdateSmoothResetFields(changeEvent.newValue); | ||
|
||
private void UpdateSmoothResetFields(bool showFields) | ||
{ | ||
if (serializedObject.FindProperty(resetsToNeutralBindingPath).boolValue && showFields) | ||
{ | ||
inspector.Add(smoothResetDuration); | ||
smoothResetDuration.PlaceInFront(smoothReset); | ||
return; | ||
} | ||
|
||
if (inspector.Contains(smoothResetDuration)) | ||
{ | ||
inspector.Remove(smoothResetDuration); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.