RotationLimitInspector.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Collections;
  4. namespace RootMotion.FinalIK
  5. {
  6. /*
  7. * Base class for all RotationLimitInspector containing common helper methods and drawing instructions
  8. * */
  9. public class RotationLimitInspector : Editor
  10. {
  11. #region Public methods
  12. // Universal color pallettes
  13. public static Color colorDefault { get { return new Color(0.0f, 1.0f, 1.0f, 1.0f); } }
  14. public static Color colorDefaultTransparent
  15. {
  16. get
  17. {
  18. Color d = colorDefault;
  19. return new Color(d.r, d.g, d.b, 0.2f);
  20. }
  21. }
  22. public static Color colorHandles { get { return new Color(1.0f, 0.5f, 0.25f, 1.0f); } }
  23. public static Color colorRotationSphere { get { return new Color(1.0f, 1.0f, 1.0f, 0.1f); } }
  24. public static Color colorInvalid { get { return new Color(1.0f, 0.3f, 0.3f, 1.0f); } }
  25. public static Color colorValid { get { return new Color(0.2f, 1.0f, 0.2f, 1.0f); } }
  26. /*
  27. * Draws the default rotation limit sphere to the scene
  28. * */
  29. public static void DrawRotationSphere(Vector3 position)
  30. {
  31. Handles.color = colorRotationSphere;
  32. Inspector.SphereCap(0, position, Quaternion.identity, 2.0f);
  33. Handles.color = Color.white;
  34. }
  35. /*
  36. * Draws a custom arrow to the scene
  37. * */
  38. public static void DrawArrow(Vector3 position, Vector3 direction, Color color, string label = "", float size = 0.01f)
  39. {
  40. Handles.color = color;
  41. Handles.DrawLine(position, position + direction);
  42. Inspector.SphereCap(0, position + direction, Quaternion.identity, size);
  43. Handles.color = Color.white;
  44. if (label != "")
  45. {
  46. GUI.color = color;
  47. Handles.Label(position + direction, label);
  48. GUI.color = Color.white;
  49. }
  50. }
  51. /*
  52. * Draws a handle for adjusting rotation limits in the scene
  53. * */
  54. public static float DrawLimitHandle(float limit, Vector3 position, Quaternion rotation, float radius, string label, float openingValue)
  55. {
  56. limit = Inspector.ScaleValueHandleSphere(limit, position, rotation, radius, 1);
  57. string labelInfo = label + ": " + limit.ToString();
  58. // If value is 0, draw a button to 'open' the value, because we cant scale 0
  59. if (limit == 0)
  60. {
  61. labelInfo = "Open " + label;
  62. if (Inspector.SphereButton(position, rotation, radius * 0.2f, radius * 0.07f))
  63. {
  64. limit = openingValue;
  65. }
  66. }
  67. Handles.Label(position, labelInfo);
  68. return limit;
  69. }
  70. #endregion
  71. }
  72. }