Skip to content

Commit c97f6ee

Browse files
committed
expanded property layout update
1 parent 3511256 commit c97f6ee

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

Assets/Editor/Editor Windows/ScriptableObjectEditorWindow.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
121121
{
122122
// Show the name of each property as a label
123123
EditorGUILayout.LabelField(property.name, GUILayout.MinWidth(PropertyMinWidth));
124-
float height = EditorGUI.GetPropertyHeight(property, GUIContent.none) + PropertySpace;
125-
height -= EditorGUIUtility.singleLineHeight;
126-
GUILayout.Space(height);
124+
125+
// if any property is bigger than expected this will calculate extra space needed (ex: array properties can expand)
126+
if (property.isExpanded)
127+
GUILayout.Space(CalculatePropertyHeight(Configs, property) - EditorGUIUtility.singleLineHeight);
128+
GUILayout.Space(PropertySpace);
127129
}
128130
ShouldNext = property.NextVisible(false); // Move to the next property, skipping nested children
129131
}
@@ -180,6 +182,12 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
180182
break;
181183
default:
182184
EditorGUILayout.PropertyField(property, GUIContent.none, true, GUIL_DefaultOptions);
185+
if (property.isExpanded)
186+
{
187+
float extraSpace = CalculatePropertyHeight(Configs, property);
188+
extraSpace -= EditorGUI.GetPropertyHeight(property);
189+
GUILayout.Space(extraSpace);
190+
}
183191
break;
184192
// Additional cases can be added here to support more property types
185193
}
@@ -206,6 +214,26 @@ private void PutPropertiesForObject<T>(List<T> Configs) where T : ScriptableObje
206214
GroupScriptableObjectsByType();
207215
}
208216
}
217+
218+
public static float CalculatePropertyHeight<T>(List<T> configs, SerializedProperty property) where T : ScriptableObject
219+
{
220+
float maxHeight = 0f;
221+
222+
foreach (var config in configs)
223+
{
224+
SerializedObject serializedObject = new SerializedObject(config);
225+
SerializedProperty targetProperty = serializedObject.FindProperty(property.propertyPath);
226+
227+
if (targetProperty != null)
228+
{
229+
float height = EditorGUI.GetPropertyHeight(targetProperty, true);
230+
maxHeight = Mathf.Max(maxHeight, height);
231+
}
232+
}
233+
234+
return maxHeight;
235+
}
236+
209237
}
210238

211239
// Custom Popup Window for Config Type Selection
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 2cac81c9ac410e441bde07e00491a572, type: 3}
13+
m_Name: Test2Config 1
14+
m_EditorClassIdentifier:
15+
numberArray: 2d0000003a000000
16+
gameObjectArray: []

Assets/Resources/ScriptableObjects/Test2Config 1.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)