MagicaMeshSpringInspector.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /// メッシュスプリングのエディタ拡張
  10. /// </summary>
  11. [CustomEditor(typeof(MagicaMeshSpring))]
  12. public class MagicaMeshSpringInspector : ClothEditor
  13. {
  14. protected override void OnEnable()
  15. {
  16. base.OnEnable();
  17. }
  18. public override void OnInspectorGUI()
  19. {
  20. MagicaMeshSpring scr = target as MagicaMeshSpring;
  21. // データ状態
  22. EditorInspectorUtility.DispVersionStatus(scr);
  23. EditorInspectorUtility.DispDataStatus(scr);
  24. serializedObject.Update();
  25. Undo.RecordObject(scr, "CreateMeshSpring");
  26. // データ検証
  27. if (EditorApplication.isPlaying == false)
  28. VerifyData();
  29. // モニターボタン
  30. EditorInspectorUtility.MonitorButtonInspector();
  31. EditorGUI.BeginChangeCheck();
  32. // メイン
  33. MainInspector();
  34. // パラメータ
  35. EditorGUILayout.Space();
  36. EditorGUILayout.Space();
  37. EditorPresetUtility.DrawPresetButton(scr, scr.Params);
  38. {
  39. var cparam = serializedObject.FindProperty("clothParams");
  40. if (EditorInspectorUtility.AlgorithmInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Algorithm), ConvertToLatestAlgorithmParameters))
  41. scr.Params.SetChangeParam(ClothParams.ParamType.Algorithm);
  42. if (EditorInspectorUtility.GravityInspector(cparam))
  43. scr.Params.SetChangeParam(ClothParams.ParamType.Gravity);
  44. if (EditorInspectorUtility.ExternalForceInspector(cparam))
  45. scr.Params.SetChangeParam(ClothParams.ParamType.ExternalForce);
  46. if (EditorInspectorUtility.DragInspector(cparam))
  47. scr.Params.SetChangeParam(ClothParams.ParamType.Drag);
  48. if (EditorInspectorUtility.MaxVelocityInspector(cparam))
  49. scr.Params.SetChangeParam(ClothParams.ParamType.MaxVelocity);
  50. if (EditorInspectorUtility.WorldInfluenceInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.WorldInfluence)))
  51. scr.Params.SetChangeParam(ClothParams.ParamType.WorldInfluence);
  52. if (EditorInspectorUtility.DistanceDisableInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.DistanceDisable)))
  53. scr.Params.SetChangeParam(ClothParams.ParamType.DistanceDisable);
  54. if (EditorInspectorUtility.ClampPositionInspector(cparam, true, scr.HasChangedParam(ClothParams.ParamType.ClampPosition)))
  55. scr.Params.SetChangeParam(ClothParams.ParamType.ClampPosition);
  56. if (EditorInspectorUtility.FullSpringInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Spring)))
  57. scr.Params.SetChangeParam(ClothParams.ParamType.Spring);
  58. if (EditorInspectorUtility.AdjustRotationInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.AdjustRotation)))
  59. scr.Params.SetChangeParam(ClothParams.ParamType.AdjustRotation);
  60. }
  61. serializedObject.ApplyModifiedProperties();
  62. // データ作成
  63. if (EditorApplication.isPlaying == false)
  64. {
  65. EditorGUI.BeginDisabledGroup(CheckCreate() == false);
  66. EditorGUILayout.Space();
  67. EditorGUILayout.Space();
  68. GUI.backgroundColor = Color.red;
  69. if (GUILayout.Button("Create"))
  70. {
  71. Undo.RecordObject(scr, "CreateMeshSpringData");
  72. BuildManager.CreateComponent(scr);
  73. }
  74. GUI.backgroundColor = Color.white;
  75. EditorGUI.EndDisabledGroup();
  76. }
  77. else
  78. {
  79. EditorGUILayout.Space();
  80. EditorGUILayout.Space();
  81. GUI.backgroundColor = Color.blue;
  82. if (GUILayout.Button("Reset Position"))
  83. {
  84. scr.ResetCloth();
  85. }
  86. GUI.backgroundColor = Color.white;
  87. }
  88. EditorGUILayout.Space();
  89. if (EditorGUI.EndChangeCheck())
  90. {
  91. // Sceneビュー更新
  92. SceneView.RepaintAll();
  93. }
  94. }
  95. //=========================================================================================
  96. /// <summary>
  97. /// 作成を実行できるか判定する
  98. /// </summary>
  99. /// <returns></returns>
  100. protected override bool CheckCreate()
  101. {
  102. MagicaMeshSpring scr = target as MagicaMeshSpring;
  103. if (scr.Deformer == null)
  104. return false;
  105. if (scr.Deformer.VerifyData() != Define.Error.None)
  106. return false;
  107. return true;
  108. }
  109. /// <summary>
  110. /// データ検証
  111. /// </summary>
  112. private void VerifyData()
  113. {
  114. MagicaMeshSpring scr = target as MagicaMeshSpring;
  115. if (scr.VerifyData() != Define.Error.None)
  116. {
  117. // 検証エラー
  118. serializedObject.ApplyModifiedProperties();
  119. }
  120. }
  121. //=========================================================================================
  122. void MainInspector()
  123. {
  124. MagicaMeshSpring scr = target as MagicaMeshSpring;
  125. EditorGUILayout.LabelField("Main Setup", EditorStyles.boldLabel);
  126. // マージメッシュデフォーマー
  127. EditorGUILayout.PropertyField(serializedObject.FindProperty("virtualDeformer"));
  128. EditorGUILayout.Space();
  129. // センタートランスフォーム
  130. scr.CenterTransform = EditorGUILayout.ObjectField(
  131. "Center Transform", scr.CenterTransform, typeof(Transform), true
  132. ) as Transform;
  133. scr.DirectionAxis = (MagicaMeshSpring.Axis)EditorGUILayout.EnumPopup("Direction Axis", scr.DirectionAxis);
  134. EditorGUILayout.Space();
  135. // チーム項目
  136. TeamBasicInspector();
  137. // カリング
  138. CullingInspector();
  139. }
  140. }
  141. }