Compare commits

..

1 Commits

2 changed files with 59 additions and 25 deletions
@@ -121,6 +121,8 @@ namespace AssetUsageDetectorNamespace
private readonly HashSet<string> assetsToSearchPathsSet = new HashSet<string>();
// The root prefab objects in assetsToSearch that will be used to search for prefab references
private readonly List<GameObject> assetsToSearchRootPrefabs = new List<GameObject>( 4 );
// Path(s) of the assets that should be excluded from the search
private readonly HashSet<string> excludedAssetsPathsSet = new HashSet<string>();
// Results for the currently searched scene
private SearchResultGroup currentSearchResultGroup;
@@ -155,6 +157,7 @@ namespace AssetUsageDetectorNamespace
private Object currentSearchedObject;
private int currentDepth;
private bool dontSearchInSourceAssets;
private bool searchingSourceAssets;
private bool isInPlayMode;
@@ -238,6 +241,7 @@ namespace AssetUsageDetectorNamespace
this.propertyModifiers = searchParameters.propertyModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
this.searchDepthLimit = searchParameters.searchDepthLimit;
this.searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
this.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
// Initialize commonly used variables
searchResult = new List<SearchResultGroup>(); // Overall search results
@@ -254,6 +258,7 @@ namespace AssetUsageDetectorNamespace
assetsToSearchSet.Clear();
assetsToSearchPathsSet.Clear();
assetsToSearchRootPrefabs.Clear();
excludedAssetsPathsSet.Clear();
if( assetDependencyCache == null )
{
@@ -485,7 +490,6 @@ namespace AssetUsageDetectorNamespace
}
// Calculate the path(s) of the assets that won't be searched for references
HashSet<string> excludedAssetsPathsSet = new HashSet<string>();
if( searchParameters.excludedAssetsFromSearch != null )
{
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
@@ -503,9 +507,6 @@ namespace AssetUsageDetectorNamespace
}
}
if( searchParameters.dontSearchInSourceAssets )
excludedAssetsPathsSet.UnionWith( assetsToSearchPathsSet );
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", 0f ) )
throw new Exception( "Search aborted" );
@@ -608,7 +609,7 @@ namespace AssetUsageDetectorNamespace
}
// Searching source assets last prevents some references from being excluded due to callStack.ContainsFast
if( !searchParameters.dontSearchInSourceAssets )
if( !dontSearchInSourceAssets )
{
searchingSourceAssets = true;
@@ -728,7 +729,11 @@ namespace AssetUsageDetectorNamespace
string assetPath = AssetDatabase.GetAssetPath( obj );
if( !string.IsNullOrEmpty( assetPath ) )
{
assetsToSearchPathsSet.Add( assetPath );
if( dontSearchInSourceAssets && AssetDatabase.IsMainAsset( obj ) )
excludedAssetsPathsSet.Add( assetPath );
}
GameObject go = null;
if( obj is GameObject )
@@ -743,7 +748,6 @@ namespace AssetUsageDetectorNamespace
for( int i = assetsToSearchRootPrefabs.Count - 1; i >= 0; i-- )
{
Transform rootTransform = assetsToSearchRootPrefabs[i].transform;
if( transform.IsChildOf( rootTransform ) )
{
shouldAddRootPrefabEntry = false;
@@ -194,6 +194,18 @@ namespace AssetUsageDetectorNamespace.Extras
private void OnEnable()
{
visibleWindow = this;
#if UNITY_2018_3_OR_NEWER
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing += ReplacePrefabStageObjectsWithAssets;
#endif
}
private void OnDisable()
{
#if UNITY_2018_3_OR_NEWER
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing -= ReplacePrefabStageObjectsWithAssets;
#endif
}
private void OnDestroy()
@@ -565,25 +577,7 @@ namespace AssetUsageDetectorNamespace.Extras
SavePrefs();
#if UNITY_2018_3_OR_NEWER
// Try replacing prefab stage objects with their corresponding prefab assets
var openPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
if( openPrefabStage != null && openPrefabStage.stageHandle.IsValid() )
{
GameObject openPrefabStagePrefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStage.prefabAssetPath );
if( openPrefabStagePrefabAsset != null )
{
for( int i = 0; i < objectsToSearch.Count; i++ )
{
if( objectsToSearch[i].obj != null && !objectsToSearch[i].obj.Equals( null ) &&
objectsToSearch[i].obj is GameObject && openPrefabStage.IsPartOfPrefabContents( (GameObject) objectsToSearch[i].obj ) )
{
GameObject prefabStageObjectSource = ( (GameObject) objectsToSearch[i].obj ).FollowSymmetricHierarchy( openPrefabStagePrefabAsset );
if( prefabStageObjectSource != null )
objectsToSearch[i].obj = prefabStageObjectSource;
}
}
}
}
ReplacePrefabStageObjectsWithAssets( UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() );
#endif
// Start searching
@@ -609,6 +603,42 @@ namespace AssetUsageDetectorNamespace.Extras
}
}
#if UNITY_2018_3_OR_NEWER
// Try replacing searched objects who are part of currently open prefab stage with their corresponding prefab assets
public void ReplacePrefabStageObjectsWithAssets( UnityEditor.Experimental.SceneManagement.PrefabStage prefabStage )
{
if( prefabStage == null || !prefabStage.stageHandle.IsValid() )
return;
GameObject prefabAsset = AssetDatabase.LoadAssetAtPath<GameObject>( prefabStage.prefabAssetPath );
if( prefabAsset == null )
return;
for( int i = 0; i < objectsToSearch.Count; i++ )
{
Object obj = objectsToSearch[i].obj;
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
{
GameObject prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabAsset );
if( prefabStageObjectSource != null )
objectsToSearch[i].obj = prefabStageObjectSource;
List<ObjectToSearch.SubAsset> subAssets = objectsToSearch[i].subAssets;
for( int j = 0; j < subAssets.Count; j++ )
{
obj = subAssets[j].subAsset;
if( obj != null && !obj.Equals( null ) && obj is GameObject && prefabStage.IsPartOfPrefabContents( (GameObject) obj ) )
{
prefabStageObjectSource = ( (GameObject) obj ).FollowSymmetricHierarchy( prefabAsset );
if( prefabStageObjectSource != null )
subAssets[j].subAsset = prefabStageObjectSource;
}
}
}
}
}
#endif
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
{
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )