Compare commits

...

8 Commits

Author SHA1 Message Date
yasirkula 133b8b1227 Fixed small text issue on 2019.1 and 2019.2 (some devices might not have been affected by this issue) 2021-07-06 17:49:31 +03:00
yasirkula 1db9dbf9b0 Fixed issues with mysterious empty dependencies returned by AssetDatabase.GetDependencies 2021-06-09 12:35:25 +03:00
yasirkula a6b0f5ae92 Unity 2020 support 2021-05-18 13:47:38 +03:00
Süleyman Yasir KULA 8e7369e44e Some properties in Project Settings like "Quality Settings->SRP Asset" weren't included in search, fixed 2021-03-28 19:57:44 +03:00
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
8 changed files with 217 additions and 76 deletions
@@ -547,26 +547,10 @@ namespace AssetUsageDetectorNamespace
}
catch( Exception e )
{
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 500 );
StringBuilder sb = new StringBuilder( objectsToSearchSet.Count * 50 + callStack.Count * 50 + 1000 );
sb.AppendLine( "<b>AssetUsageDetector Error:</b>" ).AppendLine().Append( e ).AppendLine();
if( callStack.Count > 0 )
{
sb.AppendLine( "Stack contents: " );
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();
}
Object latestUnityObjectInCallStack = AppendCallStackToStringBuilder( sb );
sb.AppendLine( "Searching references of: " );
foreach( Object obj in objectsToSearchSet )
@@ -575,7 +559,7 @@ namespace AssetUsageDetectorNamespace
sb.Append( obj.name ).Append( " (" ).Append( obj.GetType() ).AppendLine( ")" );
}
Debug.LogError( sb.ToString() );
Debug.LogError( sb.ToString(), latestUnityObjectInCallStack );
try
{
@@ -616,7 +600,9 @@ namespace AssetUsageDetectorNamespace
if( shouldOpenPrefabStageWithoutContext )
#endif
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
{
AssetDatabase.OpenAsset( AssetDatabase.LoadAssetAtPath<GameObject>( openPrefabStageAssetPath ) );
}
}
#endif
}
@@ -1087,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;
}
}
}
@@ -51,10 +51,35 @@ namespace AssetUsageDetectorNamespace
if( fileSizes == null || fileSizes.Length != dependencies.Length )
fileSizes = new long[dependencies.Length];
for( int i = 0; i < dependencies.Length; i++ )
int length = dependencies.Length;
for( int i = 0; i < length; i++ )
{
FileInfo assetFile = new FileInfo( dependencies[i] );
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
if( !string.IsNullOrEmpty( dependencies[i] ) )
{
FileInfo assetFile = new FileInfo( dependencies[i] );
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
}
else
{
// This dependency is empty which causes issues when passed to FileInfo constructor
// Find a non-empty dependency and move it to this index
for( int j = length - 1; j > i; j--, length-- )
{
if( !string.IsNullOrEmpty( dependencies[j] ) )
{
dependencies[i--] = dependencies[j];
break;
}
}
length--;
}
}
if( length != fileSizes.Length )
{
Array.Resize( ref dependencies, length );
Array.Resize( ref fileSizes, length );
}
}
}
@@ -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;
@@ -388,7 +389,37 @@ namespace AssetUsageDetectorNamespace
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] ), "Custom particle mesh" );
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;
#if UNITY_2020_2_OR_NEWER
for( int i = 0, j = collisionModule.planeCount; i < j; i++ )
#else
for( int i = 0, j = collisionModule.maxPlaneCount; i < j; i++ )
#endif
referenceNode.AddLinkTo( SearchObject( collisionModule.GetPlane( i ) ), "Collision Module: Plane" );
}
catch { }
try
{
ParticleSystem.TriggerModule triggerModule = particleSystem.trigger;
#if UNITY_2020_2_OR_NEWER
for( int i = 0, j = triggerModule.colliderCount; i < j; i++ )
#else
for( int i = 0, j = triggerModule.maxColliderCount; i < j; i++ )
#endif
referenceNode.AddLinkTo( SearchObject( triggerModule.GetCollider( i ) ), "Trigger Module: Collider" );
}
catch { }
}
else if( searchRenderers && component is Renderer )
{
@@ -998,26 +1029,38 @@ namespace AssetUsageDetectorNamespace
SerializedProperty iteratorVisible = so.GetIterator();
if( iterator.Next( true ) )
{
string assetPath = AssetDatabase.GetAssetPath( (Object) referenceNode.nodeObject );
bool isProjectSettings = !string.IsNullOrEmpty( assetPath ) && assetPath.StartsWithFast( "ProjectSettings/" );
bool iteratingVisible = iteratorVisible.NextVisible( true );
bool enterChildren;
do
{
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
// properties don't have FieldInfos so we are skipping them, which is good because search results found in
// those properties aren't interesting and mostly confusing)
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
if( isVisible )
iteratingVisible = iteratorVisible.NextVisible( true );
if( isProjectSettings )
{
// Search Project Settings in full because for some reason, important settings like SRP asset
// slot in Quality Settings aren't searched when iterating over only visible properties
enterChildren = true;
}
else
{
Type propFieldType;
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
}
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
// properties don't have FieldInfos so we are skipping them, which is good because search results found in
// those properties aren't interesting and mostly confusing)
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
if( isVisible )
iteratingVisible = iteratorVisible.NextVisible( true );
else
{
Type propFieldType;
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
}
if( !isVisible )
{
enterChildren = false;
continue;
if( !isVisible )
{
enterChildren = false;
continue;
}
}
ReferenceNode searchResult;
@@ -1079,7 +1122,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,
@@ -1110,6 +1153,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 );
}
}
}
@@ -1196,22 +1248,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
@@ -1221,6 +1271,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();
@@ -193,7 +193,7 @@ namespace AssetUsageDetectorNamespace
private static void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsageDetector.Parameters searchParameters, bool? shouldSearchChildren )
{
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true ) )
if( mainWindow != null && !mainWindow.ReturnToSetupPhase( true, true ) )
{
Debug.LogError( "Need to reset the previous search first!" );
return;
@@ -280,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()
@@ -399,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 )
{
@@ -408,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 );
@@ -526,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 );
@@ -561,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 )
{
@@ -571,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 )
{
@@ -736,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;
@@ -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 )
+26 -1
View File
@@ -81,6 +81,18 @@ 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;
#if !UNITY_2019_1_OR_NEWER || UNITY_2019_3_OR_NEWER
// On 2019.1 and 2019.2 versions, GUI.skin.button.fontSize returns 0 on some devices
// https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/page-3#post-7285954
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
#endif
}
return m_boxGUIStyle;
@@ -446,7 +458,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.9",
"version": "1.9.6",
"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!"
}