1.8.3: Added HideLabel attribute
This commit is contained in:
parent
61c7356b3a
commit
3259b62387
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ namespace Module.Inspector.Editor
|
|||
else
|
||||
label.tooltip += "\n" + validationError;
|
||||
|
||||
GUI.color = Color.red;
|
||||
EditorIcons.SetErrorIcon(label);
|
||||
}
|
||||
|
||||
if (result.draw != null)
|
||||
|
|
|
|||
14
Editor/Predrawers/HideLabelAttributeDrawer.cs
Normal file
14
Editor/Predrawers/HideLabelAttributeDrawer.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Predrawers/HideLabelAttributeDrawer.cs.meta
Normal file
3
Editor/Predrawers/HideLabelAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: df07b497331149cfb8ce6e544247cb9f
|
||||
timeCreated: 1699115325
|
||||
39
Editor/Utilities/EditorIcons.cs
Normal file
39
Editor/Utilities/EditorIcons.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Utilities/EditorIcons.cs.meta
Normal file
3
Editor/Utilities/EditorIcons.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 07b74dac541c43cb8a89bd0a1b577ec1
|
||||
timeCreated: 1699115532
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +66,8 @@ List of all available pre-drawer attributes:
|
|||
* Sets GUIContent label for `SerializedProperty` to value from another field
|
||||
* `FieldLabelFromType`
|
||||
* Sets GUIContent label for `SerializedProperty` to value type from another field
|
||||
|
||||
* `HideLabel`
|
||||
* Sets GUIContent label for `SerializedProperty` to empty string
|
||||
|
||||
|
||||
## Drawer
|
||||
|
|
|
|||
14
Runtime/Predrawers/HideLabelAttribute.cs
Normal file
14
Runtime/Predrawers/HideLabelAttribute.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Module.Inspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
public sealed class HideLabelAttribute : PredrawerModifierPropertyAttribute
|
||||
{
|
||||
[Preserve]
|
||||
public HideLabelAttribute()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Runtime/Predrawers/HideLabelAttribute.cs.meta
Normal file
3
Runtime/Predrawers/HideLabelAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f5c299642f040cabf74fd751c38e7ce
|
||||
timeCreated: 1699115292
|
||||
|
|
@ -6,9 +6,16 @@ namespace Module.Inspector
|
|||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
public class NotNullFieldAttribute : ValidatePropertyAttribute
|
||||
{
|
||||
public readonly string errorMessage;
|
||||
|
||||
[Preserve]
|
||||
public NotNullFieldAttribute()
|
||||
{
|
||||
}
|
||||
|
||||
public NotNullFieldAttribute(string errorMessage)
|
||||
{
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "com.module.inspector",
|
||||
"version": "1.8.2",
|
||||
"version": "1.8.3",
|
||||
"displayName": "Module.Inspector",
|
||||
"description": "Custom inspector with various useful property drawers",
|
||||
"unity": "2019.2",
|
||||
|
|
|
|||
Loading…
Reference in a new issue