using Module.Inspector.Editor.Utilities; using UnityEditor; using UnityEngine; namespace Module.Inspector.Editor { [CanEditMultipleObjects] [CustomEditor(typeof(Object), true, isFallback = true)] public sealed class ObjectEditor : UnityEditor.Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); DrawMethodInspector(); } private void DrawMethodInspector() { if (!IsValidMethodTarget()) return; EditorMethodUtility.ResultPrimary[] primaries = EditorMethodUtility.QueryPrimary(target); float totalHeight = CalculateMethodHeight(primaries); GUILayout.Space(totalHeight); var position = new Rect(0, 0, 1, 1); if (Event.current.type == EventType.Repaint) { position = GUILayoutUtility.GetLastRect(); position.y -= totalHeight; } position.y = position.yMax + EditorGUIUtility.singleLineHeight; position.height = 0.0f; for (var i = 0; i < primaries.Length; i++) { EditorMethodUtility.ResultPrimary primary = primaries[i]; float height = primary.drawer.GetHeight(target, primary.methodInfo); position.height = height; primary.drawer.OnGUI(position, target, primary.methodInfo); position.y += height; } } private float CalculateMethodHeight(EditorMethodUtility.ResultPrimary[] primaries) { float total = EditorGUIUtility.singleLineHeight; for (var i = 0; i < primaries.Length; i++) { EditorMethodUtility.ResultPrimary primary = primaries[i]; total += primary.drawer.GetHeight(target, primary.methodInfo); } return total; } private bool IsValidMethodTarget() { return target != null && targets.Length == 1; } } }