ArmModelEditor.cs 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(ArmModel))]
  9. internal class ArmModelEditor : Editor
  10. {
  11. protected static class ArmModelStyles
  12. {
  13. public static GUIContent poseSourceLabel = EditorGUIUtility.TrTextContent("Input Pose Source", "The source of the 3dof controller data");
  14. public static GUIContent headPositionSourceLabel = EditorGUIUtility.TrTextContent("Head Position Source", "The source of head position data used by the arm model");
  15. public static GUIContent isLockedToNeckLabel = EditorGUIUtility.TrTextContent("Lock To Neck", "If true, the root of the pose is locked to the local position of the player's neck");
  16. public static GUIContent armExtensionOffsetLabel = EditorGUIUtility.TrTextContent("Arm Extension Offset", "Offset applied to the elbow position as the controller is rotated upwards");
  17. public static GUIContent elbowBendRatioLabel = EditorGUIUtility.TrTextContent("Elbow Bend Ratio", "Amount of the controller's rotation to apply to the elbow");
  18. public static GUIContent elbowRestPositionLabel = EditorGUIUtility.TrTextContent("Elbow","The Elbow's Position relative to the users head");
  19. public static GUIContent wristRestPositionLabel = EditorGUIUtility.TrTextContent("Wrist","The Wrist's Position relative to the users head");
  20. public static GUIContent controllerRestPositionLabel = EditorGUIUtility.TrTextContent("Controller", "The Controller position relative to the users head");
  21. public static GUIContent restPositionLabel = EditorGUIUtility.TrTextContent("Rest Position");
  22. }
  23. protected SerializedProperty m_PoseSourceProp = null;
  24. protected SerializedProperty m_HeadGameObjectProp = null;
  25. protected SerializedProperty m_IsLockedToNeckProp = null;
  26. protected SerializedProperty m_ArmExtensionOffsetProp = null;
  27. protected SerializedProperty m_EblowRestPositionProp = null;
  28. protected SerializedProperty m_WristRestPositionProp = null;
  29. protected SerializedProperty m_ControllerRestPositionProp = null;
  30. protected SerializedProperty m_ElbowBendRatioProp = null;
  31. protected bool m_ExpandRestPosition = false;
  32. protected virtual void OnEnable()
  33. {
  34. m_PoseSourceProp = this.serializedObject.FindProperty("m_PoseSource");
  35. m_HeadGameObjectProp = this.serializedObject.FindProperty("m_HeadPoseSource");
  36. m_IsLockedToNeckProp = this.serializedObject.FindProperty("m_IsLockedToNeck");
  37. m_ArmExtensionOffsetProp = this.serializedObject.FindProperty("m_ElbowRestPosition");
  38. m_EblowRestPositionProp = this.serializedObject.FindProperty("m_ElbowRestPosition");
  39. m_WristRestPositionProp = this.serializedObject.FindProperty("m_WristRestPosition");
  40. m_ControllerRestPositionProp = this.serializedObject.FindProperty("m_ControllerRestPosition");
  41. m_ElbowBendRatioProp = this.serializedObject.FindProperty("m_ElbowBendRatio");
  42. }
  43. public override void OnInspectorGUI()
  44. {
  45. serializedObject.Update();
  46. EditorGUILayout.PropertyField(m_PoseSourceProp, ArmModelStyles.poseSourceLabel);
  47. EditorGUILayout.PropertyField(m_HeadGameObjectProp, ArmModelStyles.headPositionSourceLabel);
  48. EditorGUILayout.PropertyField(m_ArmExtensionOffsetProp, ArmModelStyles.armExtensionOffsetLabel);
  49. EditorGUILayout.PropertyField(m_ElbowBendRatioProp, ArmModelStyles.elbowBendRatioLabel);
  50. EditorGUILayout.PropertyField(m_IsLockedToNeckProp, ArmModelStyles.isLockedToNeckLabel);
  51. m_ExpandRestPosition = EditorGUILayout.Foldout(m_ExpandRestPosition,ArmModelStyles.restPositionLabel);
  52. if (m_ExpandRestPosition)
  53. {
  54. using (EditorGUI.IndentLevelScope indent = new EditorGUI.IndentLevelScope())
  55. {
  56. EditorGUILayout.PropertyField(m_EblowRestPositionProp, ArmModelStyles.elbowRestPositionLabel);
  57. EditorGUILayout.PropertyField(m_WristRestPositionProp, ArmModelStyles.wristRestPositionLabel);
  58. EditorGUILayout.PropertyField(m_ControllerRestPositionProp, ArmModelStyles.controllerRestPositionLabel);
  59. }
  60. }
  61. serializedObject.ApplyModifiedProperties();
  62. }
  63. }
  64. }
  65. #endif