/Assets/Mega-Fiers/Editor/MegaFiers/MegaWorldPathDeformEditor.cs

https://bitbucket.org/isereda_visco/vuforiademoiosbuild · C# · 112 lines · 84 code · 22 blank · 6 comment · 16 complexity · 11f940b4639fec67a0b1dc53189d9c98 MD5 · raw file

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