ConstraintsInspector.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace RootMotion.FinalIK {
  5. /*
  6. * Custom inspector and scene view tools for Constraints
  7. * */
  8. public class ConstraintsInspector: IKSolverInspector {
  9. #region Public methods
  10. /*
  11. * Draws the custom inspector for Constraints
  12. * */
  13. public static void AddInspector(SerializedProperty prop) {
  14. if (!prop.isExpanded) return;
  15. // Main properties
  16. EditorGUILayout.PropertyField(prop.FindPropertyRelative("target"), new GUIContent("Target", "Target transform for the pelvis (optional). If assigned, will overwrite pelvis.position in each update."));
  17. EditorGUILayout.PropertyField(prop.FindPropertyRelative("positionOffset"), new GUIContent("Pos Offset", "Pelvis offset from animation. If there is no animation playing and Fix Transforms is unchecked, it will make the character fly away."));
  18. EditorGUILayout.PropertyField(prop.FindPropertyRelative("positionWeight"), new GUIContent("Pos Weight", "The weight of lerping the pelvis to bipedIK.solvers.pelvis.position."));
  19. EditorGUILayout.PropertyField(prop.FindPropertyRelative("rotationOffset"), new GUIContent("Rot Offset", "Pelvis rotation offset from animation. If there is no animation playing and Fix Transforms is unchecked, it will make the character spin."));
  20. EditorGUILayout.PropertyField(prop.FindPropertyRelative("rotationWeight"), new GUIContent("Rot Weight", "The weiight of slerping the pelvis to bipedIK.solver.pelvis.rotation."));
  21. EditorGUILayout.Space();
  22. }
  23. /*
  24. * Draws the scene view helpers for Constraints
  25. * */
  26. public static void AddScene(Constraints constraints, Color color, bool modifiable) {
  27. if (!constraints.IsValid()) return;
  28. Handles.color = color;
  29. GUI.color = color;
  30. // Transform
  31. Inspector.SphereCap(0, constraints.transform.position, Quaternion.identity, GetHandleSize(constraints.transform.position));
  32. // Target
  33. Handles.color = new Color(color.r, color.g, color.b, color.a * constraints.positionWeight);
  34. Handles.DrawLine(constraints.transform.position, constraints.position);
  35. Handles.color = color;
  36. if (Application.isPlaying && modifiable && (constraints.positionWeight > 0 || constraints.rotationWeight > 0)) {
  37. Inspector.CubeCap(0, constraints.position, Quaternion.Euler(constraints.rotation), GetHandleSize(constraints.transform.position));
  38. // Manipulating position and rotation
  39. switch(Tools.current) {
  40. case Tool.Move:
  41. constraints.position = Handles.PositionHandle(constraints.position, Quaternion.Euler(constraints.rotation));
  42. break;
  43. case Tool.Rotate:
  44. constraints.rotation = Handles.RotationHandle(Quaternion.Euler(constraints.rotation), constraints.position).eulerAngles;
  45. break;
  46. }
  47. }
  48. Handles.color = Color.white;
  49. GUI.color = Color.white;
  50. }
  51. #endregion Public methods
  52. }
  53. }