MegaPathDeformEditor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using UnityEditor;
  2. using UnityEngine;
  3. [CanEditMultipleObjects, CustomEditor(typeof(MegaPathDeform))]
  4. public class MegaPathDeformEditor : MegaModifierEditor
  5. {
  6. //void OnSceneGUI()
  7. //{
  8. //PathDeform pd = (PathDeform)target;
  9. //Display(pd);
  10. //}
  11. public override bool Inspector()
  12. {
  13. MegaPathDeform mod = (MegaPathDeform)target;
  14. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020
  15. EditorGUIUtility.LookLikeControls();
  16. #endif
  17. mod.usedist = EditorGUILayout.Toggle("Use Distance", mod.usedist);
  18. if ( mod.usedist )
  19. mod.distance = EditorGUILayout.FloatField("Distance", mod.distance);
  20. else
  21. mod.percent = EditorGUILayout.FloatField("Percent", mod.percent);
  22. //mod.percent = EditorGUILayout.FloatField("Percent", mod.percent);
  23. mod.stretch = EditorGUILayout.FloatField("Stretch", mod.stretch);
  24. mod.twist = EditorGUILayout.FloatField("Twist", mod.twist);
  25. mod.rotate = EditorGUILayout.FloatField("Rotate", mod.rotate);
  26. mod.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis);
  27. mod.flip = EditorGUILayout.Toggle("Flip", mod.flip);
  28. mod.path = (MegaShape)EditorGUILayout.ObjectField("Path", mod.path, typeof(MegaShape), true);
  29. if ( mod.path != null && mod.path.splines.Count > 1 )
  30. {
  31. //shape.selcurve = EditorGUILayout.IntField("Curve", shape.selcurve);
  32. mod.curve = EditorGUILayout.IntSlider("Curve", mod.curve, 0, mod.path.splines.Count - 1);
  33. if ( mod.curve < 0 )
  34. mod.curve = 0;
  35. if ( mod.curve > mod.path.splines.Count - 1 )
  36. mod.curve = mod.path.splines.Count - 1;
  37. }
  38. mod.animate = EditorGUILayout.Toggle("Animate", mod.animate);
  39. mod.speed = EditorGUILayout.FloatField("Speed", mod.speed);
  40. mod.loopmode = (MegaLoopMode)EditorGUILayout.EnumPopup("Loop Mode", mod.loopmode);
  41. mod.drawpath = EditorGUILayout.Toggle("Draw Path", mod.drawpath);
  42. mod.tangent = EditorGUILayout.FloatField("Tangent", mod.tangent);
  43. mod.UseTwistCurve = EditorGUILayout.Toggle("Use Twist Curve", mod.UseTwistCurve);
  44. mod.twistCurve = EditorGUILayout.CurveField("Twist Curve", mod.twistCurve);
  45. mod.UseStretchCurve = EditorGUILayout.Toggle("Use Stretch Curve", mod.UseStretchCurve);
  46. mod.stretchCurve = EditorGUILayout.CurveField("Stretch Curve", mod.stretchCurve);
  47. mod.Up = EditorGUILayout.Vector3Field("Up", mod.Up);
  48. return false;
  49. }
  50. void Display(MegaPathDeform pd)
  51. {
  52. if ( pd.path != null )
  53. {
  54. Matrix4x4 mat = pd.transform.localToWorldMatrix * pd.path.transform.localToWorldMatrix * pd.mat;
  55. for ( int s = 0; s < pd.path.splines.Count; s++ )
  56. {
  57. float ldist = pd.path.stepdist;
  58. if ( ldist < 0.1f )
  59. ldist = 0.1f;
  60. float ds = pd.path.splines[s].length / (pd.path.splines[s].length / ldist);
  61. int c = 0;
  62. int k = -1;
  63. int lk = -1;
  64. Vector3 first = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref lk);
  65. for ( float dist = ds; dist < pd.path.splines[s].length; dist += ds )
  66. {
  67. float alpha = dist / pd.path.splines[s].length;
  68. Vector3 pos = pd.path.splines[s].Interpolate(alpha, pd.path.normalizedInterp, ref k);
  69. if ( k != lk )
  70. {
  71. for ( lk = lk + 1; lk <= k; lk++ )
  72. {
  73. Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pd.path.splines[s].knots[lk].p));
  74. first = pd.path.splines[s].knots[lk].p;
  75. }
  76. }
  77. lk = k;
  78. Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos));
  79. c++;
  80. first = pos;
  81. }
  82. if ( pd.path.splines[s].closed )
  83. {
  84. Vector3 pos = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref k);
  85. Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos));
  86. }
  87. }
  88. }
  89. }
  90. }