diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs index 82168f7..6e79c9e 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs @@ -388,7 +388,29 @@ 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; + 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 ) { @@ -1196,22 +1218,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 +1241,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(); diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs index 4598384..4f922ca 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs @@ -405,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 ); @@ -523,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 ); @@ -568,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 ) { diff --git a/Plugins/AssetUsageDetector/Editor/SearchResult.cs b/Plugins/AssetUsageDetector/Editor/SearchResult.cs index d3b456e..1f963dd 100644 --- a/Plugins/AssetUsageDetector/Editor/SearchResult.cs +++ b/Plugins/AssetUsageDetector/Editor/SearchResult.cs @@ -682,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; @@ -742,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 ) { @@ -767,7 +768,7 @@ namespace AssetUsageDetectorNamespace } parameters.guiRect = rect; - GUI.color = c; + GUI.backgroundColor = c; } private void GenerateGUINodes( SearchResultDrawParameters parameters ) diff --git a/Plugins/AssetUsageDetector/Editor/Utilities.cs b/Plugins/AssetUsageDetector/Editor/Utilities.cs index 9064309..6bf5222 100644 --- a/Plugins/AssetUsageDetector/Editor/Utilities.cs +++ b/Plugins/AssetUsageDetector/Editor/Utilities.cs @@ -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; @@ -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; diff --git a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs index 7048bea..32af9d1 100644 --- a/Plugins/AssetUsageDetector/Editor/VariableGetter.cs +++ b/Plugins/AssetUsageDetector/Editor/VariableGetter.cs @@ -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; } } diff --git a/package.json b/package.json index 4c3bbff..93eeddc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.assetusagedetector", "displayName": "Asset Usage Detector", - "version": "1.9.0", + "version": "1.9.1", "documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector", "changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases", "licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",