123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // Magica Cloth.
- // Copyright (c) MagicaSoft, 2020-2022.
- // https://magicasoft.jp
- using UnityEditor;
- using UnityEngine;
- namespace MagicaCloth
- {
- /// <summary>
- /// ボーンスプリングのエディタ拡張
- /// </summary>
- [CustomEditor(typeof(MagicaBoneSpring))]
- public class MagicaBoneSpringInspector : ClothEditor
- {
- protected override void OnEnable()
- {
- base.OnEnable();
- }
- public override void OnInspectorGUI()
- {
- MagicaBoneSpring scr = target as MagicaBoneSpring;
- // データ状態
- EditorInspectorUtility.DispVersionStatus(scr);
- EditorInspectorUtility.DispDataStatus(scr);
- serializedObject.Update();
- Undo.RecordObject(scr, "CreateBoneSpring");
- // データ検証
- if (EditorApplication.isPlaying == false)
- VerifyData();
- // モニターボタン
- EditorInspectorUtility.MonitorButtonInspector();
- // メイン
- MainInspector();
- // パラメータ
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- EditorPresetUtility.DrawPresetButton(scr, scr.Params);
- {
- var cparam = serializedObject.FindProperty("clothParams");
- if (EditorInspectorUtility.AlgorithmInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Algorithm), ConvertToLatestAlgorithmParameters))
- scr.Params.SetChangeParam(ClothParams.ParamType.Algorithm);
- if (EditorInspectorUtility.RadiusInspector(cparam))
- scr.Params.SetChangeParam(ClothParams.ParamType.Radius);
- //if (EditorInspectorUtility.MassInspector(cparam))
- // scr.Params.SetChangeParam(ClothParams.ParamType.Mass);
- if (EditorInspectorUtility.GravityInspector(cparam))
- scr.Params.SetChangeParam(ClothParams.ParamType.Gravity);
- if (EditorInspectorUtility.ExternalForceInspector(cparam))
- scr.Params.SetChangeParam(ClothParams.ParamType.ExternalForce);
- if (EditorInspectorUtility.DragInspector(cparam))
- scr.Params.SetChangeParam(ClothParams.ParamType.Drag);
- if (EditorInspectorUtility.MaxVelocityInspector(cparam))
- scr.Params.SetChangeParam(ClothParams.ParamType.MaxVelocity);
- if (EditorInspectorUtility.WorldInfluenceInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.WorldInfluence)))
- scr.Params.SetChangeParam(ClothParams.ParamType.WorldInfluence);
- if (EditorInspectorUtility.DistanceDisableInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.DistanceDisable)))
- scr.Params.SetChangeParam(ClothParams.ParamType.DistanceDisable);
- if (EditorInspectorUtility.ClampPositionInspector(cparam, true, scr.HasChangedParam(ClothParams.ParamType.ClampPosition)))
- scr.Params.SetChangeParam(ClothParams.ParamType.ClampPosition);
- if (EditorInspectorUtility.SimpleSpringInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.Spring)))
- scr.Params.SetChangeParam(ClothParams.ParamType.Spring);
- if (EditorInspectorUtility.AdjustRotationInspector(cparam, scr.HasChangedParam(ClothParams.ParamType.AdjustRotation)))
- scr.Params.SetChangeParam(ClothParams.ParamType.AdjustRotation);
- }
- serializedObject.ApplyModifiedProperties();
- // データ作成
- if (EditorApplication.isPlaying == false)
- {
- EditorGUI.BeginDisabledGroup(CheckCreate() == false);
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- GUI.backgroundColor = Color.red;
- if (GUILayout.Button("Create"))
- {
- Undo.RecordObject(scr, "CreateBoneSpring");
- BuildManager.CreateComponent(scr);
- }
- GUI.backgroundColor = Color.white;
- EditorGUI.EndDisabledGroup();
- }
- else
- {
- EditorGUILayout.Space();
- EditorGUILayout.Space();
- GUI.backgroundColor = Color.blue;
- if (GUILayout.Button("Reset Position"))
- {
- scr.ResetCloth();
- }
- GUI.backgroundColor = Color.white;
- }
- EditorGUILayout.Space();
- }
- //=========================================================================================
- /// <summary>
- /// 作成を実行できるか判定する
- /// </summary>
- /// <returns></returns>
- protected override bool CheckCreate()
- {
- if (PointSelector.EditEnable)
- return false;
- return true;
- }
- /// <summary>
- /// データ検証
- /// </summary>
- private void VerifyData()
- {
- MagicaBoneSpring scr = target as MagicaBoneSpring;
- if (scr.VerifyData() != Define.Error.None)
- {
- // 検証エラー
- serializedObject.ApplyModifiedProperties();
- }
- }
- //=========================================================================================
- void MainInspector()
- {
- MagicaBoneSpring scr = target as MagicaBoneSpring;
- EditorGUILayout.LabelField("Main Setup", EditorStyles.boldLabel);
- // ルートリスト
- EditorInspectorUtility.DrawObjectList<Transform>(
- serializedObject.FindProperty("clothTarget.rootList"),
- scr.gameObject,
- false, true,
- () => scr.gameObject.transform.root.GetComponentsInChildren<Transform>()
- );
- // チーム項目
- TeamBasicInspector();
- // アニメーション連動
- //scr.ClothTarget.IsAnimationBone = EditorGUILayout.Toggle("Is Animation Bones", scr.ClothTarget.IsAnimationBone);
- //scr.ClothTarget.IsAnimationPosition = EditorGUILayout.Toggle("Is Animation Position", scr.ClothTarget.IsAnimationPosition);
- //scr.ClothTarget.IsAnimationRotation = EditorGUILayout.Toggle("Is Animation Rotation", scr.ClothTarget.IsAnimationRotation);
- // ポイント選択
- //DrawInspectorGUI(scr);
- EditorGUILayout.Space();
- // カリング
- CullingInspector();
- }
- }
- }
|