MagicaBoneSpringInspector.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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(MagicaBoneSpring))]
  12. public class MagicaBoneSpringInspector : ClothEditor
  13. {
  14. protected override void OnEnable()
  15. {
  16. base.OnEnable();
  17. }
  18. public override void OnInspectorGUI()
  19. {
  20. MagicaBoneSpring scr = target as MagicaBoneSpring;
  21. // データ状態
  22. EditorInspectorUtility.DispVersionStatus(scr);
  23. EditorInspectorUtility.DispDataStatus(scr);
  24. serializedObject.Update();
  25. Undo.RecordObject(scr, "CreateBoneSpring");
  26. // データ検証
  27. if (EditorApplication.isPlaying == false)
  28. VerifyData();
  29. // モニターボタン
  30. EditorInspectorUtility.MonitorButtonInspector();
  31. // メイン
  32. MainInspector();
  33. // パラメータ
  34. EditorGUILayout.Space();
  35. EditorGUILayout.Space();
  36. EditorPresetUtility.DrawPresetButton(scr, scr.Params);
  37. {
  38. var cparam = serializedObject.FindProperty("clothParams");
  39. if (EditorInspectorUtility.AlgorithmInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Algorithm), ConvertToLatestAlgorithmParameters))
  40. scr.Params.SetChangeParam(ClothParams.ParamType.Algorithm);
  41. if (EditorInspectorUtility.RadiusInspector(cparam))
  42. scr.Params.SetChangeParam(ClothParams.ParamType.Radius);
  43. //if (EditorInspectorUtility.MassInspector(cparam))
  44. // scr.Params.SetChangeParam(ClothParams.ParamType.Mass);
  45. if (EditorInspectorUtility.GravityInspector(cparam))
  46. scr.Params.SetChangeParam(ClothParams.ParamType.Gravity);
  47. if (EditorInspectorUtility.ExternalForceInspector(cparam))
  48. scr.Params.SetChangeParam(ClothParams.ParamType.ExternalForce);
  49. if (EditorInspectorUtility.DragInspector(cparam))
  50. scr.Params.SetChangeParam(ClothParams.ParamType.Drag);
  51. if (EditorInspectorUtility.MaxVelocityInspector(cparam))
  52. scr.Params.SetChangeParam(ClothParams.ParamType.MaxVelocity);
  53. if (EditorInspectorUtility.WorldInfluenceInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.WorldInfluence)))
  54. scr.Params.SetChangeParam(ClothParams.ParamType.WorldInfluence);
  55. if (EditorInspectorUtility.DistanceDisableInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.DistanceDisable)))
  56. scr.Params.SetChangeParam(ClothParams.ParamType.DistanceDisable);
  57. if (EditorInspectorUtility.ClampPositionInspector(cparam, true, scr.HasChangedParam(ClothParams.ParamType.ClampPosition)))
  58. scr.Params.SetChangeParam(ClothParams.ParamType.ClampPosition);
  59. if (EditorInspectorUtility.SimpleSpringInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Spring)))
  60. scr.Params.SetChangeParam(ClothParams.ParamType.Spring);
  61. if (EditorInspectorUtility.AdjustRotationInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.AdjustRotation)))
  62. scr.Params.SetChangeParam(ClothParams.ParamType.AdjustRotation);
  63. }
  64. serializedObject.ApplyModifiedProperties();
  65. // データ作成
  66. if (EditorApplication.isPlaying == false)
  67. {
  68. EditorGUI.BeginDisabledGroup(CheckCreate() == false);
  69. EditorGUILayout.Space();
  70. EditorGUILayout.Space();
  71. GUI.backgroundColor = Color.red;
  72. if (GUILayout.Button("Create"))
  73. {
  74. Undo.RecordObject(scr, "CreateBoneSpring");
  75. BuildManager.CreateComponent(scr);
  76. }
  77. GUI.backgroundColor = Color.white;
  78. EditorGUI.EndDisabledGroup();
  79. }
  80. else
  81. {
  82. EditorGUILayout.Space();
  83. EditorGUILayout.Space();
  84. GUI.backgroundColor = Color.blue;
  85. if (GUILayout.Button("Reset Position"))
  86. {
  87. scr.ResetCloth();
  88. }
  89. GUI.backgroundColor = Color.white;
  90. }
  91. EditorGUILayout.Space();
  92. }
  93. //=========================================================================================
  94. /// <summary>
  95. /// 作成を実行できるか判定する
  96. /// </summary>
  97. /// <returns></returns>
  98. protected override bool CheckCreate()
  99. {
  100. if (PointSelector.EditEnable)
  101. return false;
  102. return true;
  103. }
  104. /// <summary>
  105. /// データ検証
  106. /// </summary>
  107. private void VerifyData()
  108. {
  109. MagicaBoneSpring scr = target as MagicaBoneSpring;
  110. if (scr.VerifyData() != Define.Error.None)
  111. {
  112. // 検証エラー
  113. serializedObject.ApplyModifiedProperties();
  114. }
  115. }
  116. //=========================================================================================
  117. void MainInspector()
  118. {
  119. MagicaBoneSpring scr = target as MagicaBoneSpring;
  120. EditorGUILayout.LabelField("Main Setup", EditorStyles.boldLabel);
  121. // ルートリスト
  122. EditorInspectorUtility.DrawObjectList<Transform>(
  123. serializedObject.FindProperty("clothTarget.rootList"),
  124. scr.gameObject,
  125. false, true,
  126. () => scr.gameObject.transform.root.GetComponentsInChildren<Transform>()
  127. );
  128. // チーム項目
  129. TeamBasicInspector();
  130. // アニメーション連動
  131. //scr.ClothTarget.IsAnimationBone = EditorGUILayout.Toggle("Is Animation Bones", scr.ClothTarget.IsAnimationBone);
  132. //scr.ClothTarget.IsAnimationPosition = EditorGUILayout.Toggle("Is Animation Position", scr.ClothTarget.IsAnimationPosition);
  133. //scr.ClothTarget.IsAnimationRotation = EditorGUILayout.Toggle("Is Animation Rotation", scr.ClothTarget.IsAnimationRotation);
  134. // ポイント選択
  135. //DrawInspectorGUI(scr);
  136. EditorGUILayout.Space();
  137. // カリング
  138. CullingInspector();
  139. }
  140. }
  141. }