Skip to content

Commit

Permalink
#185 - fixed a bug where scriptable objects with the Expandable attri…
Browse files Browse the repository at this point in the history
…bute become corrupted when the user selects multiple game objects with the same MonoBehaviour
  • Loading branch information
dbrizov committed Apr 25, 2021
1 parent 6e24ead commit 3944fec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 753bdb918c6038142acddbd7aae6958f, type: 3}
m_Name: NaughtyScriptableObject
m_EditorClassIdentifier:
vectorValue: {x: 1, y: 0, z: 0}
integer: 1
minMaxSlider: {x: 0.25, y: 0.75}
vectorValue: {x: 0, y: 1, z: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,17 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, toggleOnLabelClick: true);

// Draw the scriptable object field
float indentLength = NaughtyEditorGUI.GetIndentLength(rect);
float labelWidth = EditorGUIUtility.labelWidth - indentLength + NaughtyEditorGUI.HorizontalSpacing;
Rect propertyRect = new Rect()
{
x = rect.x + labelWidth,
x = rect.x,
y = rect.y,
width = rect.width - labelWidth,
width = rect.width,
height = EditorGUIUtility.singleLineHeight
};

EditorGUI.BeginChangeCheck();
property.objectReferenceValue = EditorGUI.ObjectField(propertyRect, GUIContent.none, property.objectReferenceValue, propertyType, false);
if (EditorGUI.EndChangeCheck())
{
property.serializedObject.ApplyModifiedProperties();
}
EditorGUI.PropertyField(propertyRect, property, label, false);

property.serializedObject.ApplyModifiedProperties();

// Draw the child properties
if (property.isExpanded)
Expand Down Expand Up @@ -142,9 +137,8 @@ private void DrawChildProperties(Rect rect, SerializedProperty property)

using (new EditorGUI.IndentLevelScope())
{
EditorGUI.BeginChangeCheck();

SerializedObject serializedObject = new SerializedObject(scriptableObject);

using (var iterator = serializedObject.GetIterator())
{
float yOffset = EditorGUIUtility.singleLineHeight;
Expand Down Expand Up @@ -182,10 +176,7 @@ private void DrawChildProperties(Rect rect, SerializedProperty property)
}
}

if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
}
serializedObject.ApplyModifiedProperties();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace NaughtyAttributes.Test
//[CreateAssetMenu(fileName = "NaughtyScriptableObject", menuName = "NaughtyAttributes/_NaughtyScriptableObject")]
public class _NaughtyScriptableObject : ScriptableObject
{
public int integer;

[MinMaxSlider(0.0f, 1.0f)]
public Vector2 minMaxSlider;

[Dropdown("GetVectorValues")]
public Vector3 vectorValue;

Expand Down

0 comments on commit 3944fec

Please sign in to comment.