1.1.0: Added validate attribute with NotNullField
This commit is contained in:
parent
18356eb532
commit
41ced8fdb7
15 changed files with 166 additions and 8 deletions
|
|
@ -14,6 +14,9 @@ namespace Module.Inspector.Editor
|
|||
if (accessType == EAccessType.Hidden)
|
||||
return;
|
||||
|
||||
bool prevEnabled = GUI.enabled;
|
||||
GUI.enabled = accessType == EAccessType.Enabled;
|
||||
|
||||
label.tooltip = result.tooltip;
|
||||
|
||||
for (var i = 0; i < result.predrawerModifiers.Count; i++)
|
||||
|
|
@ -22,18 +25,39 @@ namespace Module.Inspector.Editor
|
|||
value.drawer.Modify(value.attribute, property, label);
|
||||
}
|
||||
|
||||
bool prevEnabled = GUI.enabled;
|
||||
GUI.enabled = accessType == EAccessType.Enabled;
|
||||
var isValid = true;
|
||||
var validationError = string.Empty;
|
||||
|
||||
for (var i = 0; i < result.validators.Count; i++)
|
||||
{
|
||||
EditorPropertyUtility.ResultValue<ValidatePropertyAttribute, ValidatePropertyDrawer> value = result.validators[i];
|
||||
|
||||
if (value.drawer.Validate(value.attribute, property))
|
||||
continue;
|
||||
|
||||
validationError += value.drawer.GetValidationError(property);
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
Color prevColor = GUI.color;
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(label.tooltip))
|
||||
label.tooltip = validationError;
|
||||
else
|
||||
label.tooltip += "\n" + validationError;
|
||||
|
||||
GUI.color = Color.red;
|
||||
}
|
||||
|
||||
if (result.draw != null)
|
||||
{
|
||||
if (!result.draw.drawer.Draw(position, result.draw.attribute, property, label, result))
|
||||
{
|
||||
Color prevColor = GUI.color;
|
||||
GUI.color = Color.red;
|
||||
var errorContent = new GUIContent(result.draw.drawer.GetErrorMessage(property));
|
||||
EditorGUI.LabelField(position, label, errorContent);
|
||||
GUI.color = prevColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -41,6 +65,7 @@ namespace Module.Inspector.Editor
|
|||
EditorGUI.PropertyField(position, property, label, true);
|
||||
}
|
||||
|
||||
GUI.color = prevColor;
|
||||
GUI.enabled = prevEnabled;
|
||||
|
||||
for (var i = 0; i < result.valueModifiers.Count; i++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue