9
9
namespace Toolbox . Editor . Wizards
10
10
{
11
11
using Toolbox . Editor . Internal ;
12
+ using Editor = UnityEditor . Editor ;
12
13
13
14
/// <summary>
14
15
/// Utility window responsible for creation of <see cref="ScriptableObject"/>s.
@@ -34,7 +35,7 @@ private class CreationData
34
35
{
35
36
private bool IsDefaultObjectValid ( )
36
37
{
37
- return DefaultObject != null && DefaultObject . GetType ( ) == InstanceType ;
38
+ return BlueprintObject != null && BlueprintObject . GetType ( ) == InstanceType ;
38
39
}
39
40
40
41
public void Validate ( )
@@ -47,7 +48,7 @@ public void Validate()
47
48
InstancesCount = Mathf . Max ( InstancesCount , 1 ) ;
48
49
if ( ! IsDefaultObjectValid ( ) )
49
50
{
50
- DefaultObject = null ;
51
+ BlueprintObject = null ;
51
52
}
52
53
}
53
54
@@ -59,7 +60,7 @@ public void Validate()
59
60
public int InstancesCount { get ; set ; } = 1 ;
60
61
[ field: SerializeField , InLineEditor ]
61
62
[ field: Tooltip ( "Will be used as a blueprint for all created ScriptableObjects." ) ]
62
- public Object DefaultObject { get ; set ; }
63
+ public Object BlueprintObject { get ; set ; }
63
64
}
64
65
65
66
private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintScriptableObject ( ) ;
@@ -69,7 +70,13 @@ public void Validate()
69
70
private readonly CreationData data = new CreationData ( ) ;
70
71
71
72
private bool inspectDefaultObject ;
72
- private bool useSearchField = true ;
73
+ private Editor blueprintObjectEditor ;
74
+
75
+ protected override void OnDestroy ( )
76
+ {
77
+ base . OnDestroy ( ) ;
78
+ DestroyImmediate ( blueprintObjectEditor ) ;
79
+ }
73
80
74
81
[ MenuItem ( "Assets/Create/Editor Toolbox/Wizards/ScriptableObject Creation Wizard" , priority = 5 ) ]
75
82
internal static void Initialize ( )
@@ -83,10 +90,8 @@ private void DrawSettingsPanel()
83
90
{
84
91
EditorGUILayout . LabelField ( "Settings" , EditorStyles . boldLabel ) ;
85
92
86
- useSearchField = EditorGUILayout . ToggleLeft ( "Use Search Field" , useSearchField ) ;
87
-
88
93
var rect = EditorGUILayout . GetControlRect ( true ) ;
89
- typeField . OnGui ( rect , useSearchField , OnTypeSelected , data . InstanceType ) ;
94
+ typeField . OnGui ( rect , true , OnTypeSelected , data . InstanceType ) ;
90
95
if ( data . InstanceType == null )
91
96
{
92
97
return ;
@@ -97,7 +102,15 @@ private void DrawSettingsPanel()
97
102
EditorGUI . BeginChangeCheck ( ) ;
98
103
data . InstanceName = EditorGUILayout . TextField ( Style . nameContent , data . InstanceName ) ;
99
104
data . InstancesCount = EditorGUILayout . IntField ( Style . countContent , data . InstancesCount ) ;
100
- var assignedInstance = EditorGUILayout . ObjectField ( Style . objectContent , data . DefaultObject , data . InstanceType , false ) ;
105
+
106
+ EditorGUI . BeginChangeCheck ( ) ;
107
+ var assignedInstance = EditorGUILayout . ObjectField ( Style . objectContent , data . BlueprintObject , data . InstanceType , false ) ;
108
+ data . BlueprintObject = assignedInstance ;
109
+ if ( EditorGUI . EndChangeCheck ( ) )
110
+ {
111
+ UpdateBlueprintObjectEditor ( ) ;
112
+ }
113
+
101
114
if ( assignedInstance != null )
102
115
{
103
116
inspectDefaultObject = GUILayout . Toggle ( inspectDefaultObject ,
@@ -112,11 +125,11 @@ private void DrawSettingsPanel()
112
125
{
113
126
using ( new EditorGUILayout . VerticalScope ( Style . backgroundStyle ) )
114
127
{
115
- ToolboxEditorGui . DrawObjectProperties ( assignedInstance ) ;
128
+ blueprintObjectEditor . OnInspectorGUI ( ) ;
116
129
}
117
130
}
118
131
119
- data . DefaultObject = assignedInstance ;
132
+
120
133
if ( EditorGUI . EndChangeCheck ( ) )
121
134
{
122
135
OnWizardUpdate ( ) ;
@@ -147,7 +160,7 @@ private void CreateObjects(CreationData data)
147
160
var instancesCount = data . InstancesCount ;
148
161
for ( var i = 0 ; i < instancesCount ; i ++ )
149
162
{
150
- var instance = CreateObject ( data . InstanceType , data . DefaultObject ) ;
163
+ var instance = CreateObject ( data . InstanceType , data . BlueprintObject ) ;
151
164
CreateAsset ( instance , data . InstanceName , assetPath , i ) ;
152
165
}
153
166
@@ -181,6 +194,25 @@ private void OnTypeSelected(Type type)
181
194
}
182
195
}
183
196
197
+ private void UpdateBlueprintObjectEditor ( )
198
+ {
199
+ DestroyImmediate ( blueprintObjectEditor ) ;
200
+ blueprintObjectEditor = null ;
201
+
202
+ var targetObject = data . BlueprintObject ;
203
+ if ( targetObject == null )
204
+ {
205
+ return ;
206
+ }
207
+
208
+ blueprintObjectEditor = Editor . CreateEditor ( targetObject ) ;
209
+ blueprintObjectEditor . hideFlags = HideFlags . HideAndDontSave ;
210
+ if ( blueprintObjectEditor is ToolboxEditor toolboxEditor )
211
+ {
212
+ toolboxEditor . IgnoreProperty ( PropertyUtility . Defaults . scriptPropertyName ) ;
213
+ }
214
+ }
215
+
184
216
private static string GetActiveFolderPath ( )
185
217
{
186
218
var projectWindowUtilType = typeof ( ProjectWindowUtil ) ;
@@ -219,8 +251,8 @@ private static class Style
219
251
internal static readonly GUIStyle foldoutStyle ;
220
252
221
253
internal static readonly GUIContent nameContent = new GUIContent ( "Instance Name" ) ;
222
- internal static readonly GUIContent countContent = new GUIContent ( "Instances To Create " , "Indicates how many instances will be created." ) ;
223
- internal static readonly GUIContent objectContent = new GUIContent ( "Default Object" , "Will be used as a blueprint for all created ScriptableObjects." ) ;
254
+ internal static readonly GUIContent countContent = new GUIContent ( "Instances Count " , "Indicates how many instances will be created." ) ;
255
+ internal static readonly GUIContent objectContent = new GUIContent ( "Blueprint Object" , "Will be used as a blueprint for all created ScriptableObjects." ) ;
224
256
internal static readonly GUIContent foldoutContent = new GUIContent ( "Inspect" , "Show/Hide Properties" ) ;
225
257
226
258
internal static readonly GUILayoutOption [ ] foldoutOptions = new GUILayoutOption [ ]
0 commit comments