Skip to content

Commit 4678052

Browse files
committed
Possibility to inspect properties from the DefaultObject
1 parent a730ca7 commit 4678052

2 files changed

Lines changed: 86 additions & 5 deletions

File tree

Assets/Editor Toolbox/Editor/ToolboxEditorGui.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using UnityEditor;
44
using UnityEngine;
5+
using Object = UnityEngine.Object;
56

67
namespace Toolbox.Editor
78
{
@@ -206,16 +207,16 @@ public static void DrawMinMaxSlider(Rect rect, string label, ref float xValue, r
206207
public static void DrawMinMaxSlider(Rect rect, GUIContent label, ref float xValue, ref float yValue, float minValue, float maxValue)
207208
{
208209
rect = EditorGUI.PrefixLabel(rect, label);
209-
210+
210211
var fieldWidth = EditorGUIUtility.fieldWidth;
211212
var minFieldRect = new Rect(rect.xMin, rect.y, fieldWidth, rect.height);
212213
var maxFieldRect = new Rect(rect.xMax - fieldWidth, rect.y, fieldWidth, rect.height);
213214

214215
//set slider rect between min and max fields + additional padding
215216
var spacing = 8.0f;
216217
var sliderRect = Rect.MinMaxRect(minFieldRect.xMax + spacing,
217-
rect.yMin,
218-
maxFieldRect.xMin - spacing,
218+
rect.yMin,
219+
maxFieldRect.xMin - spacing,
219220
rect.yMax);
220221

221222
EditorGUI.BeginChangeCheck();
@@ -604,5 +605,36 @@ public static void CloseProperty()
604605
{
605606
EditorGUI.EndProperty();
606607
}
608+
609+
/// <summary>
610+
/// Displays all visible children associated to the given <see cref="Object"/>.
611+
/// This method doesn't support Toolbox-based features.
612+
/// </summary>
613+
public static void DrawObjectProperties(Object instance)
614+
{
615+
using (SerializedObject serializedObject = new SerializedObject(instance))
616+
{
617+
using (var iterator = serializedObject.GetIterator())
618+
{
619+
if (iterator.NextVisible(true))
620+
{
621+
do
622+
{
623+
var name = iterator.name;
624+
SerializedProperty childProperty = serializedObject.FindProperty(name);
625+
if (PropertyUtility.IsDefaultScriptProperty(childProperty))
626+
{
627+
continue;
628+
}
629+
630+
DrawDefaultProperty(childProperty);
631+
}
632+
while (iterator.NextVisible(false));
633+
}
634+
}
635+
636+
serializedObject.ApplyModifiedProperties();
637+
}
638+
}
607639
}
608640
}

Assets/Editor Toolbox/Editor/Wizards/ScriptableObjectCreationWizard.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void Validate()
6565
private static readonly TypeField typeField = new TypeField(sharedConstraint, sharedAppearance);
6666

6767
private readonly CreationData data = new CreationData();
68+
private bool editDefaultObject;
6869

6970
[MenuItem("Assets/Create/Toolbox/ScriptableObject Creation Wizard", priority = 9)]
7071
internal static void Initialize()
@@ -88,7 +89,25 @@ private void DrawSettingsPanel()
8889
data.InstanceName = EditorGUILayout.TextField("Instance Name", data.InstanceName);
8990
data.InstancesCount = EditorGUILayout.IntField("Instances To Create", data.InstancesCount);
9091
var content = new GUIContent("Default Object", "Will be used as a blueprint for all created ScriptableObjects.");
91-
data.DefaultObject = EditorGUILayout.ObjectField(content, data.DefaultObject, data.InstanceType, false);
92+
var instance = EditorGUILayout.ObjectField(content, data.DefaultObject, data.InstanceType, false);
93+
if (instance != null)
94+
{
95+
editDefaultObject = GUILayout.Toggle(editDefaultObject,
96+
Style.foldoutContent, Style.foldoutStyle, Style.foldoutOptions);
97+
}
98+
else
99+
{
100+
editDefaultObject = false;
101+
}
102+
103+
if (editDefaultObject)
104+
{
105+
EditorGUI.indentLevel++;
106+
ToolboxEditorGui.DrawObjectProperties(instance);
107+
EditorGUI.indentLevel--;
108+
}
109+
110+
data.DefaultObject = instance;
92111
if (EditorGUI.EndChangeCheck())
93112
{
94113
OnWizardUpdate();
@@ -177,12 +196,42 @@ protected override void OnWizardUpdate()
177196
protected override void OnWizardGui()
178197
{
179198
base.OnWizardGui();
180-
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
199+
using (new EditorGUILayout.VerticalScope(Style.backgroundStyle))
181200
{
182201
DrawSettingsPanel();
183202
}
184203
}
185204

186205
protected override bool CloseOnCreate => false;
206+
207+
private static class Style
208+
{
209+
internal static readonly GUIStyle backgroundStyle;
210+
internal static readonly GUIStyle foldoutStyle;
211+
212+
internal static readonly GUIContent foldoutContent = new GUIContent("Inspect", "Show/Hide Properties");
213+
214+
internal static readonly GUILayoutOption[] foldoutOptions = new GUILayoutOption[]
215+
{
216+
GUILayout.Width(60.0f)
217+
};
218+
219+
static Style()
220+
{
221+
backgroundStyle = new GUIStyle(EditorStyles.helpBox)
222+
{
223+
padding = new RectOffset(13, 13, 8, 8)
224+
};
225+
foldoutStyle = new GUIStyle(EditorStyles.miniButton)
226+
{
227+
#if UNITY_2019_3_OR_NEWER
228+
fontSize = 10,
229+
#else
230+
fontSize = 9,
231+
#endif
232+
alignment = TextAnchor.MiddleCenter
233+
};
234+
}
235+
}
187236
}
188237
}

0 commit comments

Comments
 (0)