@@ -269,6 +269,7 @@ static GameObject CalculatePreviewGameObject(Animator selectedAnimator, Motion m
269
269
270
270
// Use selected preview
271
271
GameObject selected = EditorHelper . InstantiateGoByPrefab ( selectedAnimator . gameObject , null ) ;
272
+ selected . tag = Constants . PREVIRE_TAG ;
272
273
InitInstantiatedPreviewRecursive ( selected ) ;
273
274
if ( IsValidPreviewGameObject ( selected , ModelImporterAnimationType . None ) )
274
275
return selected ;
@@ -315,6 +316,7 @@ void SetupBounds(GameObject go)
315
316
if ( go != null )
316
317
{
317
318
m_PreviewInstance = ReflectionHelper . Instance . EditorUtility . InstantiateForAnimatorPreview ( go ) ;
319
+ m_PreviewInstance . tag = Constants . PREVIRE_TAG ;
318
320
previewUtility . AddSingleGO ( m_PreviewInstance ) ;
319
321
320
322
Bounds bounds = new Bounds ( m_PreviewInstance . transform . position , Vector3 . zero ) ;
@@ -351,6 +353,7 @@ void InitInstance(Animator scenePreviewObject, Motion motion)
351
353
{
352
354
GameObject referenceGO = ( GameObject ) EditorGUIUtility . Load ( "Avatar/dial_flat.prefab" ) ;
353
355
m_ReferenceInstance = ( GameObject ) Object . Instantiate ( referenceGO , Vector3 . zero , Quaternion . identity ) ;
356
+ m_ReferenceInstance . tag = Constants . PREVIRE_TAG ;
354
357
InitInstantiatedPreviewRecursive ( m_ReferenceInstance ) ;
355
358
previewUtility . AddSingleGO ( m_ReferenceInstance ) ;
356
359
}
@@ -359,6 +362,7 @@ void InitInstance(Animator scenePreviewObject, Motion motion)
359
362
{
360
363
GameObject directionGO = ( GameObject ) EditorGUIUtility . Load ( "Avatar/arrow.fbx" ) ;
361
364
m_DirectionInstance = ( GameObject ) Object . Instantiate ( directionGO , Vector3 . zero , Quaternion . identity ) ;
365
+ m_DirectionInstance . tag = Constants . PREVIRE_TAG ;
362
366
InitInstantiatedPreviewRecursive ( m_DirectionInstance ) ;
363
367
previewUtility . AddSingleGO ( m_DirectionInstance ) ;
364
368
}
@@ -367,6 +371,7 @@ void InitInstance(Animator scenePreviewObject, Motion motion)
367
371
{
368
372
GameObject pivotGO = ( GameObject ) EditorGUIUtility . Load ( "Avatar/root.fbx" ) ;
369
373
m_PivotInstance = ( GameObject ) Object . Instantiate ( pivotGO , Vector3 . zero , Quaternion . identity ) ;
374
+ m_PivotInstance . tag = Constants . PREVIRE_TAG ;
370
375
InitInstantiatedPreviewRecursive ( m_PivotInstance ) ;
371
376
previewUtility . AddSingleGO ( m_PivotInstance ) ;
372
377
}
@@ -375,6 +380,7 @@ void InitInstance(Animator scenePreviewObject, Motion motion)
375
380
{
376
381
GameObject rootGO = ( GameObject ) EditorGUIUtility . Load ( "Avatar/root.fbx" ) ;
377
382
m_RootInstance = ( GameObject ) Object . Instantiate ( rootGO , Vector3 . zero , Quaternion . identity ) ;
383
+ m_RootInstance . tag = Constants . PREVIRE_TAG ;
378
384
InitInstantiatedPreviewRecursive ( m_RootInstance ) ;
379
385
previewUtility . AddSingleGO ( m_RootInstance ) ;
380
386
}
@@ -456,14 +462,7 @@ private void Init()
456
462
457
463
public void OnDisable ( )
458
464
{
459
- if ( m_PreviewUtility != null )
460
- {
461
- m_PreviewUtility . Cleanup ( ) ;
462
- m_PreviewUtility = null ;
463
- }
464
-
465
- if ( timeControl != null )
466
- timeControl . OnDisable ( ) ;
465
+ OnDestroy ( ) ;
467
466
}
468
467
469
468
public void OnDestroy ( )
@@ -1160,5 +1159,16 @@ internal static void SetEnabledRecursive(GameObject go, bool enabled)
1160
1159
renderer . enabled = enabled ;
1161
1160
}
1162
1161
}
1162
+
1163
+ [ UnityEditor . Callbacks . DidReloadScripts ]
1164
+ private static void OnScriptsReloaded ( )
1165
+ {
1166
+ var gameobjects = GameObject . FindGameObjectsWithTag ( Constants . PREVIRE_TAG ) ;
1167
+ foreach ( var item in gameobjects )
1168
+ {
1169
+ GameObject . DestroyImmediate ( item ) ;
1170
+ }
1171
+
1172
+ }
1163
1173
}
1164
1174
}
0 commit comments