mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc3a8069b4 | |||
| 98d1f43180 |
@@ -43,11 +43,12 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
public SceneSearchMode searchInScenes = SceneSearchMode.AllScenes;
|
||||
public Object[] searchInScenesSubset = null;
|
||||
public Object[] excludedScenesFromSearch = null;
|
||||
public bool searchInAssetsFolder = true;
|
||||
public Object[] searchInAssetsSubset = null;
|
||||
public Object[] excludedAssetsFromSearch = null;
|
||||
public bool dontSearchInSourceAssets = true;
|
||||
public Object[] excludedScenesFromSearch = null;
|
||||
public bool searchInProjectSettings = true;
|
||||
|
||||
public int searchDepthLimit = 4;
|
||||
public BindingFlags fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic;
|
||||
@@ -467,6 +468,17 @@ namespace AssetUsageDetectorNamespace
|
||||
} );
|
||||
}
|
||||
|
||||
// Find Project Settings to search for references
|
||||
// Don't search Project Settings if searched object(s) are all scene objects as Project Settings can't hold references to scene objects
|
||||
string[] projectSettingsToSearch = new string[0];
|
||||
if( searchParameters.searchInProjectSettings && assetsToSearchSet.Count > 0 )
|
||||
{
|
||||
string[] projectSettingsFiles = Directory.GetFiles( "ProjectSettings" );
|
||||
projectSettingsToSearch = new string[projectSettingsFiles.Length];
|
||||
for( int i = 0; i < projectSettingsFiles.Length; i++ )
|
||||
projectSettingsToSearch[i] = "ProjectSettings/" + Path.GetFileName( projectSettingsFiles[i] );
|
||||
}
|
||||
|
||||
// Initialize the nodes of searched asset(s)
|
||||
foreach( Object obj in objectsToSearchSet )
|
||||
searchedObjects.Add( obj.Hash(), PopReferenceNode( obj ) );
|
||||
@@ -477,6 +489,9 @@ namespace AssetUsageDetectorNamespace
|
||||
if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None )
|
||||
searchTotalProgress++; // DontDestroyOnLoad scene
|
||||
|
||||
if( searchParameters.showDetailedProgressBar )
|
||||
searchTotalProgress += projectSettingsToSearch.Length;
|
||||
|
||||
// Don't search assets if searched object(s) are all scene objects as assets can't hold references to scene objects
|
||||
if( searchParameters.searchInAssetsFolder && assetsToSearchSet.Count > 0 )
|
||||
{
|
||||
@@ -590,6 +605,31 @@ namespace AssetUsageDetectorNamespace
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
|
||||
// Search all assets inside ProjectSettings folder
|
||||
if( projectSettingsToSearch.Length > 0 )
|
||||
{
|
||||
currentSearchResultGroup = new SearchResultGroup( "Project Settings", SearchResultGroup.GroupType.ProjectSettings );
|
||||
|
||||
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching Project Settings", (float) searchProgress / searchTotalProgress ) )
|
||||
throw new Exception( "Search aborted" );
|
||||
|
||||
for( int i = 0; i < projectSettingsToSearch.Length; i++ )
|
||||
{
|
||||
if( searchParameters.showDetailedProgressBar && ++searchProgress % 30 == 1 && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching Project Settings", (float) searchProgress / searchTotalProgress ) )
|
||||
throw new Exception( "Search aborted" );
|
||||
|
||||
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( projectSettingsToSearch[i] );
|
||||
if( assets != null && assets.Length > 0 )
|
||||
{
|
||||
for( int j = 0; j < assets.Length; j++ )
|
||||
BeginSearchObject( assets[j] );
|
||||
}
|
||||
}
|
||||
|
||||
if( currentSearchResultGroup.NumberOfReferences > 0 )
|
||||
searchResult.Add( currentSearchResultGroup );
|
||||
}
|
||||
|
||||
// Search non-serializable variables for references while searching a scene in play mode
|
||||
if( isInPlayMode )
|
||||
searchSerializableVariablesOnly = false;
|
||||
@@ -641,7 +681,7 @@ namespace AssetUsageDetectorNamespace
|
||||
// Search through all the GameObjects under the DontDestroyOnLoad scene (if exists)
|
||||
if( isInPlayMode && searchParameters.searchInScenes != SceneSearchMode.None )
|
||||
{
|
||||
if( searchParameters.showDetailedProgressBar && EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) )
|
||||
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: DontDestroyOnLoad", 1f ) )
|
||||
throw new Exception( "Search aborted" );
|
||||
|
||||
currentSearchResultGroup = new SearchResultGroup( "DontDestroyOnLoad", SearchResultGroup.GroupType.DontDestroyOnLoad );
|
||||
@@ -753,9 +793,6 @@ namespace AssetUsageDetectorNamespace
|
||||
if( obj == null || obj.Equals( null ) )
|
||||
return;
|
||||
|
||||
if( obj is SceneAsset )
|
||||
return;
|
||||
|
||||
objectsToSearchSet.Add( obj );
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
@@ -968,10 +1005,21 @@ namespace AssetUsageDetectorNamespace
|
||||
if( unityObject != null )
|
||||
{
|
||||
// If the Object is an asset, search it in detail only if its dependencies contain at least one of the searched asset(s)
|
||||
if( unityObject.IsAsset() && ( assetsToSearchSet.Count == 0 || !AssetHasAnyReference( AssetDatabase.GetAssetPath( unityObject ) ) ) )
|
||||
if( unityObject.IsAsset() )
|
||||
{
|
||||
searchedObjects.Add( objHash, null );
|
||||
return null;
|
||||
if( assetsToSearchSet.Count == 0 )
|
||||
{
|
||||
searchedObjects.Add( objHash, null );
|
||||
return null;
|
||||
}
|
||||
|
||||
// AssetHasAnyReference always returns false for Project Settings assets, ignore its result for them
|
||||
string assetPath = AssetDatabase.GetAssetPath( unityObject );
|
||||
if( !assetPath.StartsWith( "ProjectSettings/" ) && !AssetHasAnyReference( assetPath ) )
|
||||
{
|
||||
searchedObjects.Add( objHash, null );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
callStack.Add( unityObject );
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
private const string PREFS_SEARCH_SCENES = "AUD_SceneSearch";
|
||||
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
|
||||
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
|
||||
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
|
||||
private const string PREFS_SEARCH_DEPTH_LIMIT = "AUD_Depth";
|
||||
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
|
||||
@@ -42,6 +43,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private bool searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
||||
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||
private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references
|
||||
private bool searchInProjectSettings = true; // Player Settings, Graphics Settings etc.
|
||||
|
||||
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
||||
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
|
||||
@@ -186,6 +188,7 @@ namespace AssetUsageDetectorNamespace
|
||||
mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||
mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||
mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||
mainWindow.searchInProjectSettings = searchParameters.searchInProjectSettings;
|
||||
mainWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||
mainWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||
mainWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||
@@ -269,6 +272,7 @@ namespace AssetUsageDetectorNamespace
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_SCENES, (int) GetSceneSearchMode( false ) );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
|
||||
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
|
||||
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
|
||||
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
|
||||
@@ -285,6 +289,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
|
||||
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, true );
|
||||
searchInProjectSettings = EditorPrefs.GetBool( PREFS_SEARCH_PROJECT_SETTINGS, true );
|
||||
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
|
||||
|
||||
// Fetch public, protected and private non-static fields and properties from objects by default
|
||||
@@ -378,8 +383,13 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
Color c = GUI.color;
|
||||
GUI.color = Color.cyan;
|
||||
|
||||
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
|
||||
|
||||
if( searchInAssetsFolder )
|
||||
@@ -397,7 +407,7 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
if( searchInAllScenes && !EditorApplication.isPlaying )
|
||||
GUI.enabled = false;
|
||||
@@ -433,6 +443,10 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
searchInProjectSettings = EditorGUILayout.ToggleLeft( "Project Settings (Player Settings, Graphics Settings etc.)", searchInProjectSettings );
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
//GUILayout.Box( "SEARCH SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
@@ -487,8 +501,12 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
//GUILayout.Space( 10 );
|
||||
|
||||
GUI.color = Color.cyan;
|
||||
|
||||
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
|
||||
|
||||
GUI.color = c;
|
||||
|
||||
lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
|
||||
showDetailedProgressBar = EditorGUILayout.ToggleLeft( "Show detailed progress bar (slower search)", showDetailedProgressBar );
|
||||
@@ -496,11 +514,14 @@ namespace AssetUsageDetectorNamespace
|
||||
GUILayout.Space( 10 );
|
||||
|
||||
// Don't let the user press the GO button without any valid search location
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder )
|
||||
if( !searchInAllScenes && !searchInOpenScenes && !searchInScenesInBuild && !searchInAssetsFolder && !searchInProjectSettings )
|
||||
GUI.enabled = false;
|
||||
|
||||
if( GUILayout.Button( "GO!", Utilities.GL_HEIGHT_30 ) )
|
||||
{
|
||||
InitiateSearch();
|
||||
GUIUtility.ExitGUI();
|
||||
}
|
||||
}
|
||||
else if( currentPhase == Phase.Complete )
|
||||
{
|
||||
@@ -564,7 +585,7 @@ namespace AssetUsageDetectorNamespace
|
||||
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster Refresh)", noAssetDatabaseChanges );
|
||||
searchResultDrawParameters.noAssetDatabaseChanges = noAssetDatabaseChanges;
|
||||
|
||||
GUILayout.Space( 10 );
|
||||
Utilities.DrawSeparatorLine();
|
||||
|
||||
GUILayout.Label( "Path drawing mode:" );
|
||||
|
||||
@@ -636,6 +657,7 @@ namespace AssetUsageDetectorNamespace
|
||||
excludedAssetsFromSearch = !excludedAssets.IsEmpty() ? excludedAssets.ToArray() : null,
|
||||
dontSearchInSourceAssets = dontSearchInSourceAssets,
|
||||
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
|
||||
searchInProjectSettings = searchInProjectSettings,
|
||||
//fieldModifiers = fieldModifiers,
|
||||
//propertyModifiers = propertyModifiers,
|
||||
//searchDepthLimit = searchDepthLimit,
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace AssetUsageDetectorNamespace
|
||||
Object[] searchInScenesSubset = m_searchParameters.searchInScenesSubset;
|
||||
bool searchInAssetsFolder = m_searchParameters.searchInAssetsFolder;
|
||||
Object[] searchInAssetsSubset = m_searchParameters.searchInAssetsSubset;
|
||||
bool searchInProjectSettings = m_searchParameters.searchInProjectSettings;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -134,6 +135,15 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
else if( searchResultGroup.Type == SearchResultGroup.GroupType.ProjectSettings )
|
||||
{
|
||||
m_searchParameters.searchInScenes = SceneSearchMode.None;
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = true;
|
||||
}
|
||||
else if( searchResultGroup.Type == SearchResultGroup.GroupType.Scene )
|
||||
{
|
||||
@@ -141,6 +151,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = new Object[1] { AssetDatabase.LoadAssetAtPath<SceneAsset>( searchResultGroup.Title ) };
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -148,6 +159,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = null;
|
||||
m_searchParameters.searchInAssetsFolder = false;
|
||||
m_searchParameters.searchInAssetsSubset = null;
|
||||
m_searchParameters.searchInProjectSettings = false;
|
||||
}
|
||||
|
||||
m_searchParameters.lazySceneSearch = false;
|
||||
@@ -188,6 +200,7 @@ namespace AssetUsageDetectorNamespace
|
||||
m_searchParameters.searchInScenesSubset = searchInScenesSubset;
|
||||
m_searchParameters.searchInAssetsFolder = searchInAssetsFolder;
|
||||
m_searchParameters.searchInAssetsSubset = searchInAssetsSubset;
|
||||
m_searchParameters.searchInProjectSettings = searchInProjectSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +426,7 @@ namespace AssetUsageDetectorNamespace
|
||||
// Custom class to hold the results for a single scene or Assets folder
|
||||
public class SearchResultGroup
|
||||
{
|
||||
public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2 };
|
||||
public enum GroupType { Assets = 0, Scene = 1, DontDestroyOnLoad = 2, ProjectSettings = 3 };
|
||||
|
||||
// Custom struct to hold a single path to a reference
|
||||
public struct ReferencePath
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace AssetUsageDetectorNamespace
|
||||
public static readonly GUILayoutOption GL_WIDTH_100 = GUILayout.Width( 100 );
|
||||
public static readonly GUILayoutOption GL_WIDTH_250 = GUILayout.Width( 250 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_0 = GUILayout.Height( 0 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_2 = GUILayout.Height( 2 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_30 = GUILayout.Height( 30 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_35 = GUILayout.Height( 35 );
|
||||
public static readonly GUILayoutOption GL_HEIGHT_40 = GUILayout.Height( 40 );
|
||||
@@ -105,7 +106,7 @@ namespace AssetUsageDetectorNamespace
|
||||
|
||||
if( normalState.background == null || normalState.background.Equals( null ) )
|
||||
{
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 );
|
||||
Texture2D backgroundTexture = new Texture2D( 1, 1 ) { hideFlags = HideFlags.HideAndDontSave };
|
||||
backgroundTexture.SetPixel( 0, 0, new Color( 0.88f, 0.88f, 0.88f, 0.85f ) );
|
||||
backgroundTexture.Apply();
|
||||
|
||||
@@ -474,6 +475,13 @@ namespace AssetUsageDetectorNamespace
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void DrawSeparatorLine()
|
||||
{
|
||||
GUILayout.Space( 4 );
|
||||
GUILayout.Box( "", GL_HEIGHT_2, GL_EXPAND_WIDTH );
|
||||
GUILayout.Space( 4 );
|
||||
}
|
||||
|
||||
public static bool ContainsFast<T>( this List<T> list, T element )
|
||||
{
|
||||
if( !( element is ValueType ) )
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "1.7.8",
|
||||
"version": "1.8.0",
|
||||
"description": "This editor extension helps you figure out at which places an asset or GameObject is used, i.e. lists the objects that refer to the asset. It is possible to search for references in the Assets folder (Project view) and/or in the scene(s) of your project. You can also search for references while in Play mode!"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user