@@ -165,13 +165,42 @@ public static void RenamePrefabs(PrefabDataHolder[] prefabs, string name)
165165
166166 public static void BreakPrefab ( GameObject prefab )
167167 {
168+ EditorCoroutineUtility . StartCoroutineOwnerless ( Coroutines . BreakPrefab ( prefab ) ) ;
168169 }
169170
170171 private static class Coroutines
171172 {
173+ public static IEnumerator BreakPrefab ( GameObject prefab )
172174 {
175+ System . Diagnostics . Stopwatch sw = new System . Diagnostics . Stopwatch ( ) ;
176+ sw . Start ( ) ;
173177
178+ var transforms = prefab . GetComponentsInChildren < Transform > ( ) ;
179+ int progressId = Progress . Start ( "Break Prefab" , null , Progress . Options . Sticky ) ;
174180
181+ for ( int i = 0 ; i < transforms . Length ; i ++ )
182+ {
183+ if ( sw . Elapsed . TotalSeconds > 0.5f )
184+ {
185+ yield return null ;
186+ Progress . Report ( progressId , ( float ) i / transforms . Length , "Scanning Prefab: " + i + " / " + transforms . Length ) ;
187+ sw . Restart ( ) ;
188+ }
189+ var nameSplit = transforms [ i ] . gameObject . name . Split ( ' ' ) ;
190+ var prefabName = nameSplit [ 0 ] . Trim ( ) + ".prefab" ;
191+ var prefabPaths = AssetManager . ManifestStrings . Where ( x => x . Contains ( prefabName ) ) ;
192+ if ( prefabPaths . Count ( ) == 1 )
193+ {
194+ GameObject go = GameObject . Instantiate ( Load ( prefabPaths . First ( ) ) , PrefabParent ) ;
195+ go . transform . position = transforms [ i ] . gameObject . transform . position ;
196+ go . transform . rotation = transforms [ i ] . gameObject . transform . rotation ;
197+ go . transform . localScale = transforms [ i ] . gameObject . transform . localScale ;
198+ go . name = Load ( prefabPaths . First ( ) ) . name ;
199+ go . SetActive ( true ) ;
200+ }
201+ }
202+ GameObject . DestroyImmediate ( prefab ) ;
203+ Progress . Finish ( progressId ) ;
175204 }
176205
177206 public static IEnumerator SpawnPrefabs ( PrefabData [ ] prefabs , int progressID )
0 commit comments