1.8.3: Added HideLabel attribute

This commit is contained in:
Anders Ejlersen 2023-11-04 17:47:58 +01:00
parent 61c7356b3a
commit 3259b62387
12 changed files with 97 additions and 8 deletions

View file

@ -35,7 +35,7 @@ namespace Module.Inspector.Editor
if (value.drawer.Validate(value.attribute, property))
continue;
validationError += value.drawer.GetValidationError(property);
validationError += value.drawer.GetValidationError(value.attribute, property);
isValid = false;
}
@ -47,8 +47,8 @@ namespace Module.Inspector.Editor
label.tooltip = validationError;
else
label.tooltip += "\n" + validationError;
GUI.color = Color.red;
EditorIcons.SetErrorIcon(label);
}
if (result.draw != null)

View file

@ -0,0 +1,14 @@
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(HideLabelAttribute))]
internal sealed class HideLabelAttributeDrawer : PredrawerModifierPropertyDrawer
{
public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label)
{
label.text = string.Empty;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df07b497331149cfb8ce6e544247cb9f
timeCreated: 1699115325

View file

@ -0,0 +1,39 @@
using UnityEditor;
using UnityEngine;
namespace Module.Inspector.Editor.Utilities
{
internal static class EditorIcons
{
private static GUIContent CONTENT_WARNING;
private static GUIContent CONTENT_ERROR;
private static GUIContent GetWarningIconContent()
{
if (CONTENT_WARNING == null)
CONTENT_WARNING = EditorGUIUtility.IconContent("Warning");
return CONTENT_WARNING;
}
private static GUIContent GetErrorIconContent()
{
if (CONTENT_ERROR == null)
CONTENT_ERROR = EditorGUIUtility.IconContent("Error");
return CONTENT_ERROR;
}
public static void SetWarningIcon(GUIContent content)
{
GUIContent errorContent = GetWarningIconContent();
content.image = errorContent.image;
}
public static void SetErrorIcon(GUIContent content)
{
GUIContent errorContent = GetErrorIconContent();
content.image = errorContent.image;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 07b74dac541c43cb8a89bd0a1b577ec1
timeCreated: 1699115532

View file

@ -5,6 +5,6 @@ namespace Module.Inspector.Editor
public abstract class ValidatePropertyDrawer : AbstractPropertyDrawer
{
public abstract bool Validate(ValidatePropertyAttribute attribute, SerializedProperty property);
public abstract string GetValidationError(SerializedProperty property);
public abstract string GetValidationError(ValidatePropertyAttribute attribute, SerializedProperty property);
}
}

View file

@ -42,9 +42,14 @@ namespace Module.Inspector.Editor
return true;
}
public override string GetValidationError(SerializedProperty property)
public override string GetValidationError(ValidatePropertyAttribute attribute, SerializedProperty property)
{
return "NotNullField: Value is null";
string errorMessage = ((NotNullFieldAttribute)attribute).errorMessage;
if (string.IsNullOrEmpty(errorMessage))
return "NotNullField: Value is null";
return errorMessage;
}
}
}