Skip to content

Commit

Permalink
Created a test scene, completed hinge joint editor
Browse files Browse the repository at this point in the history
  • Loading branch information
AquaGeneral committed Nov 14, 2017
1 parent 67338a1 commit e65681b
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Editor/EnjoinedConfigurableJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public override void OnInspectorGUI() {
/**
* Linear Limit
*/
if(joint.xMotion != ConfigurableJointMotion.Limited && joint.yMotion != ConfigurableJointMotion.Limited && joint.zMotion != ConfigurableJointMotion.Limited) {
if(joint.xMotion != ConfigurableJointMotion.Limited && joint.yMotion != ConfigurableJointMotion.Limited && joint.zMotion != ConfigurableJointMotion.Limited &&
(joint.linearLimit.limit != 0f || joint.linearLimit.bounciness != 0f || joint.linearLimit.contactDistance != 0f || joint.linearLimitSpring.spring != 0f ||
joint.linearLimitSpring.damper != 0f)) {
EditorGUILayout.HelpBox("The following linear limits are only used when at least one axis of Linear Motion is set to Limited", MessageType.Info);
}

Expand Down
46 changes: 35 additions & 11 deletions Editor/EnjoinedHingeJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,38 @@ namespace JesseStiller.Enjoined {
[CanEditMultipleObjects]
[CustomEditor(typeof(HingeJoint))]
public class EnjoinedHingeJoint : Editor {
private SerializedProperty connectedAnchor, autoConfigureConnectedAnchor, useSpring, spring;
private SerializedProperty connectedAnchor, autoConfigureConnectedAnchor, useSpring, spring, useMotor, motor, useLimits, limits;

private void OnEnable() {
connectedAnchor = serializedObject.FindProperty("m_ConnectedAnchor");
autoConfigureConnectedAnchor = serializedObject.FindProperty("m_AutoConfigureConnectedAnchor");
useSpring = serializedObject.FindProperty("m_UseSpring");
spring = serializedObject.FindProperty("m_Spring");
useMotor = serializedObject.FindProperty("m_UseMotor");
motor = serializedObject.FindProperty("m_Motor");
useLimits = serializedObject.FindProperty("m_UseLimits");
limits = serializedObject.FindProperty("m_Limits");
}

public override void OnInspectorGUI() {
base.OnInspectorGUI();

GUILayout.Space(20f);

/**
* Currently the only difference is that the connectedAnchor vector field is greyed out if autoConfigureConnectedAnchor is true
*/
serializedObject.Update();
SerializedProperty iterator = serializedObject.GetIterator();
for(bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) {
SubPropertyOperator subPropertyOperator;

switch(iterator.propertyPath) {
case "m_AutoConfigureConnectedAnchor":
break;
case "m_ConnectedAnchor":
GUIUtilities.DrawConnectedAnchorProperty(connectedAnchor, autoConfigureConnectedAnchor);
break;
case "m_UseSpring":
useSpring.boolValue = EditorGUILayout.ToggleLeft("Spring", useSpring.boolValue);
useSpring.boolValue = EditorGUILayout.Toggle("Spring", useSpring.boolValue);
break;
case "m_Spring":
EditorGUI.indentLevel = 1;
SubPropertyOperator subPropertyOperator = new SubPropertyOperator(iterator);
subPropertyOperator = new SubPropertyOperator(iterator);
while(subPropertyOperator.MoveNext()) {
Debug.Log(subPropertyOperator.iterator.propertyPath);
switch(subPropertyOperator.iterator.propertyPath) {
case "m_Spring.spring":
EditorGUILayout.PropertyField(subPropertyOperator.iterator, new GUIContent("Force"));
Expand All @@ -54,7 +52,33 @@ public override void OnInspectorGUI() {
}
}
EditorGUI.indentLevel = 0;
break;
case "m_UseMotor":
useMotor.boolValue = EditorGUILayout.Toggle("Motor", useMotor.boolValue);
break;
case "m_Motor":
EditorGUI.indentLevel = 1;
GUIUtilities.PropertyFieldWithoutHeader(motor);
EditorGUI.indentLevel = 0;
break;
case "m_UseLimits":
useLimits.boolValue = EditorGUILayout.Toggle("Limits", useLimits.boolValue);
break;
case "m_Limits":
EditorGUI.indentLevel = 1;
subPropertyOperator = new SubPropertyOperator(iterator);
while(subPropertyOperator.MoveNext()) {
EditorGUILayout.PropertyField(subPropertyOperator.iterator);

// Clamp the min and max limit properties only to -180 to 180
switch(subPropertyOperator.iterator.propertyPath) {
case "m_Limits.min":
case "m_Limits.max":
subPropertyOperator.iterator.floatValue = Mathf.Clamp(subPropertyOperator.iterator.floatValue, -180f, 180f);
break;
}
}
EditorGUI.indentLevel = 0;
break;
default:
EditorGUILayout.PropertyField(iterator, true, null);
Expand Down
2 changes: 1 addition & 1 deletion Editor/GUIUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JesseStiller.Enjoined {
public static class GUIUtilities {
private static readonly GUIContent[] anchorTypesGUIContent = new GUIContent[] { new GUIContent("User"), new GUIContent("Automatic") };
private static readonly GUIContent[] anchorTypesGUIContent = new GUIContent[] { new GUIContent("Custom"), new GUIContent("Automatic") };

public static void DrawConnectedAnchorProperty(SerializedProperty connectedAnchor, SerializedProperty autoConfigureConnectedAnchor) {
Rect controlRect = EditorGUILayout.GetControlRect();
Expand Down
Loading

0 comments on commit e65681b

Please sign in to comment.