MagicaDirectionalWindGizmoDrawer.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Magica Cloth.
  2. // Copyright (c) MagicaSoft, 2020-2022.
  3. // https://magicasoft.jp
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace MagicaCloth
  7. {
  8. /// <summary>
  9. /// MagicaDirectionalWindのギズモ表示
  10. /// </summary>
  11. public class MagicaDirectionalWindGizmoDrawer
  12. {
  13. [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected | GizmoType.Active)]
  14. //static void DrawGizmo(MagicaDirectionalWind scr, GizmoType gizmoType)
  15. static void DrawGizmo(WindComponent scr, GizmoType gizmoType)
  16. {
  17. bool selected = (gizmoType & GizmoType.Selected) != 0 || (ClothMonitorMenu.Monitor != null && ClothMonitorMenu.Monitor.UI.AlwaysWindShow);
  18. if (selected == false)
  19. return;
  20. if (ClothMonitorMenu.Monitor == null || ClothMonitorMenu.Monitor.UI.DrawWind)
  21. DrawWindGizmo(scr, selected);
  22. }
  23. private static void DrawWindGizmo(WindComponent scr, bool selected)
  24. {
  25. Gizmos.matrix = scr.transform.localToWorldMatrix;
  26. var size = scr.GetAreaSize();
  27. // エリア
  28. if (scr.GetWindType() == PhysicsManagerWindData.WindType.Area)
  29. {
  30. //Color areaCol = Color.white;
  31. Gizmos.color = Color.white;
  32. switch (scr.GetShapeType())
  33. {
  34. case PhysicsManagerWindData.ShapeType.Box:
  35. Gizmos.DrawWireCube(Vector3.zero, size * 2);
  36. break;
  37. case PhysicsManagerWindData.ShapeType.Sphere:
  38. Gizmos.DrawWireSphere(Vector3.zero, size.x);
  39. // 45度回転させてもう一度
  40. Gizmos.matrix = Gizmos.matrix * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 45, 0), Vector3.one);
  41. Gizmos.DrawWireSphere(Vector3.zero, size.x);
  42. Gizmos.matrix = scr.transform.localToWorldMatrix;
  43. break;
  44. }
  45. }
  46. // メイン方向
  47. //Gizmos.color = GizmoUtility.ColorWind;
  48. Gizmos.color = Color.yellow;
  49. var pos = scr.transform.position;
  50. Vector3 offset = Vector3.zero;
  51. // Anchor
  52. //if (scr.GetWindType() == PhysicsManagerWindData.WindType.Area)
  53. //{
  54. // offset = Vector3.Scale(size, scr.GetAnchor());
  55. // pos += scr.transform.TransformDirection(offset);
  56. //}
  57. var rot = MathUtility.AxisQuaternion(scr.MainDirection);
  58. float gsize = 0.5f;
  59. switch (scr.GetDirectionType())
  60. {
  61. case PhysicsManagerWindData.DirectionType.OneDirection:
  62. GizmoUtility.DrawWireArrow(pos, rot, new Vector3(gsize, gsize, gsize * 2), true);
  63. break;
  64. case PhysicsManagerWindData.DirectionType.Radial:
  65. //Gizmos.DrawWireCube(offset, Vector3.one * 0.5f);
  66. Gizmos.DrawLine(new Vector3(0, -gsize, 0), new Vector3(0, gsize, 0));
  67. Gizmos.DrawLine(new Vector3(-gsize, 0, 0), new Vector3(gsize, 0, 0));
  68. Gizmos.DrawLine(new Vector3(0, 0, -gsize), new Vector3(0, 0, gsize));
  69. break;
  70. }
  71. Gizmos.matrix = Matrix4x4.identity;
  72. }
  73. }
  74. }