1.7.0: Added option to display hidden fields for a class
This commit is contained in:
parent
9faacb6291
commit
070b82767f
12 changed files with 200 additions and 24 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using System.Reflection;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -11,17 +12,21 @@ namespace Module.Inspector.Editor
|
|||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
DrawHiddenInspector();
|
||||
DrawMethodInspector();
|
||||
}
|
||||
|
||||
private void DrawMethodInspector()
|
||||
private void DrawHiddenInspector()
|
||||
{
|
||||
if (!IsValidMethodTarget())
|
||||
if (!IsValidTarget())
|
||||
return;
|
||||
|
||||
EditorMethodUtility.ResultPrimary[] primaries = EditorMethodUtility.QueryPrimary(target);
|
||||
FieldInfo[] fields = EditorHiddenFieldUtility.Query(target);
|
||||
|
||||
if (fields.Length == 0)
|
||||
return;
|
||||
|
||||
float totalHeight = CalculateMethodHeight(primaries);
|
||||
float totalHeight = EditorHiddenFieldUtility.CalculateHeight(fields) + EditorGUIUtility.singleLineHeight * 2;
|
||||
GUILayout.Space(totalHeight);
|
||||
|
||||
var position = new Rect(0, 0, 1, 1);
|
||||
|
|
@ -37,8 +42,49 @@ namespace Module.Inspector.Editor
|
|||
}
|
||||
|
||||
position.y = position.yMax + EditorGUIUtility.singleLineHeight;
|
||||
position.height = 0.0f;
|
||||
position.height = EditorGUIUtility.singleLineHeight;
|
||||
EditorGUI.LabelField(position, "Hidden fields", EditorStyles.miniBoldLabel);
|
||||
|
||||
position.y += EditorGUIUtility.singleLineHeight;
|
||||
|
||||
for (var i = 0; i < fields.Length; i++)
|
||||
{
|
||||
EditorHiddenFieldUtility.Draw(position, fields[i], target);
|
||||
position.y += position.height;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMethodInspector()
|
||||
{
|
||||
if (!IsValidTarget())
|
||||
return;
|
||||
|
||||
EditorMethodUtility.ResultPrimary[] primaries = EditorMethodUtility.QueryPrimary(target);
|
||||
|
||||
if (primaries == null || primaries.Length == 0)
|
||||
return;
|
||||
|
||||
float totalHeight = EditorMethodUtility.CalculateHeight(target, primaries) + EditorGUIUtility.singleLineHeight * 2;
|
||||
GUILayout.Space(totalHeight);
|
||||
|
||||
var position = new Rect(0, 0, 1, 1);
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
position = GUILayoutUtility.GetLastRect();
|
||||
position.y -= totalHeight;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
position.width = EditorGUIUtility.currentViewWidth - 22.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
position.y = position.yMax + EditorGUIUtility.singleLineHeight;
|
||||
position.height = EditorGUIUtility.singleLineHeight;
|
||||
EditorGUI.LabelField(position, "Buttons", EditorStyles.miniBoldLabel);
|
||||
|
||||
position.y += EditorGUIUtility.singleLineHeight;
|
||||
|
||||
for (var i = 0; i < primaries.Length; i++)
|
||||
{
|
||||
EditorMethodUtility.ResultPrimary primary = primaries[i];
|
||||
|
|
@ -51,20 +97,7 @@ namespace Module.Inspector.Editor
|
|||
}
|
||||
}
|
||||
|
||||
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()
|
||||
private bool IsValidTarget()
|
||||
{
|
||||
return target != null && targets.Length == 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue