99namespace Toolbox . Editor . Wizards
1010{
1111 using Toolbox . Editor . Internal ;
12+ using Editor = UnityEditor . Editor ;
1213
1314 /// <summary>
1415 /// Utility window responsible for creation of <see cref="ScriptableObject"/>s.
@@ -34,7 +35,7 @@ private class CreationData
3435 {
3536 private bool IsDefaultObjectValid ( )
3637 {
37- return DefaultObject != null && DefaultObject . GetType ( ) == InstanceType ;
38+ return BlueprintObject != null && BlueprintObject . GetType ( ) == InstanceType ;
3839 }
3940
4041 public void Validate ( )
@@ -47,7 +48,7 @@ public void Validate()
4748 InstancesCount = Mathf . Max ( InstancesCount , 1 ) ;
4849 if ( ! IsDefaultObjectValid ( ) )
4950 {
50- DefaultObject = null ;
51+ BlueprintObject = null ;
5152 }
5253 }
5354
@@ -59,7 +60,7 @@ public void Validate()
5960 public int InstancesCount { get ; set ; } = 1 ;
6061 [ field: SerializeField , InLineEditor ]
6162 [ field: Tooltip ( "Will be used as a blueprint for all created ScriptableObjects." ) ]
62- public Object DefaultObject { get ; set ; }
63+ public Object BlueprintObject { get ; set ; }
6364 }
6465
6566 private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintScriptableObject ( ) ;
@@ -69,7 +70,13 @@ public void Validate()
6970 private readonly CreationData data = new CreationData ( ) ;
7071
7172 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+ }
7380
7481 [ MenuItem ( "Assets/Create/Editor Toolbox/Wizards/ScriptableObject Creation Wizard" , priority = 5 ) ]
7582 internal static void Initialize ( )
@@ -83,10 +90,8 @@ private void DrawSettingsPanel()
8390 {
8491 EditorGUILayout . LabelField ( "Settings" , EditorStyles . boldLabel ) ;
8592
86- useSearchField = EditorGUILayout . ToggleLeft ( "Use Search Field" , useSearchField ) ;
87-
8893 var rect = EditorGUILayout . GetControlRect ( true ) ;
89- typeField . OnGui ( rect , useSearchField , OnTypeSelected , data . InstanceType ) ;
94+ typeField . OnGui ( rect , true , OnTypeSelected , data . InstanceType ) ;
9095 if ( data . InstanceType == null )
9196 {
9297 return ;
@@ -97,7 +102,15 @@ private void DrawSettingsPanel()
97102 EditorGUI . BeginChangeCheck ( ) ;
98103 data . InstanceName = EditorGUILayout . TextField ( Style . nameContent , data . InstanceName ) ;
99104 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+
101114 if ( assignedInstance != null )
102115 {
103116 inspectDefaultObject = GUILayout . Toggle ( inspectDefaultObject ,
@@ -112,11 +125,11 @@ private void DrawSettingsPanel()
112125 {
113126 using ( new EditorGUILayout . VerticalScope ( Style . backgroundStyle ) )
114127 {
115- ToolboxEditorGui . DrawObjectProperties ( assignedInstance ) ;
128+ blueprintObjectEditor . OnInspectorGUI ( ) ;
116129 }
117130 }
118131
119- data . DefaultObject = assignedInstance ;
132+
120133 if ( EditorGUI . EndChangeCheck ( ) )
121134 {
122135 OnWizardUpdate ( ) ;
@@ -147,7 +160,7 @@ private void CreateObjects(CreationData data)
147160 var instancesCount = data . InstancesCount ;
148161 for ( var i = 0 ; i < instancesCount ; i ++ )
149162 {
150- var instance = CreateObject ( data . InstanceType , data . DefaultObject ) ;
163+ var instance = CreateObject ( data . InstanceType , data . BlueprintObject ) ;
151164 CreateAsset ( instance , data . InstanceName , assetPath , i ) ;
152165 }
153166
@@ -181,6 +194,25 @@ private void OnTypeSelected(Type type)
181194 }
182195 }
183196
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+
184216 private static string GetActiveFolderPath ( )
185217 {
186218 var projectWindowUtilType = typeof ( ProjectWindowUtil ) ;
@@ -219,8 +251,8 @@ private static class Style
219251 internal static readonly GUIStyle foldoutStyle ;
220252
221253 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." ) ;
224256 internal static readonly GUIContent foldoutContent = new GUIContent ( "Inspect" , "Show/Hide Properties" ) ;
225257
226258 internal static readonly GUILayoutOption [ ] foldoutOptions = new GUILayoutOption [ ]
0 commit comments