Compare commits

...

9 Commits

Author SHA1 Message Date
Süleyman Yasir KULA 7b60eeacf7 If an exception occurs while searching for references via reflection, the problematic object will be skipped and a warning will be logged to the console instead of interrupting the whole search 2021-03-17 16:13:24 +03:00
Süleyman Yasir KULA b8470536b9 - Following variables of ParticleSystem are now included in search: LightsModule->Light, CollisionModule->Plane, TriggerModule->Collider
- Improved readability of texts in dark Editor skin
- Fixed "Animator is not playing an AnimatorController" warnings
- Fixed "TMP_Sprite Animator" component getting added to TextMesh Pro objects in the scene while searching for a scene object's references at runtime
2021-03-14 17:15:00 +03:00
Süleyman Yasir KULA 1bebc8691d Update package.json
Added documentationUrl, changelogUrl and licensesUrl to package.json
2021-01-19 12:51:21 +03:00
Süleyman Yasir KULA 5a81e5011b While using the Search for References button in right-click menu, if current scene setup is different from the initial scene setup, plugin now asks user whether or not they want to restore the initial scene setup instead of automatically restoring the initial scene setup 2020-12-22 22:46:22 +03:00
Süleyman Yasir KULA ba7539d983 References from Animator Override Controllers to their base Animator Controllers are now found 2020-11-18 13:46:42 +03:00
Süleyman Yasir KULA f4129574fb - Custom meshes used in ParticleSystem's Renderer module weren't included in the search, fixed
- Fix an exception that occurred when searching an Assembly Definition File's references if one of its References was missing
2020-10-01 13:43:23 +03:00
Süleyman Yasir KULA 7738da9d19 "Search for References-Include Children" didn't include inactive child objects in search, fixed 2020-09-23 23:12:47 +03:00
Süleyman Yasir KULA 077505a217 Fixed a rare issue that occurs when searching properties with ref returns for references in Play mode 2020-08-20 12:24:37 +03:00
Süleyman Yasir KULA 003cedd363 - Added 2 options to the "Search for References" button in Hierarchy objects' context (right-click) menu: "This Object Only" and "Include Children"
- In search results, "arrayVariable.Array.data[0]" is now displayed as "arrayVariable[0]"
2020-08-08 19:52:59 +03:00
8 changed files with 219 additions and 94 deletions
@@ -547,26 +547,10 @@ namespace AssetUsageDetectorNamespace
}
catch( Exception e )
{
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine();
if( callStack.Count > 0 )
{
sb.AppendLine( "Stack contents: " );
for( int i = callStack.Count - 1; i >= 0; i-- )
{
sb.Append( i ).Append( ": " );
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 1000 );
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine().Append( e ).AppendLine();
Object unityObject = callStack[i] as Object;
if( unityObject )
sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" );
else if( callStack[i] != null )
sb.Append( callStack[i].GetType() ).AppendLine( " object" );
else
sb.AppendLine( "<<destroyed>>" );
}
sb.AppendLine();
}
Object latestUnityObjectInCallStack = AppendCallStackToStringBuilder( sb );
sb.AppendLine( "Searching references of: " );
foreach( Object obj in objectsToSearchSet )
@@ -575,10 +559,7 @@ namespace AssetUsageDetectorNamespace
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
}
sb.AppendLine();
sb.Append( e ).AppendLine();
Debug.LogError( sb.ToString() );
Debug.LogError( sb.ToString(), latestUnityObjectInCallStack );
try
{
@@ -619,7 +600,9 @@ namespace AssetUsageDetectorNamespace
if( shouldOpenPrefabStageWithoutContext )
#endif
{
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
}
}
#endif
}
@@ -1090,5 +1073,48 @@ namespace AssetUsageDetectorNamespace
Object.DestroyImmediate( temp );
}
}
// Appends contents of callStack to StringBuilder and returns the most recent Unity object in callStack
private Object AppendCallStackToStringBuilder( StringBuilder sb )
{
Object latestUnityObjectInCallStack = null;
if( callStack.Count > 0 )
{
sb.AppendLine().AppendLine( "Stack contents: " );
for( int i = callStack.Count - 1; i >= 0; i-- )
{
latestUnityObjectInCallStack = callStack[i] as Object;
if( latestUnityObjectInCallStack )
{
if( !AssetDatabase.Contains( latestUnityObjectInCallStack ) )
{
string scenePath = AssetDatabase.GetAssetOrScenePath( latestUnityObjectInCallStack );
if( !string.IsNullOrEmpty( scenePath ) && SceneManager.GetSceneByPath( scenePath ).IsValid() )
sb.Append( "Scene: " ).AppendLine( scenePath );
}
break;
}
}
for( int i = callStack.Count - 1; i >= 0; i-- )
{
sb.Append( i ).Append( ": " );
Object unityObject = callStack[i] as Object;
if( unityObject )
sb.Append( unityObject.name ).Append( " (" ).Append( unityObject.GetType() ).AppendLine( ")" );
else if( callStack[i] != null )
sb.Append( callStack[i].GetType() ).AppendLine( " object" );
else
sb.AppendLine( "<<destroyed>>" );
}
sb.AppendLine();
}
return latestUnityObjectInCallStack;
}
}
}
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Text;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
@@ -382,6 +383,36 @@ namespace AssetUsageDetectorNamespace
if( objectsToSearchSet.Contains( script ) )
referenceNode.AddLinkTo( GetReferenceNode( script ) );
}
else if( component is ParticleSystemRenderer )
{
// Search ParticleSystemRenderer's custom meshes for references (they aren't searched by SerializedObject, unfortunately)
Mesh[] meshes = new Mesh[( (ParticleSystemRenderer) component ).meshCount];
int meshCount = ( (ParticleSystemRenderer) component ).GetMeshes( meshes );
for( int i = 0; i < meshCount; i++ )
referenceNode.AddLinkTo( SearchObject( meshes[i] ), "Renderer Module: Mesh" );
}
else if( component is ParticleSystem )
{
// Some ParticleSystem properties aren't searched by SerializedObject, search them manually instead
ParticleSystem particleSystem = (ParticleSystem) component;
referenceNode.AddLinkTo( SearchObject( particleSystem.lights.light ), "Light Module: Light" );
try
{
ParticleSystem.CollisionModule collisionModule = particleSystem.collision;
for( int i = 0, j = collisionModule.maxPlaneCount; i < j; i++ )
referenceNode.AddLinkTo( SearchObject( collisionModule.GetPlane( i ) ), "Collision Module: Plane" );
}
catch { }
try
{
ParticleSystem.TriggerModule triggerModule = particleSystem.trigger;
for( int i = 0, j = triggerModule.maxColliderCount; i < j; i++ )
referenceNode.AddLinkTo( SearchObject( triggerModule.GetCollider( i ) ), "Trigger Module: Collider" );
}
catch { }
}
else if( searchRenderers && component is Renderer )
{
// If an asset is a shader, texture or material, and this component is a Renderer,
@@ -392,7 +423,7 @@ namespace AssetUsageDetectorNamespace
}
else if( component is Animation )
{
// If this component is an Animation, search its animation clips for references
// Search animation clips for references
foreach( AnimationState anim in (Animation) component )
referenceNode.AddLinkTo( SearchObject( anim.clip ) );
@@ -401,7 +432,7 @@ namespace AssetUsageDetectorNamespace
}
else if( component is Animator )
{
// If this component is an Animator, search its animation clips for references (via AnimatorController)
// Search animation clips for references (via AnimatorController)
referenceNode.AddLinkTo( SearchObject( ( (Animator) component ).runtimeAnimatorController ) );
// Search the objects that are animated by this Animator component for references
@@ -410,7 +441,7 @@ namespace AssetUsageDetectorNamespace
#if UNITY_2017_2_OR_NEWER
else if( component is Tilemap )
{
// If this component is a Tilemap, search its tiles for references
// Search the tiles for references
TileBase[] tiles = new TileBase[( (Tilemap) component ).GetUsedTilesCount()];
( (Tilemap) component ).GetUsedTilesNonAlloc( tiles );
@@ -424,7 +455,7 @@ namespace AssetUsageDetectorNamespace
#if UNITY_2017_1_OR_NEWER
else if( component is PlayableDirector )
{
// If this component is a PlayableDirectory, search its PlayableAsset's scene bindings for references
// Search the PlayableAsset's scene bindings for references
PlayableAsset playableAsset = ( (PlayableDirector) component ).playableAsset;
if( playableAsset != null && !playableAsset.Equals( null ) )
{
@@ -536,7 +567,7 @@ namespace AssetUsageDetectorNamespace
{
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].name );
if( objectsToSearchSet.Contains( defaultValue ) )
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default Variable Value: " + variables[i].name );
referenceNode.AddLinkTo( GetReferenceNode( defaultValue ), "Default variable value: " + variables[i].name );
}
}
@@ -561,6 +592,13 @@ namespace AssetUsageDetectorNamespace
}
else
{
if( controller is AnimatorOverrideController )
{
RuntimeAnimatorController parentController = ( (AnimatorOverrideController) controller ).runtimeAnimatorController;
if( objectsToSearchSet.Contains( parentController ) )
referenceNode.AddLinkTo( GetReferenceNode( parentController ) );
}
AnimationClip[] animClips = controller.animationClips;
for( int i = 0; i < animClips.Length; i++ )
referenceNode.AddLinkTo( SearchObject( animClips[i] ) );
@@ -719,9 +757,12 @@ namespace AssetUsageDetectorNamespace
#else
string assemblyPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName( assemblyDefinitionFile.references[i] );
#endif
Object searchedAssemblyDefinitionFile;
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
if( !string.IsNullOrEmpty( assemblyPath ) )
{
Object searchedAssemblyDefinitionFile;
if( assemblyDefinitionFilesToSearch.TryGetValue( assemblyPath, out searchedAssemblyDefinitionFile ) )
referenceNode.AddLinkTo( GetReferenceNode( searchedAssemblyDefinitionFile ), "Referenced Assembly" );
}
}
}
@@ -1035,7 +1076,7 @@ namespace AssetUsageDetectorNamespace
// m_RD.texture is a redundant reference that shows up when searching sprites
if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath );
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
}
} while( iterator.Next( enterChildren ) );
@@ -1061,7 +1102,7 @@ namespace AssetUsageDetectorNamespace
try
{
object variableValue = variables[i].Get( referenceNode.nodeObject );
if( variableValue == null )
if( variableValue == null || variableValue.Equals( null ) )
continue;
// Values stored inside ICollection objects are searched using IEnumerable,
@@ -1092,6 +1133,15 @@ namespace AssetUsageDetectorNamespace
catch( MissingReferenceException ) { }
catch( MissingComponentException ) { }
catch( NotImplementedException ) { }
catch( Exception e )
{
// Unknown exceptions usually occur when variableValue is an IEnumerable and its enumerator throws an unhandled exception in MoveNext or Current
StringBuilder sb = new StringBuilder( callStack.Count * 50 + 1000 );
sb.Append( "Skipped searching " ).Append( referenceNode.nodeObject.GetType().FullName ).Append( "." ).Append( variables[i].name ).AppendLine( " because it threw exception:" ).Append( e ).AppendLine();
Object latestUnityObjectInCallStack = AppendCallStackToStringBuilder( sb );
Debug.LogWarning( sb.ToString(), latestUnityObjectInCallStack );
}
}
}
@@ -1178,22 +1228,20 @@ namespace AssetUsageDetectorNamespace
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
continue;
// Additional filtering for properties:
// 1- Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of Component's to get more useful results
// 2- Ignore "canvasRenderer" and "canvas" properties of Graphic components
// 3 & 4- Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
string propertyName = property.Name;
// Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of components to get more useful results
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
continue;
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
continue;
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
continue;
else if( typeof( Renderer ).IsAssignableFrom( currType ) &&
( propertyName == "sharedMaterial" || propertyName == "sharedMaterials" ) )
continue;
// Same as above
else if( ( propertyName == "material" || propertyName == "materials" ) &&
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
#if !UNITY_2019_3_OR_NEWER
@@ -1203,6 +1251,19 @@ namespace AssetUsageDetectorNamespace
#endif
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
continue;
// "sharedMaterials" are searched via SearchComponent, no need to search it with reflection, as well
else if( typeof( Renderer ).IsAssignableFrom( currType ) &&
( propertyName == "sharedMaterial" || propertyName == "sharedMaterials" ) )
continue;
// Ignore "parameters" property of Animator since it doesn't contain any useful data and logs a warning to the console when Animator is inactive
else if( typeof( Animator ).IsAssignableFrom( currType ) && propertyName == "parameters" )
continue;
// Ignore "spriteAnimator" property of TMP_Text component because this property adds a TMP_SpriteAnimator component to the object if it doesn't exist
else if( propertyName == "spriteAnimator" && currType.Name == "TMP_Text" )
continue;
// Ignore "meshFilter" property of TextMeshPro and TMP_SubMesh components because this property adds a MeshFilter component to the object if it doesn't exist
else if( propertyName == "meshFilter" && ( currType.Name == "TextMeshPro" || currType.Name == "TMP_SubMesh" ) )
continue;
else
{
VariableGetVal getter = property.CreateGetter();
@@ -124,14 +124,13 @@ namespace AssetUsageDetectorNamespace
}
// Quickly initiate search for the selected assets
[MenuItem( "GameObject/Search for References", priority = 49 )]
[MenuItem( "GameObject/Search for References/This Object Only", priority = 49 )]
[MenuItem( "Assets/Search for References", priority = 1000 )]
private static void SearchSelectedAssetReferences( MenuCommand command )
{
// This happens when this button is clicked via hierarchy's right click context menu
// and is called once for each object in the selection. We don't want that, we want
// the function to be called only once so that there aren't multiple empty parents
// generated in one call
// the function to be called only once
if( command.context )
{
EditorApplication.update -= CallSearchSelectedAssetReferencesOnce;
@@ -141,8 +140,21 @@ namespace AssetUsageDetectorNamespace
ShowAndSearch( Selection.objects );
}
[MenuItem( "GameObject/Search for References/Include Children", priority = 49 )]
private static void SearchSelectedAssetReferencesWithChildren( MenuCommand command )
{
if( command.context )
{
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
EditorApplication.update += CallSearchSelectedAssetReferencesWithChildrenOnce;
}
else
ShowAndSearch( Selection.objects, true );
}
// Show the menu item only if there is a selection in the Editor
[MenuItem( "GameObject/Search for References", validate = true )]
[MenuItem( "GameObject/Search for References/This Object Only", validate = true )]
[MenuItem( "GameObject/Search for References/Include Children", validate = true )]
[MenuItem( "Assets/Search for References", validate = true )]
private static bool SearchSelectedAssetReferencesValidate( MenuCommand command )
{
@@ -150,13 +162,13 @@ namespace AssetUsageDetectorNamespace
}
// Quickly show the AssetUsageDetector window and initiate a search
public static void ShowAndSearch( IEnumerable<Object> searchObjects )
public static void ShowAndSearch( IEnumerable<Object> searchObjects, bool? shouldSearchChildren = null )
{
ShowAndSearchInternal( searchObjects, null );
ShowAndSearchInternal( searchObjects, null, shouldSearchChildren );
}
// Quickly show the AssetUsageDetector window and initiate a search
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters )
public static void ShowAndSearch( AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren = null )
{
if( searchParameters == null )
{
@@ -164,7 +176,7 @@ namespace AssetUsageDetectorNamespace
return;
}
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters );
ShowAndSearchInternal( searchParameters.objectsToSearch, searchParameters, shouldSearchChildren );
}
private static void CallSearchSelectedAssetReferencesOnce()
@@ -173,9 +185,15 @@ namespace AssetUsageDetectorNamespace
SearchSelectedAssetReferences( new MenuCommand( null ) );
}
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters )
private static void CallSearchSelectedAssetReferencesWithChildrenOnce()
{
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
EditorApplication.update -= CallSearchSelectedAssetReferencesWithChildrenOnce;
SearchSelectedAssetReferencesWithChildren( new MenuCommand( null ) );
}
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
{
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true, true ) )
{
Debug.LogError( "Need to reset the previous search first!" );
return;
@@ -187,7 +205,7 @@ namespace AssetUsageDetectorNamespace
if( searchObjects != null )
{
foreach( Object obj in searchObjects )
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj ) );
mainWindow.objectsToSearch.Add( new ObjectToSearch( obj, shouldSearchChildren ) );
}
if( searchParameters != null )
@@ -262,11 +280,8 @@ namespace AssetUsageDetectorNamespace
SavePrefs();
if( searchResult != null && currentPhase == Phase.Complete && !EditorApplication.isPlaying && searchResult.IsSceneSetupDifferentThanCurrentSetup() )
{
if( EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
searchResult.RestoreInitialSceneSetup();
}
if( searchResult != null && currentPhase == Phase.Complete )
searchResult.RestoreInitialSceneSetup( true );
}
private void OnFocus()
@@ -381,7 +396,7 @@ namespace AssetUsageDetectorNamespace
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
if( GUILayout.Button( "RETURN", Utilities.GL_HEIGHT_30 ) )
ReturnToSetupPhase( restoreInitialSceneSetup );
ReturnToSetupPhase( restoreInitialSceneSetup, false );
}
else if( currentPhase == Phase.Setup )
{
@@ -390,12 +405,10 @@ namespace AssetUsageDetectorNamespace
GUILayout.Space( 10 );
Color c = GUI.color;
GUI.color = Color.cyan;
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.cyan;
GUILayout.Box( "SEARCH IN", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.color = c;
GUI.backgroundColor = c;
searchInAssetsFolder = EditorGUILayout.ToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
@@ -508,11 +521,9 @@ namespace AssetUsageDetectorNamespace
//GUILayout.Space( 10 );
GUI.color = Color.cyan;
GUI.backgroundColor = Color.cyan;
GUILayout.Box( "SETTINGS", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.color = c;
GUI.backgroundColor = c;
lazySceneSearch = EditorGUILayout.ToggleLeft( "Lazy scene search: scenes are searched in detail only when they are manually refreshed (faster search)", lazySceneSearch );
noAssetDatabaseChanges = EditorGUILayout.ToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
@@ -543,7 +554,7 @@ namespace AssetUsageDetectorNamespace
restoreInitialSceneSetup = EditorGUILayout.ToggleLeft( restoreInitialSceneSetupLabel, restoreInitialSceneSetup );
if( GUILayout.Button( "Reset Search", Utilities.GL_HEIGHT_30 ) )
ReturnToSetupPhase( restoreInitialSceneSetup );
ReturnToSetupPhase( restoreInitialSceneSetup, false );
if( searchResult == null )
{
@@ -553,10 +564,10 @@ namespace AssetUsageDetectorNamespace
else if( !searchResult.SearchCompletedSuccessfully )
EditorGUILayout.HelpBox( "ERROR: search was interrupted, check the logs for more info", MessageType.Error );
Color c = GUI.color;
GUI.color = Color.green;
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.green;
GUILayout.Box( "Don't forget to save scene(s) if you made any changes!", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.color = c;
GUI.backgroundColor = c;
if( searchResult.NumberOfGroups == 0 )
{
@@ -718,9 +729,9 @@ namespace AssetUsageDetectorNamespace
}
#endif
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup )
private bool ReturnToSetupPhase( bool restoreInitialSceneSetup, bool sceneSetupRestorationIsOptional )
{
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup() )
if( searchResult != null && restoreInitialSceneSetup && !EditorApplication.isPlaying && !searchResult.RestoreInitialSceneSetup( sceneSetupRestorationIsOptional ) )
return false;
searchResult = null;
@@ -29,13 +29,13 @@ namespace AssetUsageDetectorNamespace
private static MonoScript[] monoScriptsInProject;
private static HashSet<Object> currentSubAssets;
public ObjectToSearch( Object obj )
public ObjectToSearch( Object obj, bool? shouldSearchChildren = null )
{
this.obj = obj;
RefreshSubAssets();
RefreshSubAssets( shouldSearchChildren );
}
public void RefreshSubAssets()
public void RefreshSubAssets( bool? shouldSearchChildren = null )
{
if( subAssets == null )
subAssets = new List<SubAsset>();
@@ -47,11 +47,11 @@ namespace AssetUsageDetectorNamespace
else
currentSubAssets.Clear();
AddSubAssets( obj, false );
AddSubAssets( obj, false, shouldSearchChildren );
currentSubAssets.Clear();
}
private void AddSubAssets( Object target, bool includeTarget )
private void AddSubAssets( Object target, bool includeTarget, bool? shouldSearchChildren )
{
if( target == null || target.Equals( null ) )
return;
@@ -65,13 +65,13 @@ namespace AssetUsageDetectorNamespace
// 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>();
Transform[] children = go.GetComponentsInChildren<Transform>( true );
for( int i = 0; i < children.Length; i++ )
{
if( ReferenceEquals( children[i], goTransform ) )
continue;
subAssets.Add( new SubAsset( children[i].gameObject, false ) );
subAssets.Add( new SubAsset( children[i].gameObject, shouldSearchChildren ?? false ) );
}
}
else
@@ -83,7 +83,7 @@ namespace AssetUsageDetectorNamespace
{
if( !currentSubAssets.Contains( target ) )
{
subAssets.Add( new SubAsset( target, true ) );
subAssets.Add( new SubAsset( target, shouldSearchChildren ?? true ) );
currentSubAssets.Add( target );
}
}
@@ -93,7 +93,7 @@ namespace AssetUsageDetectorNamespace
if( target.IsFolder() )
{
foreach( string filePath in Utilities.EnumerateFolderContents( target ) )
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true );
AddSubAssets( AssetDatabase.LoadAssetAtPath<Object>( filePath ), true, shouldSearchChildren );
return;
}
@@ -112,7 +112,7 @@ namespace AssetUsageDetectorNamespace
if( asset != target )
{
subAssets.Add( new SubAsset( asset, true ) );
subAssets.Add( new SubAsset( asset, shouldSearchChildren ?? true ) );
currentSubAssets.Add( asset );
}
@@ -142,7 +142,7 @@ namespace AssetUsageDetectorNamespace
if( !currentSubAssets.Contains( monoScriptsInProject[j] ) )
{
subAssets.Add( new SubAsset( monoScriptsInProject[j], true ) );
subAssets.Add( new SubAsset( monoScriptsInProject[j], shouldSearchChildren ?? true ) );
currentSubAssets.Add( monoScriptsInProject[j] );
}
}
@@ -328,7 +328,7 @@ namespace AssetUsageDetectorNamespace
// Close the scenes that were not part of the initial scene setup
// Returns true if initial scene setup is restored successfully
public bool RestoreInitialSceneSetup()
public bool RestoreInitialSceneSetup( bool optional )
{
if( initialSceneSetup == null || initialSceneSetup.Length == 0 )
return true;
@@ -336,6 +336,9 @@ namespace AssetUsageDetectorNamespace
if( EditorApplication.isPlaying || !EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() )
return false;
if( optional && IsSceneSetupDifferentThanCurrentSetup() && !EditorUtility.DisplayDialog( "Scenes", "Restore initial scene setup?", "Yes", "Leave it as is" ) )
return true;
for( int i = 0; i < initialSceneSetup.Length; i++ )
{
Scene scene = EditorSceneManager.GetSceneByPath( initialSceneSetup[i].path );
@@ -679,8 +682,8 @@ namespace AssetUsageDetectorNamespace
parameters.shouldRefreshEditorWindow = true; // A repaint is needed to work nicely with GUILayout
}
Color c = GUI.color;
GUI.color = Color.cyan;
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.cyan;
Rect rect = parameters.guiRect;
float width = rect.width;
@@ -739,7 +742,8 @@ namespace AssetUsageDetectorNamespace
if( IsExpanded )
{
GUI.color = Color.yellow;
// On light skin, yellow background looks better than light grey background
GUI.backgroundColor = EditorGUIUtility.isProSkin ? c : Color.yellow;
if( PendingSearch )
{
@@ -764,7 +768,7 @@ namespace AssetUsageDetectorNamespace
}
parameters.guiRect = rect;
GUI.color = c;
GUI.backgroundColor = c;
}
private void GenerateGUINodes( SearchResultDrawParameters parameters )
+24 -3
View File
@@ -81,6 +81,14 @@ namespace AssetUsageDetectorNamespace
alignment = TextAnchor.MiddleCenter,
font = EditorStyles.label.font
};
Color textColor = GUI.skin.button.normal.textColor;
m_boxGUIStyle.normal.textColor = textColor;
m_boxGUIStyle.hover.textColor = textColor;
m_boxGUIStyle.focused.textColor = textColor;
m_boxGUIStyle.active.textColor = textColor;
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
}
return m_boxGUIStyle;
@@ -415,8 +423,8 @@ namespace AssetUsageDetectorNamespace
if( typeof( Type ).IsAssignableFrom( type ) || type.Namespace == reflectionNamespace )
return true;
// Searching pointer variables for reference throws ArgumentException
if( type.IsPointer )
// Searching pointers or ref variables for reference throws ArgumentException
if( type.IsPointer || type.IsByRef )
return true;
return false;
@@ -446,7 +454,20 @@ namespace AssetUsageDetectorNamespace
{
// Can't use PropertyWrapper (which uses CreateDelegate) for property getters of structs
if( propertyInfo.DeclaringType.IsValueType )
return propertyInfo.CanRead ? ( ( obj ) => propertyInfo.GetValue( obj, null ) ) : (VariableGetVal) null;
{
return !propertyInfo.CanRead ? (VariableGetVal) null : ( obj ) =>
{
try
{
return propertyInfo.GetValue( obj, null );
}
catch
{
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
return null;
}
};
}
Type GenType = typeof( PropertyWrapper<,> ).MakeGenericType( propertyInfo.DeclaringType, propertyInfo.PropertyType );
return ( (IPropertyAccessor) Activator.CreateInstance( GenType, propertyInfo.GetGetMethod( true ) ) ).GetValue;
@@ -69,8 +69,7 @@ namespace AssetUsageDetectorNamespace
}
catch
{
// Property getters may return various kinds of exceptions
// if their backing fields are not initialized (yet)
// Property getters may return various kinds of exceptions if their backing fields are not initialized (yet)
return null;
}
}
+4 -1
View File
@@ -1,6 +1,9 @@
{
"name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector",
"version": "1.8.4",
"version": "1.9.2",
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
"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!"
}