Skip to content

Commit

Permalink
#277 - Fixed a bug where expandable wasn't working correctly when use…
Browse files Browse the repository at this point in the history
…d on a list that is very deeply nested
  • Loading branch information
dbrizov committed Oct 9, 2021
1 parent 9d1d2e5 commit 6ff4276
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 39 deletions.
5 changes: 2 additions & 3 deletions Samples/DemoScene/TestAssets/NaughtyScriptableObject.asset
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 753bdb918c6038142acddbd7aae6958f, type: 3}
m_Name: NaughtyScriptableObject
m_EditorClassIdentifier:
list:
listA:
- {fileID: 11400000, guid: 149474eb879a6a641b560ca17d48712f, type: 2}
- {fileID: 11400000, guid: 149474eb879a6a641b560ca17d48712f, type: 2}
- {fileID: 11400000, guid: ca97c330d5c96794aa4df848d63f836b, type: 2}
- {fileID: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 19472ac11eae27a4b804f354ca7d9c00, type: 3}
m_Name: TestScriptableObject 0
m_Name: TestScriptableObjectA
m_EditorClassIdentifier:
integer: 0
minMaxSlider: {x: 0, y: 0.5}
vectorValue: {x: 1, y: 0, z: 0}
listB:
- {fileID: 11400000, guid: 05371aa7630d3ef44ac0106af06cd73c, type: 2}
- {fileID: 11400000, guid: 05371aa7630d3ef44ac0106af06cd73c, type: 2}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ MonoBehaviour:
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 19472ac11eae27a4b804f354ca7d9c00, type: 3}
m_Name: TestScriptableObject 1
m_Script: {fileID: 11500000, guid: c2b396aeebc9d984da298eee313896bc, type: 3}
m_Name: TestScriptableObjectB
m_EditorClassIdentifier:
minMaxSlider: {x: 0.5, y: 1}
vectorValue: {x: 0, y: 1, z: 0}
slider: {x: 3, y: 7}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Scripts/Editor/PropertyDrawers/ExpandablePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ protected override float GetPropertyHeight_Internal(SerializedProperty property,
protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(rect, label, property);
property.serializedObject.Update();

if (property.objectReferenceValue == null)
{
Expand Down Expand Up @@ -110,8 +111,6 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G

EditorGUI.PropertyField(propertyRect, property, label, false);

property.serializedObject.ApplyModifiedProperties();

// Draw the child properties
if (property.isExpanded)
{
Expand All @@ -126,6 +125,7 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G
}
}

property.serializedObject.ApplyModifiedProperties();
EditorGUI.EndProperty();
}

Expand All @@ -150,6 +150,7 @@ private void DrawChildProperties(Rect rect, SerializedProperty property)
using (new EditorGUI.IndentLevelScope())
{
SerializedObject serializedObject = new SerializedObject(scriptableObject);
serializedObject.Update();

using (var iterator = serializedObject.GetIterator())
{
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Test/_NaughtyScriptableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace NaughtyAttributes.Test
public class _NaughtyScriptableObject : ScriptableObject
{
[Expandable]
public List<_TestScriptableObject> list;
public List<_TestScriptableObjectA> listA;
}
}
24 changes: 0 additions & 24 deletions Scripts/Test/_TestScriptableObject.cs

This file was deleted.

12 changes: 12 additions & 0 deletions Scripts/Test/_TestScriptableObjectA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;
using System.Collections.Generic;

namespace NaughtyAttributes.Test
{
//[CreateAssetMenu(fileName = "TestScriptableObjectA", menuName = "NaughtyAttributes/TestScriptableObjectA")]
public class _TestScriptableObjectA : ScriptableObject
{
[Expandable]
public List<_TestScriptableObjectB> listB;
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions Scripts/Test/_TestScriptableObjectB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine;
using System.Collections.Generic;

namespace NaughtyAttributes.Test
{
//[CreateAssetMenu(fileName = "TestScriptableObjectB", menuName = "NaughtyAttributes/TestScriptableObjectB")]
public class _TestScriptableObjectB : ScriptableObject
{
[MinMaxSlider(0, 10)]
public Vector2Int slider;
}
}
11 changes: 11 additions & 0 deletions Scripts/Test/_TestScriptableObjectB.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ff4276

Please sign in to comment.