Skip to content

Commit

Permalink
VectorproperyDrawer.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitGeslain committed Mar 11, 2024
1 parent 8439338 commit d342931
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using UnityEditor;

using System.Collections.Generic;
using VHToolkit.Redirection.WorldRedirection;
using VHToolkit.Redirection.PseudoHaptics;

namespace VHToolkit.Redirection.BodyRedirection {
Expand Down Expand Up @@ -45,6 +44,10 @@ private void OnEnable() {
parametersObject = new SerializedObject(parameters.objectReferenceValue);
}

private void MakePropertyField(SerializedProperty property, string text, string tooltip = null) {
EditorGUILayout.PropertyField(property, new GUIContent(text, tooltip));
}

public override void OnInspectorGUI() {
GUI.enabled = false;
EditorGUILayout.ObjectField("Script:", MonoScript.FromMonoBehaviour((BodyRedirection)target), typeof(BodyRedirection), false);
Expand All @@ -56,25 +59,24 @@ public override void OnInspectorGUI() {
EditorGUILayout.LabelField("User Parameters", EditorStyles.largeLabel);

// Scene
EditorGUILayout.PropertyField(physicalLimbs, new GUIContent("Physical Limbs"));
MakePropertyField(physicalLimbs, "Physical Limbs", "The Transform of the user's limbs tracked by the VR SDK");

// EditorGUILayout.PropertyField(virtualLimbs, new GUIContent("Virtual Limbs"));
if (technique.enumNames[technique.enumValueIndex] == nameof(Azmandian2016Hybrid)) {
EditorGUILayout.PropertyField(physicalHead, new GUIContent("Physical Head"));
EditorGUILayout.PropertyField(virtualHead, new GUIContent("Virtual Head"));
}
else if (technique.enumNames[technique.enumValueIndex] == nameof(Poupyrev1996GoGo)) {
EditorGUILayout.PropertyField(physicalHead, new GUIContent("Physical Head"));
MakePropertyField(physicalHead, "Physical Head", "The Transform of the VR headset worn by the user.");
MakePropertyField(virtualHead, "Virtual Head", "");
} else if (technique.enumNames[technique.enumValueIndex] == nameof(Poupyrev1996GoGo)) {
MakePropertyField(physicalHead, "Physical Head", "");
}


EditorGUILayout.Space(5);
EditorGUILayout.LabelField("Technique Parameters", EditorStyles.largeLabel);

EditorGUILayout.PropertyField(technique, new GUIContent("Redirection technique"));
MakePropertyField(technique, "Redirection technique", "");

EditorGUILayout.PropertyField(redirect, new GUIContent("Activate Redirection"));
EditorGUILayout.PropertyField(parameters, new GUIContent("Numerical Parameters"));
MakePropertyField(redirect, "Activate Redirection", "");
MakePropertyField(parameters, "Numerical Parameters", "");

// If no parameters Scriptable object, update object and don't render the rest of the view
if (parameters.objectReferenceValue == null) {
Expand All @@ -85,9 +87,9 @@ public override void OnInspectorGUI() {
parametersObject = new SerializedObject(parameters.objectReferenceValue);
parametersObject.Update();

EditorGUILayout.PropertyField(physicalTarget, new GUIContent("Physical Target"));
EditorGUILayout.PropertyField(virtualTarget, new GUIContent("Virtual Target"));
EditorGUILayout.PropertyField(origin, new GUIContent("Origin"));
MakePropertyField(physicalTarget, "Physical Target", "");
MakePropertyField(virtualTarget, "Virtual Target", "");
MakePropertyField(origin, "Origin", "");

// Hides redirectionLateness and controlpoint fields if the technique is not Geslain2022Polynom
if (technique.enumNames[technique.enumValueIndex] == nameof(Geslain2022Polynom)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using UnityEngine;
using UnityEditor;

using VHToolkit.Redirection;

[CustomPropertyDrawer(typeof(Vector2Horizontal))]
public class Vector2HorizontalPropertyDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

var width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 50;
var leftRect = new Rect(position.x, position.y, 125, position.height);
var rightRect = new Rect(position.x + 130, position.y, 100, position.height);

EditorGUI.PropertyField(leftRect, property.FindPropertyRelative("left"), new GUIContent("Left"));
EditorGUI.PropertyField(rightRect, property.FindPropertyRelative("right"), new GUIContent("Right"));

EditorGUI.EndProperty();
}
}

[CustomPropertyDrawer(typeof(Vector2Vertical))]
public class Vector2VerticalPropertyDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

var width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 50;
var leftRect = new Rect(position.x, position.y, 125, position.height);
var rightRect = new Rect(position.x + 130, position.y, 100, position.height);

EditorGUI.PropertyField(leftRect, property.FindPropertyRelative("up"), new GUIContent("Up"));
EditorGUI.PropertyField(rightRect, property.FindPropertyRelative("down"), new GUIContent("Down"));

EditorGUI.EndProperty();
}
}

[CustomPropertyDrawer(typeof(Vector2Gain))]
public class Vector2GainPropertyDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

var width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 50;
var leftRect = new Rect(position.x, position.y, 125, position.height);
var rightRect = new Rect(position.x + 130, position.y, 100, position.height);

EditorGUI.PropertyField(leftRect, property.FindPropertyRelative("forward"), new GUIContent("Forward"));
EditorGUI.PropertyField(rightRect, property.FindPropertyRelative("backward"), new GUIContent("Backward"));

EditorGUI.EndProperty();
}
}

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
@@ -1,5 +1,4 @@
namespace VHToolkit.Redirection
{
namespace VHToolkit.Redirection {
/// <summary>
/// Wrapper for a pair of <c>float</c> associated with left and right.
/// </summary>
Expand Down

0 comments on commit d342931

Please sign in to comment.