mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-21 07:22:37 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d24aa4939 | |||
| c16bef45cd |
@@ -28,6 +28,7 @@ There are 5 ways to install this plugin:
|
|||||||
|
|
||||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
||||||
- or, right click an object and select **Search For References**
|
- or, right click an object and select **Search For References**
|
||||||
|
- In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the references are formed. If a node's label contains text inside square brackets (e.g. *\[Child object\]*), then that text describes how that node is connected to the node to its left
|
||||||
|
|
||||||
## FEATURES
|
## FEATURES
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ using UnityEngine.UI;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
#if UNITY_2017_1_OR_NEWER
|
#if UNITY_2017_1_OR_NEWER
|
||||||
using UnityEngine.U2D;
|
using UnityEngine.U2D;
|
||||||
|
using UnityEngine.Playables;
|
||||||
|
#endif
|
||||||
#if UNITY_2018_2_OR_NEWER
|
#if UNITY_2018_2_OR_NEWER
|
||||||
using UnityEditor.U2D;
|
using UnityEditor.U2D;
|
||||||
#endif
|
#endif
|
||||||
using UnityEngine.Playables;
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
using UnityEditor.Compilation;
|
||||||
#endif
|
#endif
|
||||||
#if UNITY_2017_2_OR_NEWER
|
#if UNITY_2017_2_OR_NEWER
|
||||||
using UnityEngine.Tilemaps;
|
using UnityEngine.Tilemaps;
|
||||||
@@ -104,6 +107,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
#pragma warning disable 0649 // The fields' values are assigned via JsonUtility
|
||||||
|
[Serializable]
|
||||||
|
private struct AssemblyDefinitionReferences
|
||||||
|
{
|
||||||
|
public string reference; // Used by AssemblyDefinitionReferenceAssets
|
||||||
|
public List<string> references; // Used by AssemblyDefinitionAssets
|
||||||
|
}
|
||||||
|
#pragma warning restore 0649
|
||||||
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// A set that contains the searched asset(s) and their sub-assets (if any)
|
// A set that contains the searched asset(s) and their sub-assets (if any)
|
||||||
@@ -123,6 +137,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// Path(s) of the assets that should be excluded from the search
|
// Path(s) of the assets that should be excluded from the search
|
||||||
private readonly HashSet<string> excludedAssetsPathsSet = new HashSet<string>();
|
private readonly HashSet<string> excludedAssetsPathsSet = new HashSet<string>();
|
||||||
|
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
// Path(s) of the Assembly Definition Files in objectsToSearchSet (Value: files themselves)
|
||||||
|
private readonly Dictionary<string, Object> assemblyDefinitionFilesToSearch = new Dictionary<string, Object>( 8 );
|
||||||
|
#endif
|
||||||
|
|
||||||
// Results for the currently searched scene
|
// Results for the currently searched scene
|
||||||
private SearchResultGroup currentSearchResultGroup;
|
private SearchResultGroup currentSearchResultGroup;
|
||||||
|
|
||||||
@@ -258,6 +277,9 @@ namespace AssetUsageDetectorNamespace
|
|||||||
assetsToSearchPathsSet.Clear();
|
assetsToSearchPathsSet.Clear();
|
||||||
assetsToSearchRootPrefabs.Clear();
|
assetsToSearchRootPrefabs.Clear();
|
||||||
excludedAssetsPathsSet.Clear();
|
excludedAssetsPathsSet.Clear();
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
assemblyDefinitionFilesToSearch.Clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
if( assetDependencyCache == null )
|
if( assetDependencyCache == null )
|
||||||
{
|
{
|
||||||
@@ -291,6 +313,12 @@ namespace AssetUsageDetectorNamespace
|
|||||||
{ typeof( AnimationClip ), SearchAnimationClip },
|
{ typeof( AnimationClip ), SearchAnimationClip },
|
||||||
#if UNITY_2017_1_OR_NEWER
|
#if UNITY_2017_1_OR_NEWER
|
||||||
{ typeof( SpriteAtlas ), SearchSpriteAtlas },
|
{ typeof( SpriteAtlas ), SearchSpriteAtlas },
|
||||||
|
#endif
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
{ typeof( UnityEditorInternal.AssemblyDefinitionAsset ), SearchAssemblyDefinitionFile },
|
||||||
|
#endif
|
||||||
|
#if UNITY_2019_2_OR_NEWER
|
||||||
|
{ typeof( UnityEditorInternal.AssemblyDefinitionReferenceAsset ), SearchAssemblyDefinitionFile },
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -360,7 +388,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
// Find the scenes to search for references
|
// Find the scenes to search for references
|
||||||
HashSet<string> scenesToSearch = new HashSet<string>();
|
HashSet<string> scenesToSearch = new HashSet<string>();
|
||||||
if( searchParameters.searchInScenesSubset != null )
|
if( searchParameters.searchInScenesSubset != null && searchParameters.searchInScenesSubset.Length > 0 )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchParameters.searchInScenesSubset )
|
foreach( Object obj in searchParameters.searchInScenesSubset )
|
||||||
{
|
{
|
||||||
@@ -456,7 +484,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
// Get the paths of all assets that are to be searched
|
// Get the paths of all assets that are to be searched
|
||||||
IEnumerable<string> assetPaths;
|
IEnumerable<string> assetPaths;
|
||||||
if( searchParameters.searchInAssetsSubset == null )
|
if( searchParameters.searchInAssetsSubset == null || searchParameters.searchInAssetsSubset.Length == 0 )
|
||||||
{
|
{
|
||||||
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
|
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
|
||||||
assetPaths = allAssetPaths;
|
assetPaths = allAssetPaths;
|
||||||
@@ -506,6 +534,25 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
if( assemblyDefinitionFilesToSearch.Count > 0 )
|
||||||
|
{
|
||||||
|
// AssetDatabase.GetDependencies doesn't return references from Assembly Definition Files to their Assembly Definition References,
|
||||||
|
// so if we are searching for an Assembly Definition File's usages, we must search all Assembly Definition Files' references
|
||||||
|
// manually. By adding all these files to assetsToSearchPathsSet, we make sure that AssetHasAnyReference returns true for
|
||||||
|
// these assets and they don't get excluded from the search
|
||||||
|
string[] assemblyDefinitionFilesGuids = AssetDatabase.FindAssets( "t:AssemblyDefinitionAsset" );
|
||||||
|
for( int i = 0; i < assemblyDefinitionFilesGuids.Length; i++ )
|
||||||
|
assetsToSearchPathsSet.Add( AssetDatabase.GUIDToAssetPath( assemblyDefinitionFilesGuids[i] ) );
|
||||||
|
|
||||||
|
#if UNITY_2019_2_OR_NEWER
|
||||||
|
assemblyDefinitionFilesGuids = AssetDatabase.FindAssets( "t:AssemblyDefinitionReferenceAsset" );
|
||||||
|
for( int i = 0; i < assemblyDefinitionFilesGuids.Length; i++ )
|
||||||
|
assetsToSearchPathsSet.Add( AssetDatabase.GUIDToAssetPath( assemblyDefinitionFilesGuids[i] ) );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", 0f ) )
|
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching assets", 0f ) )
|
||||||
throw new Exception( "Search aborted" );
|
throw new Exception( "Search aborted" );
|
||||||
|
|
||||||
@@ -760,6 +807,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( shouldAddRootPrefabEntry )
|
if( shouldAddRootPrefabEntry )
|
||||||
assetsToSearchRootPrefabs.Add( go );
|
assetsToSearchRootPrefabs.Add( go );
|
||||||
}
|
}
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
else if( obj is UnityEditorInternal.AssemblyDefinitionAsset )
|
||||||
|
{
|
||||||
|
if( !string.IsNullOrEmpty( assetPath ) )
|
||||||
|
assemblyDefinitionFilesToSearch[assetPath] = obj;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -931,7 +985,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = PopReferenceNode( unityObject );
|
result = PopReferenceNode( unityObject );
|
||||||
SearchWithSerializedObject( result );
|
SearchVariablesWithSerializedObject( result );
|
||||||
}
|
}
|
||||||
|
|
||||||
callStack.RemoveAt( callStack.Count - 1 );
|
callStack.RemoveAt( callStack.Count - 1 );
|
||||||
@@ -946,7 +1000,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
currentDepth++;
|
currentDepth++;
|
||||||
|
|
||||||
result = PopReferenceNode( obj );
|
result = PopReferenceNode( obj );
|
||||||
SearchFieldsAndPropertiesOf( result );
|
SearchVariablesWithReflection( result );
|
||||||
|
|
||||||
currentDepth--;
|
currentDepth--;
|
||||||
callStack.RemoveAt( callStack.Count - 1 );
|
callStack.RemoveAt( callStack.Count - 1 );
|
||||||
@@ -1069,7 +1123,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SearchWithSerializedObject( referenceNode );
|
SearchVariablesWithSerializedObject( referenceNode );
|
||||||
return referenceNode;
|
return referenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1251,6 +1305,43 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
// Find references from an Assembly Definition File to its Assembly Definition References
|
||||||
|
private ReferenceNode SearchAssemblyDefinitionFile( Object unityObject )
|
||||||
|
{
|
||||||
|
if( assemblyDefinitionFilesToSearch.Count == 0 )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
AssemblyDefinitionReferences assemblyDefinitionFile = JsonUtility.FromJson<AssemblyDefinitionReferences>( ( (TextAsset) unityObject ).text );
|
||||||
|
ReferenceNode referenceNode = PopReferenceNode( unityObject );
|
||||||
|
|
||||||
|
if( !string.IsNullOrEmpty( assemblyDefinitionFile.reference ) )
|
||||||
|
{
|
||||||
|
if( assemblyDefinitionFile.references == null )
|
||||||
|
assemblyDefinitionFile.references = new List<string>( 1 ) { assemblyDefinitionFile.reference };
|
||||||
|
else
|
||||||
|
assemblyDefinitionFile.references.Add( assemblyDefinitionFile.reference );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( assemblyDefinitionFile.references != null )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < assemblyDefinitionFile.references.Count; i++ )
|
||||||
|
{
|
||||||
|
#if UNITY_2019_1_OR_NEWER
|
||||||
|
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyReference( assemblyDefinitionFile.references[i] );
|
||||||
|
#else
|
||||||
|
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
|
||||||
|
#endif
|
||||||
|
Object searchedAssemblyDefinitionFile;
|
||||||
|
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
|
||||||
|
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return referenceNode;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Find references from an Animation/Animator component to the objects that it animates
|
// Find references from an Animation/Animator component to the objects that it animates
|
||||||
private void SearchAnimatedObjects( ReferenceNode referenceNode )
|
private void SearchAnimatedObjects( ReferenceNode referenceNode )
|
||||||
{
|
{
|
||||||
@@ -1330,8 +1421,8 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search through field and properties of an object for references with SerializedObject
|
// Search through variables of an object with SerializedObject
|
||||||
private void SearchWithSerializedObject( ReferenceNode referenceNode )
|
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode )
|
||||||
{
|
{
|
||||||
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
||||||
{
|
{
|
||||||
@@ -1378,11 +1469,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use reflection algorithm as fallback
|
// Use reflection algorithm as fallback
|
||||||
SearchFieldsAndPropertiesOf( referenceNode );
|
SearchVariablesWithReflection( referenceNode );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search through field and properties of an object for references
|
// Search through variables of an object with reflection
|
||||||
private void SearchFieldsAndPropertiesOf( ReferenceNode referenceNode )
|
private void SearchVariablesWithReflection( ReferenceNode referenceNode )
|
||||||
{
|
{
|
||||||
// Get filtered variables for this object
|
// Get filtered variables for this object
|
||||||
VariableGetterHolder[] variables = GetFilteredVariablesForType( referenceNode.nodeObject.GetType() );
|
VariableGetterHolder[] variables = GetFilteredVariablesForType( referenceNode.nodeObject.GetType() );
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// To work nicely with GUILayout and scroll view
|
// To work nicely with GUILayout and scroll view
|
||||||
EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, GUILayout.Height( guiHeight ) );
|
EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, GUILayout.Height( guiHeight ) );
|
||||||
|
|
||||||
if( parameters.tooltip != null )
|
if( !string.IsNullOrEmpty( parameters.tooltip ) )
|
||||||
{
|
{
|
||||||
// Show tooltip at mouse position
|
// Show tooltip at mouse position
|
||||||
Vector2 mousePos = Event.current.mousePosition;
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
normalState = m_tooltipGUIStyle.normal;
|
normalState = m_tooltipGUIStyle.normal;
|
||||||
|
|
||||||
normalState.background = null;
|
normalState.background = null;
|
||||||
|
normalState.scaledBackgrounds = new Texture2D[0];
|
||||||
normalState.textColor = Color.black;
|
normalState.textColor = Color.black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ This tool helps you find usages of the selected asset(s) and/or Object(s) in you
|
|||||||
2. HOW TO
|
2. HOW TO
|
||||||
Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References".
|
Open "Window-Asset Usage Detector" window, configure the settings and hit GO! You can also right click an object and select "Search For References".
|
||||||
|
|
||||||
|
In the search results page, each row represents a reference to the searched Object(s). Rows can be traversed from left to right to see how the
|
||||||
|
references are formed. If a node's label contains text inside square brackets (e.g. [Child object]), then that text describes how that node is
|
||||||
|
connected to the node to its left.
|
||||||
|
|
||||||
3. KNOWN LIMITATIONS
|
3. KNOWN LIMITATIONS
|
||||||
- static variables are not searched
|
- static variables are not searched
|
||||||
- GUIText materials are not searched
|
- GUIText materials are not searched
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.yasirkula.assetusagedetector",
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
"displayName": "Asset Usage Detector",
|
"displayName": "Asset Usage Detector",
|
||||||
"version": "1.7.7",
|
"version": "1.7.8",
|
||||||
"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!"
|
"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