mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-20 23:12:38 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d24aa4939 | |||
| c16bef45cd | |||
| 7b939a2104 | |||
| ccf3e2f733 | |||
| c6b1edfd93 | |||
| 7358b12609 | |||
| ab539adc54 | |||
| 4909b9c558 | |||
| 94381ff7d2 | |||
| 17d3b33e8e | |||
| ff193224e9 | |||
| 51abec24d7 |
@@ -0,0 +1,46 @@
|
|||||||
|
# Asset Usage Detector for Unity 3D
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
**Available on Asset Store:** https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837
|
||||||
|
|
||||||
|
**Forum Thread:** https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/
|
||||||
|
|
||||||
|
**[Support the Developer ☕](https://yasirkula.itch.io/unity3d)**
|
||||||
|
|
||||||
|
## ABOUT
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
## INSTALLATION
|
||||||
|
|
||||||
|
There are 5 ways to install this plugin:
|
||||||
|
|
||||||
|
- import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) via *Assets-Import Package*
|
||||||
|
- clone/[download](https://github.com/yasirkula/UnityAssetUsageDetector/archive/master.zip) this repository and move the *Plugins* folder to your Unity project's *Assets* folder
|
||||||
|
- import it from [Asset Store](https://assetstore.unity.com/packages/tools/utilities/asset-usage-detector-112837)
|
||||||
|
- *(via Package Manager)* add the following line to *Packages/manifest.json*:
|
||||||
|
- `"com.yasirkula.assetusagedetector": "https://github.com/yasirkula/UnityAssetUsageDetector.git",`
|
||||||
|
- *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command:
|
||||||
|
- `openupm add com.yasirkula.assetusagedetector`
|
||||||
|
|
||||||
|
## HOW TO
|
||||||
|
|
||||||
|
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
||||||
|
- 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
|
||||||
|
|
||||||
|
- You can search for references of any object that extends *UnityEngine.Object*
|
||||||
|
- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references
|
||||||
|
- Can search in multiple scenes at once
|
||||||
|
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## KNOWN LIMITATIONS
|
||||||
|
|
||||||
|
- *static* variables are not searched
|
||||||
|
- GUIText materials are not searched
|
||||||
|
- Textures in Lens Flare's can not be searched
|
||||||
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 56436d3bf8363484a9696f11a535c2fb
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d2008cf328f1a2e4da790e4bdd4191cd
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "AssetUsageDetector.Editor",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8579ab42c9ab63d4bac5fb07bd390b46
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com)
|
// Asset Usage Detector - by Suleyman Yasir KULA (yasirkula@gmail.com)
|
||||||
|
|
||||||
using AssetUsageDetectorNamespace.Extras;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.Animations;
|
using UnityEditor.Animations;
|
||||||
@@ -15,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;
|
||||||
@@ -105,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)
|
||||||
@@ -121,6 +134,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private readonly HashSet<string> assetsToSearchPathsSet = new HashSet<string>();
|
private readonly HashSet<string> assetsToSearchPathsSet = new HashSet<string>();
|
||||||
// The root prefab objects in assetsToSearch that will be used to search for prefab references
|
// The root prefab objects in assetsToSearch that will be used to search for prefab references
|
||||||
private readonly List<GameObject> assetsToSearchRootPrefabs = new List<GameObject>( 4 );
|
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>();
|
||||||
|
|
||||||
|
#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;
|
||||||
@@ -129,8 +149,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private readonly Dictionary<Type, VariableGetterHolder[]> typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
private readonly Dictionary<Type, VariableGetterHolder[]> typeToVariables = new Dictionary<Type, VariableGetterHolder[]>( 4096 );
|
||||||
// An optimization to search an object only once (key is a hash of the searched object)
|
// An optimization to search an object only once (key is a hash of the searched object)
|
||||||
private readonly Dictionary<string, ReferenceNode> searchedObjects = new Dictionary<string, ReferenceNode>( 32768 );
|
private readonly Dictionary<string, ReferenceNode> searchedObjects = new Dictionary<string, ReferenceNode>( 32768 );
|
||||||
|
// An optimization to fetch an animation clip's curve bindings only once
|
||||||
|
private readonly Dictionary<AnimationClip, EditorCurveBinding[]> animationClipUniqueBindings = new Dictionary<AnimationClip, EditorCurveBinding[]>( 256 );
|
||||||
// An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
// An optimization to fetch the dependencies of an asset only once (key is the path of the asset)
|
||||||
private Dictionary<string, CacheEntry> assetDependencyCache;
|
private Dictionary<string, CacheEntry> assetDependencyCache;
|
||||||
|
private CacheEntry lastRefreshedCacheEntry;
|
||||||
|
|
||||||
// Dictionary to quickly find the function to search a specific type with
|
// Dictionary to quickly find the function to search a specific type with
|
||||||
private Dictionary<Type, Func<Object, ReferenceNode>> typeToSearchFunction;
|
private Dictionary<Type, Func<Object, ReferenceNode>> typeToSearchFunction;
|
||||||
@@ -145,12 +168,14 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private bool searchMaterialsForTexture;
|
private bool searchMaterialsForTexture;
|
||||||
|
|
||||||
private bool searchSerializableVariablesOnly;
|
private bool searchSerializableVariablesOnly;
|
||||||
|
private bool prevSearchSerializableVariablesOnly;
|
||||||
|
|
||||||
private int searchDepthLimit; // Depth limit for recursively searching variables of objects
|
private int searchDepthLimit; // Depth limit for recursively searching variables of objects
|
||||||
|
|
||||||
private Object currentSearchedObject;
|
private Object currentSearchedObject;
|
||||||
private int currentDepth;
|
private int currentDepth;
|
||||||
|
|
||||||
|
private bool dontSearchInSourceAssets;
|
||||||
private bool searchingSourceAssets;
|
private bool searchingSourceAssets;
|
||||||
private bool isInPlayMode;
|
private bool isInPlayMode;
|
||||||
|
|
||||||
@@ -168,8 +193,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
private readonly List<ReferenceNode> nodesPool = new List<ReferenceNode>( 32 );
|
private readonly List<ReferenceNode> nodesPool = new List<ReferenceNode>( 32 );
|
||||||
private readonly List<VariableGetterHolder> validVariables = new List<VariableGetterHolder>( 32 );
|
private readonly List<VariableGetterHolder> validVariables = new List<VariableGetterHolder>( 32 );
|
||||||
|
|
||||||
private readonly string reflectionNameSpace = typeof( Assembly ).Namespace;
|
|
||||||
|
|
||||||
private string CachePath { get { return Application.dataPath + "/../Library/AssetUsageDetector.cache"; } } // Path of the cache file
|
private string CachePath { get { return Application.dataPath + "/../Library/AssetUsageDetector.cache"; } } // Path of the cache file
|
||||||
|
|
||||||
// Search for references!
|
// Search for references!
|
||||||
@@ -235,14 +258,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
this.fieldModifiers = searchParameters.fieldModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
this.fieldModifiers = searchParameters.fieldModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||||
this.propertyModifiers = searchParameters.propertyModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
this.propertyModifiers = searchParameters.propertyModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||||
this.searchDepthLimit = searchParameters.searchDepthLimit;
|
this.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||||
|
this.searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
|
||||||
|
this.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||||
|
|
||||||
// Initialize commonly used variables
|
// Initialize commonly used variables
|
||||||
searchResult = new List<SearchResultGroup>(); // Overall search results
|
searchResult = new List<SearchResultGroup>(); // Overall search results
|
||||||
|
|
||||||
if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers )
|
if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers || prevSearchSerializableVariablesOnly != searchSerializableVariablesOnly )
|
||||||
typeToVariables.Clear();
|
typeToVariables.Clear();
|
||||||
|
|
||||||
searchedObjects.Clear();
|
searchedObjects.Clear();
|
||||||
|
animationClipUniqueBindings.Clear();
|
||||||
callStack.Clear();
|
callStack.Clear();
|
||||||
objectsToSearchSet.Clear();
|
objectsToSearchSet.Clear();
|
||||||
sceneObjectsToSearchSet.Clear();
|
sceneObjectsToSearchSet.Clear();
|
||||||
@@ -250,6 +276,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
assetsToSearchSet.Clear();
|
assetsToSearchSet.Clear();
|
||||||
assetsToSearchPathsSet.Clear();
|
assetsToSearchPathsSet.Clear();
|
||||||
assetsToSearchRootPrefabs.Clear();
|
assetsToSearchRootPrefabs.Clear();
|
||||||
|
excludedAssetsPathsSet.Clear();
|
||||||
|
#if UNITY_2017_3_OR_NEWER
|
||||||
|
assemblyDefinitionFilesToSearch.Clear();
|
||||||
|
#endif
|
||||||
|
|
||||||
if( assetDependencyCache == null )
|
if( assetDependencyCache == null )
|
||||||
{
|
{
|
||||||
@@ -265,6 +295,8 @@ namespace AssetUsageDetectorNamespace
|
|||||||
foreach( var cacheEntry in assetDependencyCache.Values )
|
foreach( var cacheEntry in assetDependencyCache.Values )
|
||||||
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
||||||
|
|
||||||
|
lastRefreshedCacheEntry = null;
|
||||||
|
|
||||||
if( typeToSearchFunction == null )
|
if( typeToSearchFunction == null )
|
||||||
{
|
{
|
||||||
typeToSearchFunction = new Dictionary<Type, Func<Object, ReferenceNode>>()
|
typeToSearchFunction = new Dictionary<Type, Func<Object, ReferenceNode>>()
|
||||||
@@ -281,12 +313,19 @@ 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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
prevFieldModifiers = fieldModifiers;
|
prevFieldModifiers = fieldModifiers;
|
||||||
prevPropertyModifiers = propertyModifiers;
|
prevPropertyModifiers = propertyModifiers;
|
||||||
|
prevSearchSerializableVariablesOnly = searchSerializableVariablesOnly;
|
||||||
|
|
||||||
searchPrefabConnections = false;
|
searchPrefabConnections = false;
|
||||||
searchMonoBehavioursForScript = false;
|
searchMonoBehavioursForScript = false;
|
||||||
@@ -349,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 )
|
||||||
{
|
{
|
||||||
@@ -428,9 +467,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
// By default, search only serializable variables for references
|
|
||||||
searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
|
|
||||||
|
|
||||||
// Initialize the nodes of searched asset(s)
|
// Initialize the nodes of searched asset(s)
|
||||||
foreach( Object obj in objectsToSearchSet )
|
foreach( Object obj in objectsToSearchSet )
|
||||||
searchedObjects.Add( obj.Hash(), PopReferenceNode( obj ) );
|
searchedObjects.Add( obj.Hash(), PopReferenceNode( obj ) );
|
||||||
@@ -448,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;
|
||||||
@@ -481,7 +517,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the path(s) of the assets that won't be searched for references
|
// Calculate the path(s) of the assets that won't be searched for references
|
||||||
HashSet<string> excludedAssetsPathsSet = new HashSet<string>();
|
|
||||||
if( searchParameters.excludedAssetsFromSearch != null )
|
if( searchParameters.excludedAssetsFromSearch != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
||||||
@@ -499,8 +534,24 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( searchParameters.dontSearchInSourceAssets )
|
#if UNITY_2017_3_OR_NEWER
|
||||||
excludedAssetsPathsSet.UnionWith( assetsToSearchPathsSet );
|
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" );
|
||||||
@@ -539,7 +590,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
searchResult.Add( currentSearchResultGroup );
|
searchResult.Add( currentSearchResultGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search non-serializable variables for references only if we are currently searching a scene and the editor is in play mode
|
// Search non-serializable variables for references while searching a scene in play mode
|
||||||
if( isInPlayMode )
|
if( isInPlayMode )
|
||||||
searchSerializableVariablesOnly = false;
|
searchSerializableVariablesOnly = false;
|
||||||
|
|
||||||
@@ -604,7 +655,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Searching source assets last prevents some references from being excluded due to callStack.ContainsFast
|
// Searching source assets last prevents some references from being excluded due to callStack.ContainsFast
|
||||||
if( !searchParameters.dontSearchInSourceAssets )
|
if( !dontSearchInSourceAssets )
|
||||||
{
|
{
|
||||||
searchingSourceAssets = true;
|
searchingSourceAssets = true;
|
||||||
|
|
||||||
@@ -626,18 +677,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
Debug.LogException( e );
|
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
|
||||||
|
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine();
|
||||||
if( callStack.Count > 0 )
|
if( callStack.Count > 0 )
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder( callStack.Count * 50 );
|
|
||||||
sb.AppendLine( "Stack contents: " );
|
sb.AppendLine( "Stack contents: " );
|
||||||
for( int i = 0; i < callStack.Count; i++ )
|
for( int i = callStack.Count - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
sb.Append( i ).Append( ": " );
|
sb.Append( i ).Append( ": " );
|
||||||
|
|
||||||
Object unityObject = callStack[i] as Object;
|
Object unityObject = callStack[i] as Object;
|
||||||
if( unityObject != null )
|
if( unityObject )
|
||||||
sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" );
|
sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" );
|
||||||
else if( callStack[i] != null )
|
else if( callStack[i] != null )
|
||||||
sb.Append( callStack[i].GetType() ).AppendLine( " object" );
|
sb.Append( callStack[i].GetType() ).AppendLine( " object" );
|
||||||
@@ -645,9 +695,21 @@ namespace AssetUsageDetectorNamespace
|
|||||||
sb.AppendLine( "<<destroyed>>" );
|
sb.AppendLine( "<<destroyed>>" );
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogError( sb.ToString() );
|
sb.AppendLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.AppendLine( "Searching references of: " );
|
||||||
|
foreach( Object obj in objectsToSearchSet )
|
||||||
|
{
|
||||||
|
if( obj )
|
||||||
|
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine();
|
||||||
|
sb.Append( e ).AppendLine();
|
||||||
|
|
||||||
|
Debug.LogError( sb.ToString() );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InitializeSearchResultNodes( searchResult );
|
InitializeSearchResultNodes( searchResult );
|
||||||
@@ -713,7 +775,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
string assetPath = AssetDatabase.GetAssetPath( obj );
|
string assetPath = AssetDatabase.GetAssetPath( obj );
|
||||||
if( !string.IsNullOrEmpty( assetPath ) )
|
if( !string.IsNullOrEmpty( assetPath ) )
|
||||||
|
{
|
||||||
assetsToSearchPathsSet.Add( assetPath );
|
assetsToSearchPathsSet.Add( assetPath );
|
||||||
|
if( dontSearchInSourceAssets && AssetDatabase.IsMainAsset( obj ) )
|
||||||
|
excludedAssetsPathsSet.Add( assetPath );
|
||||||
|
}
|
||||||
|
|
||||||
GameObject go = null;
|
GameObject go = null;
|
||||||
if( obj is GameObject )
|
if( obj is GameObject )
|
||||||
@@ -728,7 +794,6 @@ namespace AssetUsageDetectorNamespace
|
|||||||
for( int i = assetsToSearchRootPrefabs.Count - 1; i >= 0; i-- )
|
for( int i = assetsToSearchRootPrefabs.Count - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
Transform rootTransform = assetsToSearchRootPrefabs[i].transform;
|
Transform rootTransform = assetsToSearchRootPrefabs[i].transform;
|
||||||
|
|
||||||
if( transform.IsChildOf( rootTransform ) )
|
if( transform.IsChildOf( rootTransform ) )
|
||||||
{
|
{
|
||||||
shouldAddRootPrefabEntry = false;
|
shouldAddRootPrefabEntry = false;
|
||||||
@@ -742,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
|
||||||
{
|
{
|
||||||
@@ -913,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 );
|
||||||
@@ -928,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 );
|
||||||
@@ -1012,11 +1084,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// If this component is an Animation, search its animation clips for references
|
// If this component is an Animation, search its animation clips for references
|
||||||
foreach( AnimationState anim in (Animation) component )
|
foreach( AnimationState anim in (Animation) component )
|
||||||
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
|
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
|
||||||
|
|
||||||
|
// Search the objects that are animated by this Animation component for references
|
||||||
|
SearchAnimatedObjects( referenceNode );
|
||||||
}
|
}
|
||||||
else if( component is Animator )
|
else if( component is Animator )
|
||||||
{
|
{
|
||||||
// If this component is an Animator, search its animation clips for references
|
// If this component is an Animator, search its animation clips for references (via AnimatorController)
|
||||||
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
|
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
|
||||||
|
|
||||||
|
// Search the objects that are animated by this Animator component for references
|
||||||
|
SearchAnimatedObjects( referenceNode );
|
||||||
}
|
}
|
||||||
#if UNITY_2017_2_OR_NEWER
|
#if UNITY_2017_2_OR_NEWER
|
||||||
else if( component is Tilemap )
|
else if( component is Tilemap )
|
||||||
@@ -1045,7 +1123,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SearchWithSerializedObject( referenceNode );
|
SearchVariablesWithSerializedObject( referenceNode );
|
||||||
return referenceNode;
|
return referenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1227,8 +1305,124 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Search through field and properties of an object for references with SerializedObject
|
#if UNITY_2017_3_OR_NEWER
|
||||||
private void SearchWithSerializedObject( ReferenceNode referenceNode )
|
// 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
|
||||||
|
private void SearchAnimatedObjects( ReferenceNode referenceNode )
|
||||||
|
{
|
||||||
|
GameObject root = ( (Component) referenceNode.nodeObject ).gameObject;
|
||||||
|
AnimationClip[] clips = AnimationUtility.GetAnimationClips( root );
|
||||||
|
for( int i = 0; i < clips.Length; i++ )
|
||||||
|
{
|
||||||
|
AnimationClip clip = clips[i];
|
||||||
|
bool isClipUnique = true;
|
||||||
|
for( int j = i - 1; j >= 0; j-- )
|
||||||
|
{
|
||||||
|
if( clips[j] == clip )
|
||||||
|
{
|
||||||
|
isClipUnique = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !isClipUnique )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
EditorCurveBinding[] uniqueBindings;
|
||||||
|
if( !animationClipUniqueBindings.TryGetValue( clip, out uniqueBindings ) )
|
||||||
|
{
|
||||||
|
// Calculate all the "unique" paths that the animation clip's curves have
|
||||||
|
// Both float curves (GetCurveBindings) and object reference curves (GetObjectReferenceCurveBindings) are checked
|
||||||
|
List<EditorCurveBinding> _uniqueBindings = new List<EditorCurveBinding>( 2 );
|
||||||
|
EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings( clip );
|
||||||
|
for( int j = 0; j < bindings.Length; j++ )
|
||||||
|
{
|
||||||
|
string bindingPath = bindings[j].path;
|
||||||
|
if( string.IsNullOrEmpty( bindingPath ) ) // Ignore the root animated object
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBindingUnique = true;
|
||||||
|
for( int k = _uniqueBindings.Count - 1; k >= 0; k-- )
|
||||||
|
{
|
||||||
|
if( bindingPath == _uniqueBindings[k].path )
|
||||||
|
{
|
||||||
|
isBindingUnique = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( isBindingUnique )
|
||||||
|
_uniqueBindings.Add( bindings[j] );
|
||||||
|
}
|
||||||
|
|
||||||
|
bindings = AnimationUtility.GetObjectReferenceCurveBindings( clip );
|
||||||
|
for( int j = 0; j < bindings.Length; j++ )
|
||||||
|
{
|
||||||
|
string bindingPath = bindings[j].path;
|
||||||
|
if( string.IsNullOrEmpty( bindingPath ) ) // Ignore the root animated object
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bool isBindingUnique = true;
|
||||||
|
for( int k = _uniqueBindings.Count - 1; k >= 0; k-- )
|
||||||
|
{
|
||||||
|
if( bindingPath == _uniqueBindings[k].path )
|
||||||
|
{
|
||||||
|
isBindingUnique = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( isBindingUnique )
|
||||||
|
_uniqueBindings.Add( bindings[j] );
|
||||||
|
}
|
||||||
|
|
||||||
|
uniqueBindings = _uniqueBindings.ToArray();
|
||||||
|
animationClipUniqueBindings[clip] = uniqueBindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
string clipName = clip.name;
|
||||||
|
for( int j = 0; j < uniqueBindings.Length; j++ )
|
||||||
|
referenceNode.AddLinkTo( SearchObject( AnimationUtility.GetAnimatedObject( root, uniqueBindings[j] ) ), "Animated via clip: " + clipName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Search through variables of an object with SerializedObject
|
||||||
|
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode )
|
||||||
{
|
{
|
||||||
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
|
||||||
{
|
{
|
||||||
@@ -1275,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() );
|
||||||
@@ -1319,12 +1513,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( UnassignedReferenceException )
|
catch( UnassignedReferenceException ) { }
|
||||||
{ }
|
catch( MissingReferenceException ) { }
|
||||||
catch( MissingReferenceException )
|
catch( MissingComponentException ) { }
|
||||||
{ }
|
catch( NotImplementedException ) { }
|
||||||
catch( MissingComponentException )
|
|
||||||
{ }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1341,7 +1533,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
// 2- skip primitive types, enums and strings
|
// 2- skip primitive types, enums and strings
|
||||||
// 3- skip common Unity types that can't hold any references (e.g. Vector3, Rect, Color, Quaternion)
|
// 3- skip common Unity types that can't hold any references (e.g. Vector3, Rect, Color, Quaternion)
|
||||||
//
|
//
|
||||||
// P.S. IsPrimitiveUnityType() extension function handles steps 2) and 3)
|
// P.S. IsIgnoredUnityType() extension function handles steps 2) and 3)
|
||||||
|
|
||||||
validVariables.Clear();
|
validVariables.Clear();
|
||||||
|
|
||||||
@@ -1361,16 +1553,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip primitive types
|
// Skip primitive types
|
||||||
Type variableType = field.FieldType;
|
if( field.FieldType.IsIgnoredUnityType() )
|
||||||
if( variableType.IsPrimitiveUnityType() )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
|
|
||||||
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Searching pointer variables for reference throws ArgumentException
|
|
||||||
if( variableType.IsPointer )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Additional filtering for fields:
|
// Additional filtering for fields:
|
||||||
@@ -1382,7 +1565,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
VariableGetVal getter = field.CreateGetter( type );
|
VariableGetVal getter = field.CreateGetter( type );
|
||||||
if( getter != null )
|
if( getter != null )
|
||||||
validVariables.Add( new VariableGetterHolder( field, getter, field.IsSerializable() ) );
|
validVariables.Add( new VariableGetterHolder( field, getter, searchSerializableVariablesOnly ? field.IsSerializable() : true ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
currType = currType.BaseType;
|
currType = currType.BaseType;
|
||||||
@@ -1404,16 +1587,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip primitive types
|
// Skip primitive types
|
||||||
Type variableType = property.PropertyType;
|
if( property.PropertyType.IsIgnoredUnityType() )
|
||||||
if( variableType.IsPrimitiveUnityType() )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
|
|
||||||
if( typeof( Type ).IsAssignableFrom( variableType ) || variableType.Namespace == reflectionNameSpace )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Searching pointer variables for reference throws ArgumentException
|
|
||||||
if( variableType.IsPointer )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Skip properties without a getter function
|
// Skip properties without a getter function
|
||||||
@@ -1447,18 +1621,18 @@ namespace AssetUsageDetectorNamespace
|
|||||||
continue;
|
continue;
|
||||||
else if( ( propertyName == "material" || propertyName == "materials" ) &&
|
else if( ( propertyName == "material" || propertyName == "materials" ) &&
|
||||||
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
|
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
|
||||||
typeof( Collider2D ).IsAssignableFrom( currType )
|
|
||||||
#if !UNITY_2019_3_OR_NEWER
|
#if !UNITY_2019_3_OR_NEWER
|
||||||
#pragma warning disable 0618
|
#pragma warning disable 0618
|
||||||
|| typeof( GUIText ).IsAssignableFrom( currType ) ) )
|
typeof( GUIText ).IsAssignableFrom( currType ) ||
|
||||||
#pragma warning restore 0618
|
#pragma warning restore 0618
|
||||||
#endif
|
#endif
|
||||||
|
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VariableGetVal getter = property.CreateGetter();
|
VariableGetVal getter = property.CreateGetter();
|
||||||
if( getter != null )
|
if( getter != null )
|
||||||
validVariables.Add( new VariableGetterHolder( property, getter, property.IsSerializable() ) );
|
validVariables.Add( new VariableGetterHolder( property, getter, searchSerializableVariablesOnly ? property.IsSerializable() : true ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1506,8 +1680,55 @@ namespace AssetUsageDetectorNamespace
|
|||||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||||
if( !assetFile.Exists || assetFile.Length != fileSizes[i] )
|
if( !assetFile.Exists || assetFile.Length != fileSizes[i] )
|
||||||
{
|
{
|
||||||
|
// Although not reproduced, it is reported that this section caused StackOverflowException due to infinite loop,
|
||||||
|
// if that happens, log useful information to help reproduce the issue
|
||||||
|
if( lastRefreshedCacheEntry == cacheEntry )
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder( 1000 );
|
||||||
|
sb.AppendLine( "<b>Infinite loop while refreshing a cache entry, please report it to the author.</b>" ).AppendLine();
|
||||||
|
sb.Append( "Asset path: " ).AppendLine( assetPath );
|
||||||
|
|
||||||
|
for( int j = 0; j < 2; j++ )
|
||||||
|
{
|
||||||
|
if( j == 1 )
|
||||||
|
{
|
||||||
|
cacheEntry.Refresh( assetPath );
|
||||||
|
dependencies = cacheEntry.dependencies;
|
||||||
|
fileSizes = cacheEntry.fileSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine().AppendLine( j == 0 ? "Old Dependencies:" : "New Dependencies" );
|
||||||
|
for( int k = 0; k < dependencies.Length; k++ )
|
||||||
|
{
|
||||||
|
sb.Append( "- " ).Append( dependencies[k] );
|
||||||
|
|
||||||
|
if( Directory.Exists( dependencies[k] ) )
|
||||||
|
{
|
||||||
|
sb.Append( " (Dir)" );
|
||||||
|
if( fileSizes[k] != 0L )
|
||||||
|
sb.Append( " WasCachedAsFile: " ).Append( fileSizes[k] );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assetFile = new FileInfo( dependencies[k] );
|
||||||
|
sb.Append( " (File) " ).Append( "CachedSize: " ).Append( fileSizes[k] );
|
||||||
|
if( assetFile.Exists )
|
||||||
|
sb.Append( " RealSize: " ).Append( assetFile.Length );
|
||||||
|
else
|
||||||
|
sb.Append( " NoLongerExists" );
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.LogError( sb.ToString() );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
cacheEntry.Refresh( assetPath );
|
cacheEntry.Refresh( assetPath );
|
||||||
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
cacheEntry.searchResult = CacheEntry.Result.Unknown;
|
||||||
|
lastRefreshedCacheEntry = cacheEntry;
|
||||||
|
|
||||||
return AssetHasAnyReference( assetPath );
|
return AssetHasAnyReference( assetPath );
|
||||||
}
|
}
|
||||||
@@ -1659,7 +1880,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
assetDependencyCache = null;
|
assetDependencyCache = null;
|
||||||
Debug.LogException( e );
|
Debug.LogWarning( "Couldn't load cache (probably cache format has changed in an update), will regenerate cache.\n" + e.ToString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
public enum Phase { Setup, Processing, Complete };
|
public enum Phase { Setup, Processing, Complete };
|
||||||
|
|
||||||
@@ -26,6 +26,9 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
|
||||||
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
private const string PREFS_SHOW_TOOLTIPS = "AUD_Tooltips";
|
||||||
|
|
||||||
|
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
|
||||||
|
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f );
|
||||||
|
|
||||||
private AssetUsageDetector core = new AssetUsageDetector();
|
private AssetUsageDetector core = new AssetUsageDetector();
|
||||||
private SearchResult searchResult; // Overall search results
|
private SearchResult searchResult; // Overall search results
|
||||||
|
|
||||||
@@ -38,7 +41,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not)
|
private bool searchInScenesInBuildTickedOnly = true; // Scenes in build (ticked only or not)
|
||||||
private bool searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
private bool searchInAllScenes = true; // All scenes (including scenes that are not in build)
|
||||||
private bool searchInAssetsFolder = true; // Assets in Project window
|
private bool searchInAssetsFolder = true; // Assets in Project window
|
||||||
private bool dontSearchInSourceAssets = false; // objectsToSearch won't be searched for internal references
|
private bool dontSearchInSourceAssets = true; // objectsToSearch won't be searched for internal references
|
||||||
|
|
||||||
private List<Object> searchInAssetsSubset = new List<Object>() { null }; // If not empty, only these assets are searched for references
|
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
|
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
|
||||||
@@ -68,17 +71,47 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
private Vector2 scrollPosition = Vector2.zero;
|
private Vector2 scrollPosition = Vector2.zero;
|
||||||
|
|
||||||
private static AssetUsageDetectorWindow visibleWindow = null;
|
private bool shouldRepositionSelf;
|
||||||
|
private Rect windowTargetPosition;
|
||||||
|
|
||||||
|
private static AssetUsageDetectorWindow mainWindow = null;
|
||||||
|
|
||||||
// Add "Asset Usage Detector" menu item to the Window menu
|
// Add "Asset Usage Detector" menu item to the Window menu
|
||||||
[MenuItem( "Window/Asset Usage Detector" )]
|
[MenuItem( "Window/Asset Usage Detector/Active Window" )]
|
||||||
private static void Init()
|
private static void OpenActiveWindow()
|
||||||
{
|
{
|
||||||
AssetUsageDetectorWindow window = GetWindow<AssetUsageDetectorWindow>();
|
if( !mainWindow )
|
||||||
window.titleContent = new GUIContent( "Asset Usage Detector" );
|
{
|
||||||
window.minSize = new Vector2( 325f, 220f );
|
mainWindow = GetWindow<AssetUsageDetectorWindow>();
|
||||||
|
mainWindow.titleContent = windowTitle;
|
||||||
|
mainWindow.minSize = windowMinSize;
|
||||||
|
}
|
||||||
|
|
||||||
window.Show();
|
mainWindow.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MenuItem( "Window/Asset Usage Detector/New Window" )]
|
||||||
|
private static void OpenNewWindow()
|
||||||
|
{
|
||||||
|
Rect? windowTargetPosition = null;
|
||||||
|
if( mainWindow )
|
||||||
|
{
|
||||||
|
Rect position = mainWindow.position;
|
||||||
|
position.position += new Vector2( 50f, 50f );
|
||||||
|
windowTargetPosition = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindow = CreateInstance<AssetUsageDetectorWindow>();
|
||||||
|
mainWindow.titleContent = windowTitle;
|
||||||
|
mainWindow.minSize = windowMinSize;
|
||||||
|
|
||||||
|
if( windowTargetPosition.HasValue )
|
||||||
|
{
|
||||||
|
mainWindow.shouldRepositionSelf = true;
|
||||||
|
mainWindow.windowTargetPosition = windowTargetPosition.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindow.Show( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quickly initiate search for the selected assets
|
// Quickly initiate search for the selected assets
|
||||||
@@ -133,57 +166,58 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
|
||||||
{
|
{
|
||||||
if( visibleWindow != null && !visibleWindow.ReturnToSetupPhase( true ) )
|
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
|
||||||
{
|
{
|
||||||
Debug.LogError( "Need to reset the previous search first!" );
|
Debug.LogError( "Need to reset the previous search first!" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Init();
|
OpenActiveWindow();
|
||||||
|
|
||||||
visibleWindow.objectsToSearch.Clear();
|
mainWindow.objectsToSearch.Clear();
|
||||||
if( searchObjects != null )
|
if( searchObjects != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchObjects )
|
foreach( Object obj in searchObjects )
|
||||||
visibleWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
|
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( searchParameters != null )
|
if( searchParameters != null )
|
||||||
{
|
{
|
||||||
visibleWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
mainWindow.ParseSceneSearchMode( searchParameters.searchInScenes );
|
||||||
visibleWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
mainWindow.searchInAssetsFolder = searchParameters.searchInAssetsFolder;
|
||||||
visibleWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
mainWindow.dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
|
||||||
visibleWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
mainWindow.searchDepthLimit = searchParameters.searchDepthLimit;
|
||||||
visibleWindow.fieldModifiers = searchParameters.fieldModifiers;
|
mainWindow.fieldModifiers = searchParameters.fieldModifiers;
|
||||||
visibleWindow.propertyModifiers = searchParameters.propertyModifiers;
|
mainWindow.propertyModifiers = searchParameters.propertyModifiers;
|
||||||
visibleWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
mainWindow.searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
|
||||||
visibleWindow.lazySceneSearch = searchParameters.lazySceneSearch;
|
mainWindow.lazySceneSearch = searchParameters.lazySceneSearch;
|
||||||
visibleWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
mainWindow.noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
|
||||||
visibleWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
mainWindow.showDetailedProgressBar = searchParameters.showDetailedProgressBar;
|
||||||
|
|
||||||
visibleWindow.searchInAssetsSubset.Clear();
|
mainWindow.searchInAssetsSubset.Clear();
|
||||||
if( searchParameters.searchInAssetsSubset != null )
|
if( searchParameters.searchInAssetsSubset != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchParameters.searchInAssetsSubset )
|
foreach( Object obj in searchParameters.searchInAssetsSubset )
|
||||||
visibleWindow.searchInAssetsSubset.Add( obj );
|
mainWindow.searchInAssetsSubset.Add( obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
visibleWindow.excludedAssets.Clear();
|
mainWindow.excludedAssets.Clear();
|
||||||
if( searchParameters.excludedAssetsFromSearch != null )
|
if( searchParameters.excludedAssetsFromSearch != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
foreach( Object obj in searchParameters.excludedAssetsFromSearch )
|
||||||
visibleWindow.excludedAssets.Add( obj );
|
mainWindow.excludedAssets.Add( obj );
|
||||||
}
|
}
|
||||||
|
|
||||||
visibleWindow.excludedScenes.Clear();
|
mainWindow.excludedScenes.Clear();
|
||||||
if( searchParameters.excludedScenesFromSearch != null )
|
if( searchParameters.excludedScenesFromSearch != null )
|
||||||
{
|
{
|
||||||
foreach( Object obj in searchParameters.excludedScenesFromSearch )
|
foreach( Object obj in searchParameters.excludedScenesFromSearch )
|
||||||
visibleWindow.excludedScenes.Add( obj );
|
mainWindow.excludedScenes.Add( obj );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visibleWindow.InitiateSearch();
|
mainWindow.InitiateSearch();
|
||||||
|
mainWindow.Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
@@ -193,7 +227,22 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
visibleWindow = this;
|
mainWindow = 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
|
||||||
|
|
||||||
|
if( mainWindow == this )
|
||||||
|
mainWindow = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
@@ -208,8 +257,11 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
|
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
|
||||||
searchResult.RestoreInitialSceneSetup();
|
searchResult.RestoreInitialSceneSetup();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
visibleWindow = null;
|
private void OnFocus()
|
||||||
|
{
|
||||||
|
mainWindow = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SavePrefs()
|
private void SavePrefs()
|
||||||
@@ -286,6 +338,12 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
nextPlayModeRefreshTime = EditorApplication.timeSinceStartup + PLAY_MODE_REFRESH_INTERVAL; ;
|
nextPlayModeRefreshTime = EditorApplication.timeSinceStartup + PLAY_MODE_REFRESH_INTERVAL; ;
|
||||||
Repaint();
|
Repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( shouldRepositionSelf )
|
||||||
|
{
|
||||||
|
shouldRepositionSelf = false;
|
||||||
|
position = windowTargetPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGUI()
|
private void OnGUI()
|
||||||
@@ -523,7 +581,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
GUILayout.Space( 35 );
|
GUILayout.Space( 35 );
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Shorter: Draw only the most relevant unique parts of the complete paths that start with a UnityEngine.Object", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) )
|
if( EditorGUILayout.ToggleLeft( "Shorter: Draw only the most relevant parts (that start with a UnityEngine.Object) of the complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.ShortRelevantParts ) )
|
||||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.ShortRelevantParts;
|
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.ShortRelevantParts;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
@@ -532,7 +590,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
|
|
||||||
GUILayout.Space( 35 );
|
GUILayout.Space( 35 );
|
||||||
|
|
||||||
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of complete paths that are unique", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
if( EditorGUILayout.ToggleLeft( "Shortest: Draw only the last two nodes of complete paths", searchResultDrawParameters.pathDrawingMode == PathDrawingMode.Shortest ) )
|
||||||
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Shortest;
|
searchResultDrawParameters.pathDrawingMode = PathDrawingMode.Shortest;
|
||||||
|
|
||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
@@ -565,25 +623,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
SavePrefs();
|
SavePrefs();
|
||||||
|
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
// Try replacing prefab stage objects with their corresponding prefab assets
|
ReplacePrefabStageObjectsWithAssets( UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() );
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Start searching
|
// Start searching
|
||||||
@@ -609,6 +649,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 )
|
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
|
||||||
{
|
{
|
||||||
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
public class EmptyEnumerator<T> : IEnumerable<T>, IEnumerator<T>
|
public class EmptyEnumerator<T> : IEnumerable<T>, IEnumerator<T>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
public abstract class ListDrawer<T>
|
public abstract class ListDrawer<T>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ObjectToSearch
|
public class ObjectToSearch
|
||||||
@@ -56,74 +56,95 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
if( target == null || target.Equals( null ) )
|
if( target == null || target.Equals( null ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( !target.IsAsset() || !AssetDatabase.IsMainAsset( target ) || target is SceneAsset )
|
if( !target.IsAsset() )
|
||||||
return;
|
|
||||||
|
|
||||||
if( includeTarget )
|
|
||||||
{
|
{
|
||||||
if( !currentSubAssets.Contains( target ) )
|
GameObject go = target as GameObject;
|
||||||
|
if( !go || !go.scene.IsValid() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If this is a scene object, add its child objects to the sub-assets list
|
||||||
|
// but don't include them in the search by default
|
||||||
|
Transform goTransform = go.transform;
|
||||||
|
Transform[] children = go.GetComponentsInChildren<Transform>();
|
||||||
|
for( int i = 0; i < children.Length; i++ )
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( target, true ) );
|
if( ReferenceEquals( children[i], goTransform ) )
|
||||||
currentSubAssets.Add( target );
|
continue;
|
||||||
|
|
||||||
|
subAssets.Add( new SubAsset( children[i].gameObject, false ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If asset is a directory, add all of its contents as sub-assets recursively
|
if( !AssetDatabase.IsMainAsset( target ) || target is SceneAsset )
|
||||||
if( target.IsFolder() )
|
|
||||||
{
|
|
||||||
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
|
||||||
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find sub-asset(s) of the asset (if any)
|
if( includeTarget )
|
||||||
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) );
|
|
||||||
for( int i = 0; i < assets.Length; i++ )
|
|
||||||
{
|
|
||||||
Object asset = assets[i];
|
|
||||||
if( asset == null || asset.Equals( null ) || asset is Component )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( currentSubAssets.Contains( asset ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( asset != target )
|
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( asset, true ) );
|
if( !currentSubAssets.Contains( target ) )
|
||||||
currentSubAssets.Add( asset );
|
{
|
||||||
|
subAssets.Add( new SubAsset( target, true ) );
|
||||||
|
currentSubAssets.Add( target );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If asset is a directory, add all of its contents as sub-assets recursively
|
||||||
|
if( target.IsFolder() )
|
||||||
|
{
|
||||||
|
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
|
||||||
|
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MonoScripts are a special case such that other MonoScript objects
|
// Find sub-asset(s) of the asset (if any)
|
||||||
// that extend this MonoScript are also considered a sub-asset
|
Object[] assets = AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( target ) );
|
||||||
if( asset is MonoScript )
|
for( int i = 0; i < assets.Length; i++ )
|
||||||
{
|
{
|
||||||
Type monoScriptType = ( (MonoScript) asset ).GetClass();
|
Object asset = assets[i];
|
||||||
if( monoScriptType == null || ( !monoScriptType.IsInterface && !typeof( Component ).IsAssignableFrom( monoScriptType ) ) )
|
if( asset == null || asset.Equals( null ) || asset is Component )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Find all MonoScript objects in the project
|
if( currentSubAssets.Contains( asset ) )
|
||||||
if( monoScriptsInProject == null )
|
continue;
|
||||||
|
|
||||||
|
if( asset != target )
|
||||||
{
|
{
|
||||||
string[] monoScriptGuids = AssetDatabase.FindAssets( "t:MonoScript" );
|
subAssets.Add( new SubAsset( asset, true ) );
|
||||||
monoScriptsInProject = new MonoScript[monoScriptGuids.Length];
|
currentSubAssets.Add( asset );
|
||||||
for( int k = 0; k < monoScriptGuids.Length; k++ )
|
|
||||||
monoScriptsInProject[k] = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( monoScriptGuids[k] ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add any MonoScript objects that extend this MonoScript as a sub-asset
|
// MonoScripts are a special case such that other MonoScript objects
|
||||||
for( int j = 0; j < monoScriptsInProject.Length; j++ )
|
// that extend this MonoScript are also considered a sub-asset
|
||||||
|
if( asset is MonoScript )
|
||||||
{
|
{
|
||||||
Type otherMonoScriptType = monoScriptsInProject[j].GetClass();
|
Type monoScriptType = ( (MonoScript) asset ).GetClass();
|
||||||
if( otherMonoScriptType == null || monoScriptType == otherMonoScriptType || !monoScriptType.IsAssignableFrom( otherMonoScriptType ) )
|
if( monoScriptType == null || ( !monoScriptType.IsInterface && !typeof( Component ).IsAssignableFrom( monoScriptType ) ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
// Find all MonoScript objects in the project
|
||||||
|
if( monoScriptsInProject == null )
|
||||||
{
|
{
|
||||||
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
|
string[] monoScriptGuids = AssetDatabase.FindAssets( "t:MonoScript" );
|
||||||
currentSubAssets.Add( monoScriptsInProject[j] );
|
monoScriptsInProject = new MonoScript[monoScriptGuids.Length];
|
||||||
|
for( int k = 0; k < monoScriptGuids.Length; k++ )
|
||||||
|
monoScriptsInProject[k] = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( monoScriptGuids[k] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add any MonoScript objects that extend this MonoScript as a sub-asset
|
||||||
|
for( int j = 0; j < monoScriptsInProject.Length; j++ )
|
||||||
|
{
|
||||||
|
Type otherMonoScriptType = monoScriptsInProject[j].GetClass();
|
||||||
|
if( otherMonoScriptType == null || monoScriptType == otherMonoScriptType || !monoScriptType.IsAssignableFrom( otherMonoScriptType ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
|
||||||
|
{
|
||||||
|
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
|
||||||
|
currentSubAssets.Add( monoScriptsInProject[j] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using AssetUsageDetectorNamespace.Extras;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
@@ -218,14 +217,20 @@ 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;
|
||||||
Vector2 size = Utilities.TooltipGUIStyle.CalcSize( new GUIContent( parameters.tooltip ) );
|
Vector2 size = Utilities.TooltipGUIStyle.CalcSize( new GUIContent( parameters.tooltip ) );
|
||||||
size.x += 10f;
|
size.x += 10f;
|
||||||
|
|
||||||
GUI.Box( new Rect( new Vector2( mousePos.x - size.x * 0.5f, mousePos.y - size.y ), size ), parameters.tooltip, Utilities.TooltipGUIStyle );
|
Rect tooltipRect = new Rect( new Vector2( mousePos.x - size.x * 0.5f, mousePos.y - size.y ), size );
|
||||||
|
if( tooltipRect.xMin < 0f )
|
||||||
|
tooltipRect.x -= tooltipRect.xMin;
|
||||||
|
else if( tooltipRect.xMax > parameters.guiRect.width )
|
||||||
|
tooltipRect.x -= tooltipRect.xMax - parameters.guiRect.width;
|
||||||
|
|
||||||
|
GUI.Box( tooltipRect, parameters.tooltip, Utilities.TooltipGUIStyle );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( parameters.shouldRefreshEditorWindow )
|
if( parameters.shouldRefreshEditorWindow )
|
||||||
@@ -623,7 +628,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
|
|
||||||
referencePathsShortUnique = new List<ReferencePath>( 32 );
|
referencePathsShortUnique = new List<ReferencePath>( 32 );
|
||||||
for( int i = 0; i < references.Count; i++ )
|
for( int i = 0; i < references.Count; i++ )
|
||||||
references[i].CalculateShortUniquePaths( referencePathsShortUnique );
|
references[i].CalculateShortUniquePaths( referencePathsShortUnique, Type == GroupType.Scene || Type == GroupType.DontDestroyOnLoad );
|
||||||
|
|
||||||
referencePathsShortest = new List<ReferencePath>( referencePathsShortUnique.Count );
|
referencePathsShortest = new List<ReferencePath>( referencePathsShortUnique.Count );
|
||||||
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
for( int i = 0; i < referencePathsShortUnique.Count; i++ )
|
||||||
@@ -1013,13 +1018,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate short unique paths that start with this node
|
// Calculate short unique paths that start with this node
|
||||||
public void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> currentPaths )
|
public void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> currentPaths, bool startPathsWithSceneObjects )
|
||||||
{
|
{
|
||||||
CalculateShortUniquePaths( currentPaths, new List<ReferenceNode>( 8 ), new List<int>( 8 ) { -1 }, 0, new List<ReferenceNode>( 8 ) );
|
CalculateShortUniquePaths( currentPaths, startPathsWithSceneObjects, new List<ReferenceNode>( 8 ), new List<int>( 8 ) { -1 }, 0, new List<ReferenceNode>( 8 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just some boring calculations to find the short unique paths recursively
|
// Just some boring calculations to find the short unique paths recursively
|
||||||
private void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> shortestPaths, List<ReferenceNode> currentPath, List<int> currentPathIndices, int latestObjectIndexInPath, List<ReferenceNode> stack )
|
private void CalculateShortUniquePaths( List<SearchResultGroup.ReferencePath> shortestPaths, bool startPathsWithSceneObjects, List<ReferenceNode> currentPath, List<int> currentPathIndices, int latestObjectIndexInPath, List<ReferenceNode> stack )
|
||||||
{
|
{
|
||||||
int currentIndex = currentPath.Count;
|
int currentIndex = currentPath.Count;
|
||||||
currentPath.Add( this );
|
currentPath.Add( this );
|
||||||
@@ -1060,14 +1065,17 @@ namespace AssetUsageDetectorNamespace
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( instanceId.HasValue ) // nodeObject is Unity object
|
if( instanceId.HasValue ) // nodeObject is Unity object
|
||||||
latestObjectIndexInPath = currentIndex;
|
{
|
||||||
|
if( !startPathsWithSceneObjects || !AssetDatabase.Contains( instanceId.Value ) )
|
||||||
|
latestObjectIndexInPath = currentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
for( int i = 0; i < links.Count; i++ )
|
for( int i = 0; i < links.Count; i++ )
|
||||||
{
|
{
|
||||||
currentPathIndices.Add( i );
|
currentPathIndices.Add( i );
|
||||||
stack.Add( this );
|
stack.Add( this );
|
||||||
|
|
||||||
links[i].targetNode.CalculateShortUniquePaths( shortestPaths, currentPath, currentPathIndices, latestObjectIndexInPath, stack );
|
links[i].targetNode.CalculateShortUniquePaths( shortestPaths, startPathsWithSceneObjects, currentPath, currentPathIndices, latestObjectIndexInPath, stack );
|
||||||
|
|
||||||
stack.RemoveAt( stack.Count - 1 );
|
stack.RemoveAt( stack.Count - 1 );
|
||||||
currentPathIndices.RemoveAt( currentIndex + 1 );
|
currentPathIndices.RemoveAt( currentIndex + 1 );
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
using Unity.Collections;
|
||||||
|
#endif
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditor.SceneManagement;
|
using UnityEditor.SceneManagement;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
public static class Utilities
|
public static class Utilities
|
||||||
{
|
{
|
||||||
@@ -36,6 +39,11 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly string reflectionNamespace = typeof( Assembly ).Namespace;
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
private static readonly string nativeCollectionsNamespace = typeof( NativeArray<int> ).Namespace;
|
||||||
|
#endif
|
||||||
|
|
||||||
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
|
||||||
|
|
||||||
#if UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3_OR_NEWER
|
||||||
@@ -91,6 +99,7 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,10 +360,27 @@ namespace AssetUsageDetectorNamespace.Extras
|
|||||||
return Attribute.IsDefined( type, typeof( SerializableAttribute ), false );
|
return Attribute.IsDefined( type, typeof( SerializableAttribute ), false );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the type is a common Unity type (let's call them primitives)
|
// Check if instances of this type should be searched for references
|
||||||
public static bool IsPrimitiveUnityType( this Type type )
|
public static bool IsIgnoredUnityType( this Type type )
|
||||||
{
|
{
|
||||||
return type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum;
|
if( type.IsPrimitive || primitiveUnityTypes.Contains( type ) || type.IsEnum )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
// Searching NativeArrays for reference can throw InvalidOperationException if the collection is disposed
|
||||||
|
if( type.Namespace == nativeCollectionsNamespace )
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime
|
||||||
|
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Searching pointer variables for reference throws ArgumentException
|
||||||
|
if( type.IsPointer )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get <get> function for a field
|
// Get <get> function for a field
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AssetUsageDetectorNamespace.Extras
|
namespace AssetUsageDetectorNamespace
|
||||||
{
|
{
|
||||||
// Delegate to get the value of a variable (either field or property)
|
// Delegate to get the value of a variable (either field or property)
|
||||||
public delegate object VariableGetVal( object obj );
|
public delegate object VariableGetVal( object obj );
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
# Asset Usage Detector for Unity 3D
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
**Available on Asset Store:** https://www.assetstore.unity3d.com/en/#!/content/112837
|
|
||||||
|
|
||||||
**Forum Thread:** https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/
|
|
||||||
|
|
||||||
### A. ABOUT
|
|
||||||
|
|
||||||
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!
|
|
||||||
|
|
||||||
### B. HOW TO USE
|
|
||||||
|
|
||||||
- Import [AssetUsageDetector.unitypackage](https://github.com/yasirkula/UnityAssetUsageDetector/releases) to your project
|
|
||||||
- Open **Window - Asset Usage Detector** window, configure the settings and hit **GO!**
|
|
||||||
- or, right click an object and select **Search For References**
|
|
||||||
|
|
||||||
### C. FEATURES
|
|
||||||
|
|
||||||
- You can search for references of any object that extends *UnityEngine.Object*
|
|
||||||
- Extensive search algorithm that uses *SerializedObject* and *reflection* to find references
|
|
||||||
- Can search in multiple scenes at once
|
|
||||||
- Can show complete paths to the references or only the most relevant parts of the paths (see the demonstration below)
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### D. KNOWN LIMITATIONS
|
|
||||||
|
|
||||||
- *static* variables are not searched
|
|
||||||
- GUIText materials are not searched
|
|
||||||
- Textures in Lens Flare's can not be searched
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
|
"displayName": "Asset Usage Detector",
|
||||||
|
"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!"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ce102123c0ff0a6429f8d5f930e77d96
|
||||||
|
PackageManifestImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user