59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEditor;
|
||
|
||
[CustomEditor(typeof(MassInspectorController))]
|
||
public class MassInspectorControllerEditor : Editor
|
||
{
|
||
public override void OnInspectorGUI()
|
||
{
|
||
var controller = (MassInspectorController)target;
|
||
|
||
if (controller.targets == null)
|
||
return;
|
||
|
||
EditorGUILayout.LabelField("Маса обʼєктів", EditorStyles.boldLabel);
|
||
EditorGUILayout.Space();
|
||
|
||
for (int i = 0; i < controller.targets.Count; i++)
|
||
{
|
||
var t = controller.targets[i];
|
||
if (t == null) continue;
|
||
|
||
EditorGUILayout.BeginVertical("box");
|
||
|
||
EditorGUILayout.BeginHorizontal();
|
||
EditorGUILayout.LabelField(string.IsNullOrEmpty(t.ukrainianName) ? "(без назви)" : t.ukrainianName, GUILayout.Width(140));
|
||
t.rigidbody = (Rigidbody)EditorGUILayout.ObjectField(t.rigidbody, typeof(Rigidbody), true);
|
||
EditorGUILayout.EndHorizontal();
|
||
|
||
if (t.rigidbody != null)
|
||
{
|
||
if (t.baseMass <= 0f)
|
||
t.baseMass = t.rigidbody.mass;
|
||
|
||
float currentMultiplier = t.baseMass > 0f ? (t.rigidbody.mass / t.baseMass) : 1f;
|
||
float newMultiplier = EditorGUILayout.Slider("Множник маси", currentMultiplier, 0.5f, 1.5f);
|
||
|
||
EditorGUILayout.LabelField("Поточна маса", t.rigidbody.mass.ToString("F2") + " кг");
|
||
|
||
if (!Mathf.Approximately(currentMultiplier, newMultiplier))
|
||
{
|
||
Undo.RecordObject(t.rigidbody, "Change Mass");
|
||
t.rigidbody.mass = t.baseMass * newMultiplier;
|
||
EditorUtility.SetDirty(t.rigidbody);
|
||
}
|
||
}
|
||
|
||
EditorGUILayout.EndVertical();
|
||
}
|
||
|
||
if (GUI.changed)
|
||
{
|
||
EditorUtility.SetDirty(controller);
|
||
}
|
||
}
|
||
}
|