Skip to content

Commit

Permalink
feat(Structure): provide custom data types to convey better meaning
Browse files Browse the repository at this point in the history
  > **Breaking Changes**

In a number of scripts, standard data types were being used but created
confusion in meaning, such as using a `Vector2` for a min/max range as
this would then display in the editor as `x` and `y` values, with `x`
being minimum and the `y` being maximum.

This has now been replaced with a new `Limits2D` data type that
displays the same 2 float input boxes as a `Vector2` but instead uses
the labels of `min` and `max` which makes a lot more sense.

The `Limits2D` data type can also have a new custom attribute applied
to it called `[MinMaxRange]` which works in a similar way to `[Range]`
but it provides 2 slider points that can be dragged to set a minimum
and maximum value for the control. It should also work with a Vector2
if required.

The Axis Scale Grab Action has also been updated to use the new
Vector3State data type when determining which axes should be locked
for scaling. This is in place of the previous 3 separate boolean
parameters.
  • Loading branch information
thestonefox committed Nov 3, 2017
1 parent f9e4ba1 commit ef35e19
Show file tree
Hide file tree
Showing 27 changed files with 595 additions and 167 deletions.
33 changes: 14 additions & 19 deletions Assets/VRTK/Documentation/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5618,9 +5618,9 @@ Moves the Transform of the Interactable Object towards the interacting object wi
* **Force Kinematic On Grab:** If this is checked then it will force the rigidbody on the Interactable Object to be `Kinematic` when the grab occurs.
* **Release Deceleration Damper:** The damper in which to slow the Interactable Object down when released to simulate continued momentum. The higher the number, the faster the Interactable Object will come to a complete stop on release.
* **Reset To Orign On Release Speed:** The speed in which the Interactable Object returns to it's origin position when released. If the `Reset To Orign On Release Speed` is `0f` then the position will not be reset.
* **X Axis Limits:** The minimum (`x`) and maximum (`y`) limits the Interactable Object can be moved along the x axis.
* **Y Axis Limits:** The minimum (`x`) and maximum (`y`) limits the Interactable Object can be moved along the y axis.
* **Z Axis Limits:** The minimum (`x`) and maximum (`y`) limits the Interactable Object can be moved along the z axis.
* **X Axis Limits:** The minimum and maximum limits the Interactable Object can be moved along the x axis.
* **Y Axis Limits:** The minimum and maximum limits the Interactable Object can be moved along the y axis.
* **Z Axis Limits:** The minimum and maximum limits the Interactable Object can be moved along the z axis.
* **Min Max Threshold:** The threshold the position value needs to be within to register a min or max position value.
* **Min Max Normalized Threshold:** The threshold the normalized position value needs to be within to register a min or max normalized position value.

Expand Down Expand Up @@ -5778,12 +5778,12 @@ The ResetPosition method will move the Interactable Object back to the origin po

#### GetWorldLimits/0

> `public virtual Vector2[] GetWorldLimits()`
> `public virtual Limits2D[] GetWorldLimits()`

* Parameters
* _none_
* Returns
* `Vector2[]` - An array of axis limits in world space.
* `Limits2D[]` - An array of axis limits in world space.

The GetWorldLimits method returns an array of minimum and maximum axis limits for the Interactable Object in world space.

Expand Down Expand Up @@ -5812,7 +5812,7 @@ Rotates the Transform of the Interactable Object around a specified transform lo
* **Rotation Friction:** The amount of friction to apply when rotating, simulates a tougher rotation.
* **Release Deceleration Damper:** The damper in which to slow the Interactable Object's rotation down when released to simulate continued momentum. The higher the number, the faster the Interactable Object will come to a complete stop on release.
* **Reset To Orign On Release Speed:** The speed in which the Interactable Object returns to it's origin rotation when released. If the `Reset To Orign On Release Speed` is `0f` then the rotation will not be reset.
* **Angle Limits:** The negative `(x)` and positive `(y)` limits the axis can be rotated to.
* **Angle Limits:** The negative and positive limits the axis can be rotated to.
* **Min Max Threshold:** The threshold the rotation value needs to be within to register a min or max rotation value.
* **Min Max Normalized Threshold:** The threshold the normalized rotation value needs to be within to register a min or max normalized rotation value.

Expand Down Expand Up @@ -6083,9 +6083,7 @@ Scales the grabbed Interactable Object along the given axes based on the positio
### Inspector Parameters

* **Ungrab Distance:** The distance the secondary grabbing object must move away from the original grab position before the secondary grabbing object auto ungrabs the Interactable Object.
* **Lock X Axis:** If checked the current X Axis of the Interactable Object won't be scaled
* **Lock Y Axis:** If checked the current Y Axis of the Interactable Object won't be scaled
* **Lock Z Axis:** If checked the current Z Axis of the Interactable Object won't be scaled
* **Lock Axis:** Locks the specified checked axes so they won't be scaled
* **Uniform Scaling:** If checked all the axes will be scaled together (unless locked)

### Class Methods
Expand Down Expand Up @@ -6506,14 +6504,13 @@ A physics based rotatable object.
### Inspector Parameters

* **Hinge Point:** A Transform that denotes the position where the rotator hinge will be created.
* **Minimum Angle:** The minimum angle the rotator can rotate to.
* **Maximum Angle:** The maximum angle the rotator can rotate to.
* **Angle Limits:** The minimum and maximum angle the rotator can rotate to.
* **Min Max Threshold Angle:** The angle at which the rotator rotation can be within the minimum or maximum angle before the minimum or maximum angles are considered reached.
* **Resting Angle:** The angle at which will be considered as the resting position of the rotator.
* **Force Resting Angle Threshold:** The threshold angle from the `Resting Angle` that the current angle of the rotator needs to be within to snap the rotator back to the `Resting Angle`.
* **Angle Target:** The target angle to rotate the rotator to.
* **Is Locked:** If this is checked then the rotator Rigidbody will have all rotations frozen.
* **Step Value Range:** The minimum `(x)` and the maximum `(y)` step values for the rotator to register along the `Operate Axis`.
* **Step Value Range:** The minimum and the maximum step values for the rotator to register along the `Operate Axis`.
* **Step Size:** The increments the rotator value will change in between the `Step Value Range`.
* **Use Step As Value:** If this is checked then the value for the rotator will be the step value and not the absolute rotation of the rotator Transform.
* **Snap To Step:** If this is checked then the rotator will snap to the angle of the nearest step along the value range.
Expand Down Expand Up @@ -6662,7 +6659,7 @@ A physics based slider.
* **Position Target:** The target position to move the slider towards given in a normalized value of `0f` (start point) to `1f` (end point).
* **Resting Position:** The position the slider when it is at the default resting point given in a normalized value of `0f` (start point) to `1f` (end point).
* **Force Resting Position Threshold:** The normalized threshold value the slider has to be within the `Resting Position` before the slider is forced back to the `Resting Position` if it is not grabbed.
* **Step Value Range:** The minimum `(x)` and the maximum `(y)` step values for the slider to register along the `Operate Axis`.
* **Step Value Range:** The minimum and the maximum step values for the slider to register along the `Operate Axis`.
* **Step Size:** The increments the slider value will change in between the `Step Value Range`.
* **Use Step As Value:** If this is checked then the value for the slider will be the step value and not the absolute position of the slider Transform.
* **Snap To Step:** If this is checked then the slider will snap to the position of the nearest step along the value range.
Expand Down Expand Up @@ -6888,13 +6885,12 @@ A artificially simulated openable rotator.
### Inspector Parameters

* **Hinge Point:** A Transform that denotes the position where the rotator will rotate around.
* **Minimum Angle:** The minimum angle the rotator can rotate to.
* **Maximum Angle:** The maximum angle the rotator can rotate to.
* **Angle Limits:** The minimum and maximum angle the rotator can rotate to.
* **Min Max Threshold Angle:** The angle at which the rotator rotation can be within the minimum or maximum angle before the minimum or maximum angles are considered reached.
* **Resting Angle:** The angle at which will be considered as the resting position of the rotator.
* **Force Resting Angle Threshold:** The threshold angle from the `Resting Angle` that the current angle of the rotator needs to be within to snap the rotator back to the `Resting Angle`.
* **Is Locked:** If this is checked then the rotator Rigidbody will have all rotations frozen.
* **Step Value Range:** The minimum `(x)` and the maximum `(y)` step values for the rotator to register along the `Operate Axis`.
* **Step Value Range:** The minimum and the maximum step values for the rotator to register along the `Operate Axis`.
* **Step Size:** The increments the rotator value will change in between the `Step Value Range`.
* **Use Step As Value:** If this is checked then the value for the rotator will be the step value and not the absolute rotation of the rotator Transform.
* **Snap To Step:** If this is checked then the rotator will snap to the angle of the nearest step along the value range.
Expand Down Expand Up @@ -7042,7 +7038,7 @@ A artificially simulated slider.
* **Min Max Threshold:** The normalized position the slider can be within the minimum or maximum slider positions before the minimum or maximum positions are considered reached.
* **Resting Position:** The position the slider when it is at the default resting point given in a normalized value of `0f` (start point) to `1f` (end point).
* **Force Resting Position Threshold:** The normalized threshold value the slider has to be within the `Resting Position` before the slider is forced back to the `Resting Position` if it is not grabbed.
* **Step Value Range:** The minimum `(x)` and the maximum `(y)` step values for the slider to register along the `Operate Axis`.
* **Step Value Range:** The minimum and the maximum step values for the slider to register along the `Operate Axis`.
* **Step Size:** The increments the slider value will change in between the `Step Value Range`.
* **Use Step As Value:** If this is checked then the value for the slider will be the step value and not the absolute position of the slider Transform.
* **Snap To Step:** If this is checked then the slider will snap to the position of the nearest step along the value range.
Expand Down Expand Up @@ -9275,8 +9271,7 @@ In more detail:
* `-msaa X`: Set MSAA level to X
* **Msaa Level:** The MSAA level to use.
* **Scale Render Viewport:** Toggles whether the render viewport scale is dynamically adjusted to maintain VR framerate. If unchecked, the renderer will render at the recommended resolution provided by the current `VRDevice`.
* **Minimum Render Scale:** The minimum allowed render scale.
* **Maximum Render Scale:** The maximum allowed render scale.
* **Render Scale Limits:** The minimum and maximum allowed render scale.
* **Maximum Render Target Dimension:** The maximum allowed render target dimension. This puts an upper limit on the size of the render target regardless of the maximum render scale.
* **Render Scale Fill Rate Step Size In Percent:** The fill rate step size in percent by which the render scale levels will be calculated.
* **Scale Render Target Resolution:** Toggles whether the render target resolution is dynamically adjusted to maintain VR framerate. If unchecked, the renderer will use the maximum target resolution specified by `maximumRenderScale`.
Expand Down

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

9 changes: 9 additions & 0 deletions Assets/VRTK/Source/Editor/Attributes.meta

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

78 changes: 78 additions & 0 deletions Assets/VRTK/Source/Editor/Attributes/MinMaxRangeDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using UnityEngine;
using UnityEditor;
using System.Globalization;
using Supyrb;
using VRTK;

[CustomPropertyDrawer(typeof(MinMaxRangeAttribute))]
class MinMaxRangeDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
label.tooltip = VRTK_EditorUtilities.GetTooltipAttribute(fieldInfo).tooltip;
bool foundGeneric = false;
bool valid = false;
try
{
Vector2 input = SerializedPropertyExtensions.GetValue<Limits2D>(property).AsVector2();
Vector2 output = BuildSlider(position, label, input, out valid);
if (valid)
{
SerializedPropertyExtensions.SetValue<Limits2D>(property, new Limits2D(output));
}
foundGeneric = true;
}
catch (System.Exception)
{
Error(position, label);
}

if (!foundGeneric)
{
switch (property.propertyType)
{
case SerializedPropertyType.Vector2:
Vector2 input = property.vector2Value;
Vector2 output = BuildSlider(position, label, input, out valid);
if (valid)
{
property.vector2Value = output;
}
break;
default:
Error(position, label);
break;
}
}
}

private Vector2 BuildSlider(Rect position, GUIContent label, Vector2 range, out bool valid)
{
float fieldWidth = GUI.skin.textField.CalcSize(new GUIContent(1.234f.ToString(CultureInfo.InvariantCulture))).x; ;
float fieldPadding = 5f;
float min = range.x;
float max = range.y;

MinMaxRangeAttribute attr = attribute as MinMaxRangeAttribute;
EditorGUI.BeginChangeCheck();
Rect updatedPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
min = EditorGUI.FloatField(new Rect(updatedPosition.x, updatedPosition.y, fieldWidth, updatedPosition.height), Mathf.Clamp(min, attr.min, attr.max));
EditorGUI.MinMaxSlider(new Rect(updatedPosition.x + (fieldWidth + fieldPadding), updatedPosition.y, updatedPosition.width - ((fieldWidth + fieldPadding) * 2f), updatedPosition.height), ref min, ref max, attr.min, attr.max);
max = EditorGUI.FloatField(new Rect(updatedPosition.x + (updatedPosition.width - fieldWidth), updatedPosition.y, fieldWidth, updatedPosition.height), Mathf.Clamp(max, attr.min, attr.max));

if (EditorGUI.EndChangeCheck())
{
range.x = min;
range.y = max;
valid = true;
return range;
}
valid = false;
return Vector2.zero;
}

private void Error(Rect position, GUIContent label)
{
EditorGUI.LabelField(position, label, new GUIContent("Use only with Vector2 or Limits2D"));
}
}
12 changes: 12 additions & 0 deletions Assets/VRTK/Source/Editor/Attributes/MinMaxRangeDrawer.cs.meta

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

33 changes: 33 additions & 0 deletions Assets/VRTK/Source/Editor/DataTypes/Limits2DDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using UnityEngine;
using UnityEditor;
using VRTK;

[CustomPropertyDrawer(typeof(Limits2D))]
public class Limits2DDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
label.tooltip = VRTK_EditorUtilities.GetTooltipAttribute(fieldInfo).tooltip;
SerializedProperty minimum = property.FindPropertyRelative("minimum");
SerializedProperty maximum = property.FindPropertyRelative("maximum");

int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
float updatePositionX = position.x;
float labelWidth = 30f;
float fieldWidth = (position.width / 3f) - labelWidth;

EditorGUI.LabelField(new Rect(updatePositionX, position.y, labelWidth, position.height), "Min");
updatePositionX += labelWidth;
minimum.floatValue = EditorGUI.FloatField(new Rect(updatePositionX, position.y, fieldWidth, position.height), minimum.floatValue);
updatePositionX += fieldWidth;

EditorGUI.LabelField(new Rect(updatePositionX, position.y, labelWidth, position.height), "Max");
updatePositionX += labelWidth;
maximum.floatValue = EditorGUI.FloatField(new Rect(updatePositionX, position.y, fieldWidth, position.height), maximum.floatValue);
updatePositionX += fieldWidth;

EditorGUI.indentLevel = indent;
}
}
12 changes: 12 additions & 0 deletions Assets/VRTK/Source/Editor/DataTypes/Limits2DDrawer.cs.meta

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

2 changes: 2 additions & 0 deletions Assets/VRTK/Source/Editor/DataTypes/Vector3StateDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using UnityEngine;
using UnityEditor;
using VRTK;

[CustomPropertyDrawer(typeof(Vector3State))]
public class Vector3StateDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
label.tooltip = VRTK_EditorUtilities.GetTooltipAttribute(fieldInfo).tooltip;
SerializedProperty xState = property.FindPropertyRelative("xState");
SerializedProperty yState = property.FindPropertyRelative("yState");
SerializedProperty zState = property.FindPropertyRelative("zState");
Expand Down
Loading

0 comments on commit ef35e19

Please sign in to comment.