1.8.1: Fixed issue with certain drawers using EditorGUI.PropertyField, which would invoke a second draw with the same attribute

This commit is contained in:
Anders Ejlersen 2023-04-21 18:44:44 +02:00
parent eb19150d98
commit b189ec8b97
8 changed files with 21 additions and 14 deletions

View file

@ -20,8 +20,10 @@ namespace Module.Inspector.Editor
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
string temp = EditorGUI.TextField(rect0, label, property.stringValue);
EditorGUI.PropertyField(rect0, property, label);
if (!temp.Equals(property.stringValue))
property.stringValue = temp;
if (GUI.Button(rect1, "Find")) if (GUI.Button(rect1, "Find"))
{ {

View file

@ -20,9 +20,11 @@ namespace Module.Inspector.Editor
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
string temp = EditorGUI.TextField(rect0, label, property.stringValue);
EditorGUI.PropertyField(rect0, property, label);
if (!temp.Equals(property.stringValue))
property.stringValue = temp;
if (GUI.Button(rect1, "Find")) if (GUI.Button(rect1, "Find"))
{ {
string path = EditorUtility.OpenFolderPanel("Folder", "Assets/", string.Empty); string path = EditorUtility.OpenFolderPanel("Folder", "Assets/", string.Empty);

View file

@ -84,7 +84,7 @@ namespace Module.Inspector.Editor
return "Unknown error"; return "Unknown error";
} }
private static ESupportType IsSupported(SerializedProperty property) private static ESupportType IsSupported(SerializedProperty property)
{ {
if (property.propertyType != SerializedPropertyType.ManagedReference) if (property.propertyType != SerializedPropertyType.ManagedReference)

View file

@ -20,8 +20,10 @@ namespace Module.Inspector.Editor
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
string temp = EditorGUI.TextField(rect0, label, property.stringValue);
EditorGUI.PropertyField(rect0, property, label);
if (!temp.Equals(property.stringValue))
property.stringValue = temp;
if (GUI.Button(rect1, "Find")) if (GUI.Button(rect1, "Find"))
EditorWindowStringToField.Open(att.type, property); EditorWindowStringToField.Open(att.type, property);

View file

@ -20,12 +20,13 @@ namespace Module.Inspector.Editor
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
string temp = EditorGUI.TextField(rect0, label, property.stringValue);
EditorGUI.PropertyField(rect0, property, label);
if (!temp.Equals(property.stringValue))
property.stringValue = temp;
if (GUI.Button(rect1, "Find")) if (GUI.Button(rect1, "Find"))
EditorWindowStringToType.Open(att.assignableFrom, property); EditorWindowStringToType.Open(att.assignableFrom, property);
} }
EditorGUI.EndProperty(); EditorGUI.EndProperty();
return true; return true;

View file

@ -526,7 +526,7 @@ namespace Module.Inspector.Editor
case SerializedPropertyType.BoundsInt: case SerializedPropertyType.BoundsInt:
return property.boundsIntValue.ToString(); return property.boundsIntValue.ToString();
case SerializedPropertyType.ManagedReference: case SerializedPropertyType.ManagedReference:
return property.objectReferenceValue != null ? property.objectReferenceValue.ToString() : "null"; return property.managedReferenceValue != null ? property.managedReferenceValue.ToString() : "null";
} }
return "Unable to draw value as string"; return "Unable to draw value as string";

View file

@ -171,6 +171,6 @@ List of all decorator attributes:
To allow fields hidden from inspector either by `NonSerialized` or `HideInInspector` add the following to the class: To allow fields hidden from inspector either by `NonSerialized` or `HideInInspector` add the following to the class:
* `EnableShowHiddenFields` * `EnableShowHiddenFields`
* Enables an additional search to find any "hidden" fields and draw them below `DefaultInspector` * Enables an additional search to find any "hidden" fields and draw them below `DefaultInspector`
* `ShowHiddenField` * `ShowHiddenField`
* Optional attribute for fields, if `EnableShowHiddenFields` has parameter `true` * Optional attribute for fields, if `EnableShowHiddenFields` has parameter `true`

View file

@ -1,6 +1,6 @@
{ {
"name": "com.module.inspector", "name": "com.module.inspector",
"version": "1.8.0", "version": "1.8.1",
"displayName": "Module.Inspector", "displayName": "Module.Inspector",
"description": "Custom inspector with various useful property drawers", "description": "Custom inspector with various useful property drawers",
"unity": "2019.2", "unity": "2019.2",