0.2.0: Moved into inspector drawer from module.toolbox to module.inspector
This commit is contained in:
parent
5671c2c754
commit
ffec2abdf4
227 changed files with 5306 additions and 29 deletions
68
Editor/ObjectEditor.cs
Normal file
68
Editor/ObjectEditor.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue