diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs index ee4d2ba..82b233a 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs @@ -153,8 +153,10 @@ namespace AssetUsageDetectorNamespace private int searchedObjectsCount; // Number of searched objects private double searchStartTime; - private List nodesPool = new List( 32 ); - private List validVariables = new List( 32 ); + private readonly List nodesPool = new List( 32 ); + private readonly List validVariables = new List( 32 ); + + private readonly string reflectionNameSpace = typeof( Assembly ).Namespace; private string CachePath { get { return Application.dataPath + "/../Library/AssetUsageDetector.cache"; } } // Path of the cache file @@ -1152,7 +1154,12 @@ namespace AssetUsageDetectorNamespace continue; // Skip primitive types - if( fields[i].FieldType.IsPrimitiveUnityType() ) + Type variableType = fields[i].FieldType; + 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; // Additional filtering for fields: @@ -1184,7 +1191,12 @@ namespace AssetUsageDetectorNamespace continue; // Skip primitive types - if( properties[i].PropertyType.IsPrimitiveUnityType() ) + Type variableType = properties[i].PropertyType; + 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; // No need to check properties with 'override' keyword diff --git a/Plugins/AssetUsageDetector/Editor/Utilities.cs b/Plugins/AssetUsageDetector/Editor/Utilities.cs index 8e9d79b..84e76d6 100644 --- a/Plugins/AssetUsageDetector/Editor/Utilities.cs +++ b/Plugins/AssetUsageDetector/Editor/Utilities.cs @@ -16,19 +16,18 @@ namespace AssetUsageDetectorNamespace.Extras typeof( string ), typeof( Vector4 ), typeof( Vector3 ), typeof( Vector2 ), typeof( Rect ), typeof( Quaternion ), typeof( Color ), typeof( Color32 ), typeof( LayerMask ), typeof( Matrix4x4 ), typeof( AnimationCurve ), typeof( Gradient ), typeof( RectOffset ), - typeof( Assembly ), // Searching assembly variables for reference throws InvalidCastException on .NET 4.0 runtime typeof( bool[] ), typeof( byte[] ), typeof( sbyte[] ), typeof( char[] ), typeof( decimal[] ), typeof( double[] ), typeof( float[] ), typeof( int[] ), typeof( uint[] ), typeof( long[] ), typeof( ulong[] ), typeof( short[] ), typeof( ushort[] ), typeof( string[] ), typeof( Vector4[] ), typeof( Vector3[] ), typeof( Vector2[] ), typeof( Rect[] ), typeof( Quaternion[] ), typeof( Color[] ), typeof( Color32[] ), typeof( LayerMask[] ), - typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ), typeof( Assembly[] ), + typeof( Matrix4x4[] ), typeof( AnimationCurve[] ), typeof( Gradient[] ), typeof( RectOffset[] ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ), - typeof( List ), typeof( List ), typeof( List ), typeof( List ), typeof( List ) + typeof( List ), typeof( List ), typeof( List ), typeof( List ) }; private static readonly HashSet folderContentsSet = new HashSet();