SwingArmModelEditor.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. #if ENABLE_VR || ENABLE_AR
  5. using UnityEngine.XR.LegacyInputHelpers;
  6. namespace UnityEditor.XR.LegacyInputHelpers
  7. {
  8. [CustomEditor(typeof(SwingArmModel))]
  9. internal class SwingArmModelEditor : ArmModelEditor
  10. {
  11. protected static class SwingArmModelStyles
  12. {
  13. public static GUIContent rotationRatioLabel = EditorGUIUtility.TrTextContent("Rotation Ratio");
  14. public static GUIContent shoulderRotationRatioLabel = EditorGUIUtility.TrTextContent("Shoulder", "Portion of controller rotation applied to the shoulder joint");
  15. public static GUIContent elbowRotationRatioLabel = EditorGUIUtility.TrTextContent("Elbow", "Portion of controller rotation applied to the elbow joint");
  16. public static GUIContent wristRotationRatioLabel = EditorGUIUtility.TrTextContent("Wrist", "Portion of controller rotation applied to the wrist joint");
  17. public static GUIContent shiftedRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Rotation Ratio");
  18. public static GUIContent shiftedShoulderRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Shoulder","Portion of controller rotation applied to the shoulder joint when the controller is backwards");
  19. public static GUIContent shiftedElbowRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Elbow", "Portion of controller rotation applied to the elbow joint when the controller is backwards");
  20. public static GUIContent shiftedWristRotationRatioLabel = EditorGUIUtility.TrTextContent("Shifted Wrist", "Portion of controller rotation applied to the wrist joint when the controller is backwards");
  21. public static GUIContent jointShiftAngleLabel = EditorGUIUtility.TrTextContent("Joint Shift Angle", "The min/max angle of the controller before starting to lerp towards the shifted joint ratios");
  22. public static GUIContent jointShiftExponentLabel = EditorGUIUtility.TrTextContent("Joint Shift Exponent", "Exponent applied to the joint shift ratio to control the curve of the shift");
  23. }
  24. SerializedProperty m_ShoulderRotationRatioProp = null;
  25. SerializedProperty m_EblowRotationRatioProp = null;
  26. SerializedProperty m_WristRotationRatioProp = null;
  27. SerializedProperty m_ShiftedShoulderRotationRatioProp = null;
  28. SerializedProperty m_ShiftedEblowRotationRatioProp = null;
  29. SerializedProperty m_ShiftedWristRotationRatioProp = null;
  30. SerializedProperty m_JointShiftAngleProp = null;
  31. SerializedProperty m_JointShiftExponentProp = null;
  32. bool m_ExpandShoulder = false;
  33. bool m_ExpandShiftedShoulder = false;
  34. protected override void OnEnable()
  35. {
  36. base.OnEnable();
  37. m_ShoulderRotationRatioProp = this.serializedObject.FindProperty("m_ShoulderRotationRatio");
  38. m_EblowRotationRatioProp = this.serializedObject.FindProperty("m_ElbowRotationRatio");
  39. m_WristRotationRatioProp = this.serializedObject.FindProperty("m_WristRotationRatio");
  40. m_ShiftedShoulderRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedShoulderRotationRatio");
  41. m_ShiftedEblowRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedElbowRotationRatio");
  42. m_ShiftedWristRotationRatioProp = this.serializedObject.FindProperty("m_ShiftedWristRotationRatio");
  43. m_JointShiftAngleProp = this.serializedObject.FindProperty("m_JointShiftAngle");
  44. m_JointShiftExponentProp = this.serializedObject.FindProperty("m_JointShiftExponent");
  45. }
  46. public override void OnInspectorGUI()
  47. {
  48. serializedObject.Update();
  49. EditorGUILayout.PropertyField(m_PoseSourceProp, ArmModelStyles.poseSourceLabel);
  50. EditorGUILayout.PropertyField(m_HeadGameObjectProp, ArmModelStyles.headPositionSourceLabel);
  51. EditorGUILayout.PropertyField(m_ArmExtensionOffsetProp, ArmModelStyles.armExtensionOffsetLabel);
  52. EditorGUILayout.PropertyField(m_JointShiftAngleProp, SwingArmModelStyles.jointShiftAngleLabel);
  53. EditorGUILayout.PropertyField(m_JointShiftExponentProp, SwingArmModelStyles.jointShiftExponentLabel);
  54. EditorGUILayout.PropertyField(m_ElbowBendRatioProp, ArmModelStyles.elbowBendRatioLabel);
  55. EditorGUILayout.PropertyField(m_IsLockedToNeckProp, ArmModelStyles.isLockedToNeckLabel);
  56. m_ExpandRestPosition = EditorGUILayout.Foldout(m_ExpandRestPosition, ArmModelStyles.restPositionLabel);
  57. if (m_ExpandRestPosition)
  58. {
  59. using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
  60. {
  61. EditorGUILayout.PropertyField(m_EblowRestPositionProp, ArmModelStyles.elbowRestPositionLabel);
  62. EditorGUILayout.PropertyField(m_WristRestPositionProp, ArmModelStyles.wristRestPositionLabel);
  63. EditorGUILayout.PropertyField(m_ControllerRestPositionProp, ArmModelStyles.controllerRestPositionLabel);
  64. }
  65. }
  66. m_ExpandShoulder = EditorGUILayout.Foldout(m_ExpandShoulder, SwingArmModelStyles.rotationRatioLabel);
  67. if (m_ExpandShoulder)
  68. {
  69. using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
  70. {
  71. EditorGUILayout.PropertyField(m_ShoulderRotationRatioProp, SwingArmModelStyles.shoulderRotationRatioLabel);
  72. EditorGUILayout.PropertyField(m_EblowRotationRatioProp, SwingArmModelStyles.elbowRotationRatioLabel);
  73. EditorGUILayout.PropertyField(m_WristRotationRatioProp, SwingArmModelStyles.wristRotationRatioLabel);
  74. }
  75. }
  76. m_ExpandShiftedShoulder = EditorGUILayout.Foldout(m_ExpandShiftedShoulder, SwingArmModelStyles.shiftedRotationRatioLabel);
  77. if (m_ExpandShiftedShoulder)
  78. {
  79. using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
  80. {
  81. EditorGUILayout.PropertyField(m_ShiftedShoulderRotationRatioProp, SwingArmModelStyles.shiftedShoulderRotationRatioLabel);
  82. EditorGUILayout.PropertyField(m_ShiftedEblowRotationRatioProp, SwingArmModelStyles.shiftedElbowRotationRatioLabel);
  83. EditorGUILayout.PropertyField(m_ShiftedWristRotationRatioProp, SwingArmModelStyles.shiftedWristRotationRatioLabel);
  84. }
  85. }
  86. serializedObject.ApplyModifiedProperties();
  87. }
  88. }
  89. }
  90. #endif