Skip to content

Commit 1ea10a3

Browse files
committed
Added support for nested types in Random List
1 parent dfb5858 commit 1ea10a3

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Editor/Utilities/RandomListDrawer.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,23 @@ private static ReorderableList CreateReoderableList(SerializedProperty property)
9898
var list = new ReorderableList(property.serializedObject, itemListProperty, true, false, true, true);
9999
list.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) =>
100100
{
101+
var itemProperty = itemListProperty.GetArrayElementAtIndex(index);
101102
Rect objectRect = new Rect(rect.x, rect.y + 2, rect.width * 2 / 3, rect.height - 4);
102-
EditorGUI.PropertyField(objectRect, itemListProperty.GetArrayElementAtIndex(index), GUIContent.none);
103+
GUIContent label = GUIContent.none;
103104

104-
Rect weightRect = new Rect(objectRect.xMax + 5, objectRect.y, rect.width - objectRect.width - 5, objectRect.height);
105+
if (itemProperty.hasVisibleChildren)
106+
{
107+
label = new GUIContent(itemProperty.displayName, itemProperty.tooltip);
108+
objectRect.x += 10;
109+
objectRect.width -= 10;
110+
}
111+
112+
EditorGUI.PropertyField(objectRect, itemProperty, label, true);
113+
114+
Rect weightRect = new Rect(objectRect.xMax + 5, objectRect.y, rect.width * 1 / 3 - 5, EditorGUIUtility.singleLineHeight);
105115
EditorGUI.PropertyField(weightRect, weightListProperty.GetArrayElementAtIndex(index), GUIContent.none);
116+
117+
106118
};
107119

108120
list.drawElementBackgroundCallback += (Rect rect, int index, bool isActive, bool isFocused) =>
@@ -116,7 +128,7 @@ private static ReorderableList CreateReoderableList(SerializedProperty property)
116128

117129
if (!isActive)
118130
GUI.backgroundColor *= 0.6f;
119-
131+
120132
Style.sliderRange.Draw(rect, GUIContent.none, false, false, false, false);
121133
GUI.backgroundColor = previous;
122134
};
@@ -140,6 +152,11 @@ private static ReorderableList CreateReoderableList(SerializedProperty property)
140152
return list.selectedIndices.Count == 1;
141153
};
142154

155+
list.elementHeightCallback += (int index) =>
156+
{
157+
return Mathf.Max(EditorGUIUtility.singleLineHeight+2f, EditorGUI.GetPropertyHeight(itemListProperty.GetArrayElementAtIndex(index)));
158+
};
159+
143160
// For fancy footer that allows adjustment of the total sum on the fly, see the following gist:
144161
// https://i.lu.je/2022/Unity_HoZtERJPs6.png
145162
// https://gist.github.com/Lachee/e76299f00b334b741a6bccd82229e907
@@ -326,9 +343,10 @@ private void DrawSliderBox(Rect area, List<WeightSlider> weights, int activeWeig
326343

327344
void IRistBoxLabelDrawer.DrawLabel(Rect position, RandomListEditorStyle style, SerializedProperty property, float weight, bool isMini)
328345
{
346+
var name = property.hasVisibleChildren ? property.displayName : property.GetValueName();
329347
var label = isMini
330-
? property.GetValueName()
331-
: string.Format("{0}\n{1:0}%", property.GetValueName(), weight * 100);
348+
? name
349+
: string.Format("{0}\n{1:0}%", name, weight * 100);
332350

333351
style.sliderText.Draw(position, label, false, false, false, false);
334352
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.lachee.utilities",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"displayName": "Lachee's Utilities",
55
"description": "Bunch of utility functionality",
66
"unity": "2019.1",

0 commit comments

Comments
 (0)