0.2.0: Moved into inspector drawer from module.toolbox to module.inspector

This commit is contained in:
Anders Ejlersen 2021-09-18 15:48:14 +02:00
parent 5671c2c754
commit ffec2abdf4
227 changed files with 5306 additions and 29 deletions

View file

@ -0,0 +1,63 @@
using Module.Inspector.Editor.Utilities;
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor
{
public abstract class AbstractPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorPropertyUtility.Result result = EditorPropertyUtility.Query(fieldInfo);
EAccessType accessType = GetAccessType(property, result);
if (accessType == EAccessType.Hidden)
return;
label.tooltip = result.tooltip;
bool prevEnabled = GUI.enabled;
GUI.enabled = accessType == EAccessType.Enabled;
if (result.draw != null)
{
if (!result.draw.drawer.Draw(position, result.draw.attribute, property, label, result))
EditorGUI.LabelField(position, label, result.draw.drawer.GetErrorMessage(property));
}
else
{
EditorGUI.PropertyField(position, property, label, true);
}
GUI.enabled = prevEnabled;
for (var i = 0; i < result.valueModifiers.Count; i++)
{
EditorPropertyUtility.ResultValue<ValueModifierPropertyAttribute, ValueModifierPropertyDrawer> value = result.valueModifiers[i];
value.drawer.Modify(value.attribute, property);
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
EditorPropertyUtility.Result result = EditorPropertyUtility.Query(fieldInfo);
EAccessType accessType = GetAccessType(property, result);
return accessType != EAccessType.Hidden ? EditorGUI.GetPropertyHeight(property, label) : 0.0f;
}
private EAccessType GetAccessType(SerializedProperty property, EditorPropertyUtility.Result result)
{
if (result.accessModifiers.Count == 0)
return EAccessType.Enabled;
EAccessType accessType = 0;
for (var i = 0; i < result.accessModifiers.Count; i++)
{
EditorPropertyUtility.ResultValue<AccessModifierPropertyAttribute, AccessModifierPropertyDrawer> value = result.accessModifiers[i];
accessType = value.drawer.GetAccessType(value.attribute, property, accessType);
}
return accessType;
}
}
}