Compare commits

..

3 Commits

Author SHA1 Message Date
Süleyman Yasir KULA 98d1f43180 References to "SceneAsset"s are now found (fixes #22) 2020-06-16 18:46:22 +03:00
Süleyman Yasir KULA 7d24aa4939 Update package.json 2020-05-29 21:23:42 +03:00
Süleyman Yasir KULA c16bef45cd - Assembly Definition Files' "Assembly Definition References" are now included in the search
- Refreshing the "Project Window (Assets)" group in search results page wasn't working sometimes, fixed
- Tooltips were hard to see in 2019.3+, fixed
2020-05-29 15:27:21 +03:00
6 changed files with 111 additions and 17 deletions
+1
View File
@@ -28,6 +28,7 @@ There are 5 ways to install this plugin:
- 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
@@ -14,10 +14,13 @@ using UnityEngine.UI;
using System.Text;
#if UNITY_2017_1_OR_NEWER
using UnityEngine.U2D;
using UnityEngine.Playables;
#endif
#if UNITY_2018_2_OR_NEWER
using UnityEditor.U2D;
#endif
using UnityEngine.Playables;
#if UNITY_2017_3_OR_NEWER
using UnityEditor.Compilation;
#endif
#if UNITY_2017_2_OR_NEWER
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
// 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
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
private SearchResultGroup currentSearchResultGroup;
@@ -258,6 +277,9 @@ namespace AssetUsageDetectorNamespace
assetsToSearchPathsSet.Clear();
assetsToSearchRootPrefabs.Clear();
excludedAssetsPathsSet.Clear();
#if UNITY_2017_3_OR_NEWER
assemblyDefinitionFilesToSearch.Clear();
#endif
if( assetDependencyCache == null )
{
@@ -291,6 +313,12 @@ namespace AssetUsageDetectorNamespace
{ typeof( AnimationClip ), SearchAnimationClip },
#if UNITY_2017_1_OR_NEWER
{ 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
};
}
@@ -360,7 +388,7 @@ namespace AssetUsageDetectorNamespace
// Find the scenes to search for references
HashSet<string> scenesToSearch = new HashSet<string>();
if( searchParameters.searchInScenesSubset != null )
if( searchParameters.searchInScenesSubset != null && searchParameters.searchInScenesSubset.Length > 0 )
{
foreach( Object obj in searchParameters.searchInScenesSubset )
{
@@ -456,7 +484,7 @@ namespace AssetUsageDetectorNamespace
// Get the paths of all assets that are to be searched
IEnumerable<string> assetPaths;
if( searchParameters.searchInAssetsSubset == null )
if( searchParameters.searchInAssetsSubset == null || searchParameters.searchInAssetsSubset.Length == 0 )
{
string[] allAssetPaths = AssetDatabase.GetAllAssetPaths();
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 ) )
throw new Exception( "Search aborted" );
@@ -706,9 +753,6 @@ namespace AssetUsageDetectorNamespace
if( obj == null || obj.Equals( null ) )
return;
if( obj is SceneAsset )
return;
objectsToSearchSet.Add( obj );
#if UNITY_2018_3_OR_NEWER
@@ -760,6 +804,13 @@ namespace AssetUsageDetectorNamespace
if( shouldAddRootPrefabEntry )
assetsToSearchRootPrefabs.Add( go );
}
#if UNITY_2017_3_OR_NEWER
else if( obj is UnityEditorInternal.AssemblyDefinitionAsset )
{
if( !string.IsNullOrEmpty( assetPath ) )
assemblyDefinitionFilesToSearch[assetPath] = obj;
}
#endif
}
else
{
@@ -931,7 +982,7 @@ namespace AssetUsageDetectorNamespace
else
{
result = PopReferenceNode( unityObject );
SearchWithSerializedObject( result );
SearchVariablesWithSerializedObject( result );
}
callStack.RemoveAt( callStack.Count - 1 );
@@ -946,7 +997,7 @@ namespace AssetUsageDetectorNamespace
currentDepth++;
result = PopReferenceNode( obj );
SearchFieldsAndPropertiesOf( result );
SearchVariablesWithReflection( result );
currentDepth--;
callStack.RemoveAt( callStack.Count - 1 );
@@ -1069,7 +1120,7 @@ namespace AssetUsageDetectorNamespace
}
#endif
SearchWithSerializedObject( referenceNode );
SearchVariablesWithSerializedObject( referenceNode );
return referenceNode;
}
@@ -1251,6 +1302,43 @@ namespace AssetUsageDetectorNamespace
}
#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
private void SearchAnimatedObjects( ReferenceNode referenceNode )
{
@@ -1330,8 +1418,8 @@ namespace AssetUsageDetectorNamespace
}
}
// Search through field and properties of an object for references with SerializedObject
private void SearchWithSerializedObject( ReferenceNode referenceNode )
// Search through variables of an object with SerializedObject
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode )
{
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() )
{
@@ -1378,11 +1466,11 @@ namespace AssetUsageDetectorNamespace
}
// Use reflection algorithm as fallback
SearchFieldsAndPropertiesOf( referenceNode );
SearchVariablesWithReflection( referenceNode );
}
// Search through field and properties of an object for references
private void SearchFieldsAndPropertiesOf( ReferenceNode referenceNode )
// Search through variables of an object with reflection
private void SearchVariablesWithReflection( ReferenceNode referenceNode )
{
// Get filtered variables for this object
VariableGetterHolder[] variables = GetFilteredVariablesForType( referenceNode.nodeObject.GetType() );
@@ -217,7 +217,7 @@ namespace AssetUsageDetectorNamespace
// To work nicely with GUILayout and scroll view
EditorGUILayout.GetControlRect( Utilities.GL_EXPAND_WIDTH, GUILayout.Height( guiHeight ) );
if( parameters.tooltip != null )
if( !string.IsNullOrEmpty( parameters.tooltip ) )
{
// Show tooltip at mouse position
Vector2 mousePos = Event.current.mousePosition;
@@ -99,6 +99,7 @@ namespace AssetUsageDetectorNamespace
normalState = m_tooltipGUIStyle.normal;
normalState.background = null;
normalState.scaledBackgrounds = new Texture2D[0];
normalState.textColor = Color.black;
}
+4
View File
@@ -9,6 +9,10 @@ This tool helps you find usages of the selected asset(s) and/or Object(s) in you
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".
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
- static variables are not searched
- GUIText materials are not searched
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector",
"version": "1.7.7",
"version": "1.7.9",
"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!"
}
}