MagicaBoneClothGizmoDrawer.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /// MagicaBoneClothのギズモ表示
  10. /// </summary>
  11. public class MagicaBoneClothGizmoDrawer
  12. {
  13. [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected | GizmoType.Active)]
  14. //[DrawGizmo(GizmoType.Selected | GizmoType.Active)]
  15. static void DrawGizmo(MagicaBoneCloth scr, GizmoType gizmoType)
  16. {
  17. bool selected = (gizmoType & GizmoType.Selected) != 0 || (ClothMonitorMenu.Monitor != null && ClothMonitorMenu.Monitor.UI.AlwaysClothShow);
  18. if (scr.VerifyData() != Define.Error.None)
  19. {
  20. DrawRootLine(scr);
  21. return;
  22. }
  23. if (PointSelector.EditEnable)
  24. {
  25. DrawRootLine(scr);
  26. return;
  27. }
  28. if (ClothMonitorMenu.Monitor == null)
  29. return;
  30. if (selected == false)
  31. return;
  32. // 常に表示
  33. ClothGizmoDrawer.AlwaysDrawClothGizmo(scr, scr.Params);
  34. // デフォーマーギズモ
  35. DeformerGizmoDrawer.DrawDeformerGizmo(scr, scr, 0.015f);
  36. if (ClothMonitorMenu.Monitor.UI.DrawCloth)
  37. {
  38. // クロスギズモ
  39. ClothGizmoDrawer.DrawClothGizmo(
  40. scr,
  41. scr.ClothData,
  42. scr.Params,
  43. scr.Setup,
  44. scr,
  45. scr
  46. );
  47. }
  48. else
  49. {
  50. DrawRootLine(scr);
  51. }
  52. }
  53. //=========================================================================================
  54. static void DrawRootLine(MagicaBoneCloth scr)
  55. {
  56. for (int i = 0; i < scr.ClothTarget.RootCount; i++)
  57. {
  58. var root = scr.ClothTarget.GetRoot(i);
  59. if (root == null)
  60. continue;
  61. DrawTransformLine(root, root);
  62. }
  63. }
  64. static void DrawTransformLine(Transform t, Transform root)
  65. {
  66. if (t == null)
  67. return;
  68. // トランスフォーム描画
  69. if (PointSelector.EditEnable == false)
  70. {
  71. Gizmos.color = (t == root) ? GizmoUtility.ColorKinematic : GizmoUtility.ColorDynamic;
  72. GizmoUtility.DrawWireCube(t.position, t.rotation, Vector3.one * 0.01f);
  73. }
  74. int cnt = t.childCount;
  75. for (int i = 0; i < cnt; i++)
  76. {
  77. Transform ct = t.GetChild(i);
  78. // ライン
  79. Gizmos.color = GizmoUtility.ColorRotationLine;
  80. Gizmos.DrawLine(t.position, ct.position);
  81. DrawTransformLine(ct, root);
  82. }
  83. }
  84. }
  85. }