Skip to content

Commit 0342ab2

Browse files
committed
For simplicity's sake, removed the following search parameters that were only exposed in the code: searchNonSerializableVariables, fieldModifiers, propertyModifiers
1 parent 6a158cb commit 0342ab2

6 files changed

Lines changed: 95 additions & 224 deletions

File tree

Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public class Parameters
3838
public bool searchInProjectSettings = true;
3939

4040
public int searchDepthLimit = 4;
41-
public BindingFlags fieldModifiers = BindingFlags.Public | BindingFlags.NonPublic;
42-
public BindingFlags propertyModifiers = BindingFlags.Public | BindingFlags.NonPublic;
43-
public bool searchNonSerializableVariables = true;
4441

4542
public bool searchUnusedMaterialProperties = true;
4643

@@ -467,10 +464,6 @@ public SearchResult Run( Parameters searchParameters )
467464
searchResult.Add( currentSearchResultGroup );
468465
}
469466

470-
// Search non-serializable variables for references while searching a scene in play mode
471-
if( isInPlayMode )
472-
searchSerializableVariablesOnly = false;
473-
474467
if( scenesToSearch.Count > 0 )
475468
{
476469
// Calculate the path(s) of the scenes that won't be searched for references

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs

Lines changed: 84 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,6 @@ private static string ExtractGUIDFromString( string str )
173173
private bool searchMonoBehavioursForScript;
174174
private bool searchTextureReferences;
175175
private bool searchShaderGraphsForSubGraphs;
176-
private bool searchSerializableVariablesOnly;
177-
private bool prevSearchSerializableVariablesOnly;
178-
179-
private BindingFlags fieldModifiers, propertyModifiers;
180-
private BindingFlags prevFieldModifiers, prevPropertyModifiers;
181176

182177
// Unity's internal function that returns a SerializedProperty's corresponding FieldInfo
183178
private delegate FieldInfo FieldInfoGetter( SerializedProperty p, out Type t );
@@ -246,17 +241,6 @@ private void InitializeSearchFunctionsData( Parameters searchParameters )
246241
};
247242
}
248243

249-
fieldModifiers = searchParameters.fieldModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
250-
propertyModifiers = searchParameters.propertyModifiers | BindingFlags.Instance | BindingFlags.DeclaredOnly;
251-
searchSerializableVariablesOnly = !searchParameters.searchNonSerializableVariables;
252-
253-
if( prevFieldModifiers != fieldModifiers || prevPropertyModifiers != propertyModifiers || prevSearchSerializableVariablesOnly != searchSerializableVariablesOnly )
254-
typeToVariables.Clear();
255-
256-
prevFieldModifiers = fieldModifiers;
257-
prevPropertyModifiers = propertyModifiers;
258-
prevSearchSerializableVariablesOnly = searchSerializableVariablesOnly;
259-
260244
searchPrefabConnections = false;
261245
searchMonoBehavioursForScript = false;
262246
searchTextureReferences = false;
@@ -739,7 +723,7 @@ private ReferenceNode SearchMonoScript( object obj )
739723
VariableGetterHolder[] variables = GetFilteredVariablesForType( scriptType );
740724
for( int i = 0; i < variables.Length; i++ )
741725
{
742-
if( variables[i].isSerializable && !variables[i].IsProperty )
726+
if (!variables[i].IsProperty)
743727
{
744728
Object defaultValue = scriptImporter.GetDefaultReference( variables[i].Name );
745729
if( objectsToSearchSet.Contains( defaultValue ) )
@@ -1502,10 +1486,6 @@ private void SearchVariablesWithReflection( ReferenceNode referenceNode )
15021486
VariableGetterHolder[] variables = GetFilteredVariablesForType( referenceNode.nodeObject.GetType() );
15031487
for( int i = 0; i < variables.Length; i++ )
15041488
{
1505-
// When possible, don't search non-serializable variables
1506-
if( searchSerializableVariablesOnly && !variables[i].isSerializable )
1507-
continue;
1508-
15091489
try
15101490
{
15111491
object variableValue = variables[i].Get( referenceNode.nodeObject );
@@ -1603,126 +1583,107 @@ private VariableGetterHolder[] GetFilteredVariablesForType( Type type )
16031583

16041584
validVariables.Clear();
16051585

1606-
// Filter the fields
1607-
if( fieldModifiers != ( BindingFlags.Instance | BindingFlags.DeclaredOnly ) )
1586+
Type currType = type;
1587+
while( currType != typeof( object ) )
16081588
{
1609-
Type currType = type;
1610-
while( currType != typeof( object ) )
1589+
foreach (FieldInfo field in currType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
16111590
{
1612-
FieldInfo[] fields = currType.GetFields( fieldModifiers );
1613-
for( int i = 0; i < fields.Length; i++ )
1614-
{
1615-
FieldInfo field = fields[i];
1616-
1617-
// Skip obsolete fields
1618-
if( Attribute.IsDefined( field, typeof( ObsoleteAttribute ) ) )
1619-
continue;
1620-
1621-
// Skip primitive types
1622-
if( field.FieldType.IsIgnoredUnityType() )
1623-
continue;
1591+
// Skip obsolete fields
1592+
if( Attribute.IsDefined( field, typeof( ObsoleteAttribute ) ) )
1593+
continue;
16241594

1625-
// "ref struct"s can't be accessed via reflection
1626-
if( field.FieldType.IsByRefLike )
1627-
continue;
1595+
// Skip primitive types
1596+
if( field.FieldType.IsIgnoredUnityType() )
1597+
continue;
16281598

1629-
// Additional filtering for fields:
1630-
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
1631-
string fieldName = field.Name;
1632-
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
1633-
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
1634-
continue;
1599+
// "ref struct"s can't be accessed via reflection
1600+
if( field.FieldType.IsByRefLike )
1601+
continue;
16351602

1636-
VariableGetVal getter = field.CreateGetter( type );
1637-
if( getter != null )
1638-
validVariables.Add( new VariableGetterHolder( field, getter, searchSerializableVariablesOnly ? field.IsSerializable() : true ) );
1639-
}
1603+
// Additional filtering for fields:
1604+
// 1- Ignore "m_RectTransform", "m_CanvasRenderer" and "m_Canvas" fields of Graphic components
1605+
string fieldName = field.Name;
1606+
if( typeof( Graphic ).IsAssignableFrom( currType ) &&
1607+
( fieldName == "m_RectTransform" || fieldName == "m_CanvasRenderer" || fieldName == "m_Canvas" ) )
1608+
continue;
16401609

1641-
currType = currType.BaseType;
1610+
VariableGetVal getter = field.CreateGetter( type );
1611+
if (getter != null)
1612+
validVariables.Add(new VariableGetterHolder(field, getter));
16421613
}
1643-
}
16441614

1645-
if( propertyModifiers != ( BindingFlags.Instance | BindingFlags.DeclaredOnly ) )
1646-
{
1647-
Type currType = type;
1648-
while( currType != typeof( object ) )
1615+
foreach (PropertyInfo property in currType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
16491616
{
1650-
PropertyInfo[] properties = currType.GetProperties( propertyModifiers );
1651-
for( int i = 0; i < properties.Length; i++ )
1652-
{
1653-
PropertyInfo property = properties[i];
1654-
1655-
// Skip obsolete properties
1656-
if( Attribute.IsDefined( property, typeof( ObsoleteAttribute ) ) )
1657-
continue;
1617+
// Skip obsolete properties
1618+
if( Attribute.IsDefined( property, typeof( ObsoleteAttribute ) ) )
1619+
continue;
16581620

1659-
// Skip primitive types
1660-
if( property.PropertyType.IsIgnoredUnityType() )
1661-
continue;
1621+
// Skip primitive types
1622+
if( property.PropertyType.IsIgnoredUnityType() )
1623+
continue;
16621624

1663-
// "ref struct"s can't be accessed via reflection
1664-
if( property.PropertyType.IsByRefLike )
1665-
continue;
1625+
// "ref struct"s can't be accessed via reflection
1626+
if( property.PropertyType.IsByRefLike )
1627+
continue;
16661628

1667-
// Skip properties without a getter function
1668-
MethodInfo propertyGetter = property.GetGetMethod( true );
1669-
if( propertyGetter == null )
1670-
continue;
1629+
// Skip properties without a getter function
1630+
MethodInfo propertyGetter = property.GetGetMethod( true );
1631+
if( propertyGetter == null )
1632+
continue;
16711633

1672-
// Skip indexer properties
1673-
if( property.GetIndexParameters().Length > 0 )
1674-
continue;
1634+
// Skip indexer properties
1635+
if( property.GetIndexParameters().Length > 0 )
1636+
continue;
16751637

1676-
// No need to check properties with 'override' keyword
1677-
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
1678-
continue;
1638+
// No need to check properties with 'override' keyword
1639+
if( propertyGetter.GetBaseDefinition().DeclaringType != propertyGetter.DeclaringType )
1640+
continue;
16791641

1680-
string propertyName = property.Name;
1642+
string propertyName = property.Name;
16811643

1682-
// Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of components to get more useful results
1683-
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
1684-
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
1685-
continue;
1686-
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
1687-
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
1688-
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
1689-
continue;
1690-
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
1691-
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
1692-
continue;
1693-
// Same as above
1694-
else if( ( propertyName == "material" || propertyName == "materials" ) &&
1695-
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
1696-
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
1697-
continue;
1698-
// Ignore certain Material properties that are already searched via SearchMaterial function (also, if a material doesn't have a _Color or _BaseColor
1699-
// property and its "color" property is called, it logs an error to the console, so this rule helps avoid that scenario, as well)
1700-
else if( ( propertyName == "color" || propertyName == "mainTexture" ) && typeof( Material ).IsAssignableFrom( currType ) )
1701-
continue;
1702-
// Ignore "parameters" property of Animator since it doesn't contain any useful data and logs a warning to the console when Animator is inactive
1703-
else if( typeof( Animator ).IsAssignableFrom( currType ) && propertyName == "parameters" )
1704-
continue;
1705-
// Ignore "spriteAnimator" property of TMP_Text component because this property adds a TMP_SpriteAnimator component to the object if it doesn't exist
1706-
else if( propertyName == "spriteAnimator" && currType.Name == "TMP_Text" )
1707-
continue;
1708-
// Ignore "meshFilter" property of TextMeshPro and TMP_SubMesh components because this property adds a MeshFilter component to the object if it doesn't exist
1709-
else if( propertyName == "meshFilter" && ( currType.Name == "TextMeshPro" || currType.Name == "TMP_SubMesh" ) )
1710-
continue;
1711-
// Ignore "users" property of TerrainData because it returns the Terrains in the scene that use that TerrainData. This causes issues with callStack because TerrainData
1712-
// is already in callStack when Terrains are searched via "users" property of it and hence, Terrain->TerrainData references for that TerrainData can't be found in scenes
1713-
// (this is how callStack works, it prevents searching an object if it's already in callStack to avoid infinite recursion)
1714-
else if( propertyName == "users" && typeof( TerrainData ).IsAssignableFrom( currType ) )
1715-
continue;
1716-
else
1717-
{
1718-
VariableGetVal getter = property.CreateGetter();
1719-
if( getter != null )
1720-
validVariables.Add( new VariableGetterHolder( property, getter, searchSerializableVariablesOnly ? property.IsSerializable() : true ) );
1721-
}
1644+
// Ignore "gameObject", "transform", "rectTransform" and "attachedRigidbody" properties of components to get more useful results
1645+
if( typeof( Component ).IsAssignableFrom( currType ) && ( propertyName == "gameObject" ||
1646+
propertyName == "transform" || propertyName == "attachedRigidbody" || propertyName == "rectTransform" ) )
1647+
continue;
1648+
// Ignore "canvasRenderer" and "canvas" properties of Graphic components to get more useful results
1649+
else if( typeof( Graphic ).IsAssignableFrom( currType ) &&
1650+
( propertyName == "canvasRenderer" || propertyName == "canvas" ) )
1651+
continue;
1652+
// Prevent accessing properties of Unity that instantiate an existing resource (causing memory leak)
1653+
else if( typeof( MeshFilter ).IsAssignableFrom( currType ) && propertyName == "mesh" )
1654+
continue;
1655+
// Same as above
1656+
else if( ( propertyName == "material" || propertyName == "materials" ) &&
1657+
( typeof( Renderer ).IsAssignableFrom( currType ) || typeof( Collider ).IsAssignableFrom( currType ) ||
1658+
typeof( Collider2D ).IsAssignableFrom( currType ) ) )
1659+
continue;
1660+
// Ignore certain Material properties that are already searched via SearchMaterial function (also, if a material doesn't have a _Color or _BaseColor
1661+
// property and its "color" property is called, it logs an error to the console, so this rule helps avoid that scenario, as well)
1662+
else if( ( propertyName == "color" || propertyName == "mainTexture" ) && typeof( Material ).IsAssignableFrom( currType ) )
1663+
continue;
1664+
// Ignore "parameters" property of Animator since it doesn't contain any useful data and logs a warning to the console when Animator is inactive
1665+
else if( typeof( Animator ).IsAssignableFrom( currType ) && propertyName == "parameters" )
1666+
continue;
1667+
// Ignore "spriteAnimator" property of TMP_Text component because this property adds a TMP_SpriteAnimator component to the object if it doesn't exist
1668+
else if( propertyName == "spriteAnimator" && currType.Name == "TMP_Text" )
1669+
continue;
1670+
// Ignore "meshFilter" property of TextMeshPro and TMP_SubMesh components because this property adds a MeshFilter component to the object if it doesn't exist
1671+
else if( propertyName == "meshFilter" && ( currType.Name == "TextMeshPro" || currType.Name == "TMP_SubMesh" ) )
1672+
continue;
1673+
// Ignore "users" property of TerrainData because it returns the Terrains in the scene that use that TerrainData. This causes issues with callStack because TerrainData
1674+
// is already in callStack when Terrains are searched via "users" property of it and hence, Terrain->TerrainData references for that TerrainData can't be found in scenes
1675+
// (this is how callStack works, it prevents searching an object if it's already in callStack to avoid infinite recursion)
1676+
else if( propertyName == "users" && typeof( TerrainData ).IsAssignableFrom( currType ) )
1677+
continue;
1678+
else
1679+
{
1680+
VariableGetVal getter = property.CreateGetter();
1681+
if (getter != null)
1682+
validVariables.Add(new VariableGetterHolder(property, getter));
17221683
}
1723-
1724-
currType = currType.BaseType;
17251684
}
1685+
1686+
currType = currType.BaseType;
17261687
}
17271688

17281689
result = validVariables.ToArray();

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ private enum WindowFilter { AlwaysReturnActive, ReturnActiveIfNotLocked, AlwaysR
1818
private const string PREFS_SEARCH_ASSETS = "AUD_AssetsSearch";
1919
private const string PREFS_SEARCH_PROJECT_SETTINGS = "AUD_ProjectSettingsSearch";
2020
private const string PREFS_DONT_SEARCH_SOURCE_ASSETS = "AUD_AssetsExcludeSrc";
21-
private const string PREFS_SEARCH_DEPTH_LIMIT = "AUD_Depth";
22-
private const string PREFS_SEARCH_FIELDS = "AUD_Fields";
23-
private const string PREFS_SEARCH_PROPERTIES = "AUD_Properties";
24-
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
2521
private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps";
2622
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
2723
#if ASSET_USAGE_ADDRESSABLES
@@ -86,13 +82,10 @@ private bool IsLocked
8682
private List<Object> excludedAssets = new List<Object>() { null }; // These assets won't be searched for references
8783
private List<Object> excludedScenes = new List<Object>() { null }; // These scenes won't be searched for references
8884

89-
private int searchDepthLimit = 4; // Depth limit for recursively searching variables of objects
90-
9185
private bool lazySceneSearch = true;
9286
#if ASSET_USAGE_ADDRESSABLES
9387
private bool addressablesSupport = false;
9488
#endif
95-
private bool searchNonSerializableVariables = true;
9689
private bool searchUnusedMaterialProperties = true;
9790
private bool calculateUnusedObjects = false;
9891
private bool hideDuplicateRows = true;
@@ -101,8 +94,6 @@ private bool IsLocked
10194
private bool noAssetDatabaseChanges = false;
10295
private bool showDetailedProgressBar = true;
10396

104-
private BindingFlags fieldModifiers, propertyModifiers;
105-
10697
private SearchRefactoring searchRefactoring = null; // Its value can be assigned via ShowAndSearch
10798

10899
private readonly ObjectToSearchListDrawer objectsToSearchDrawer = new ObjectToSearchListDrawer();
@@ -293,10 +284,6 @@ private void ShowAndSearchInternal( IEnumerable<Object> searchObjects, AssetUsag
293284
searchInAssetsFolder = searchParameters.searchInAssetsFolder;
294285
dontSearchInSourceAssets = searchParameters.dontSearchInSourceAssets;
295286
searchInProjectSettings = searchParameters.searchInProjectSettings;
296-
searchDepthLimit = searchParameters.searchDepthLimit;
297-
fieldModifiers = searchParameters.fieldModifiers;
298-
propertyModifiers = searchParameters.propertyModifiers;
299-
searchNonSerializableVariables = searchParameters.searchNonSerializableVariables;
300287
searchUnusedMaterialProperties = searchParameters.searchUnusedMaterialProperties;
301288
searchRefactoring = searchParameters.searchRefactoring;
302289
lazySceneSearch = searchParameters.lazySceneSearch;
@@ -373,10 +360,6 @@ private void SavePrefs()
373360
EditorPrefs.SetBool( PREFS_SEARCH_ASSETS, searchInAssetsFolder );
374361
EditorPrefs.SetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, dontSearchInSourceAssets );
375362
EditorPrefs.SetBool( PREFS_SEARCH_PROJECT_SETTINGS, searchInProjectSettings );
376-
EditorPrefs.SetInt( PREFS_SEARCH_DEPTH_LIMIT, searchDepthLimit );
377-
EditorPrefs.SetInt( PREFS_SEARCH_FIELDS, (int) fieldModifiers );
378-
EditorPrefs.SetInt( PREFS_SEARCH_PROPERTIES, (int) propertyModifiers );
379-
EditorPrefs.SetBool( PREFS_SEARCH_NON_SERIALIZABLES, searchNonSerializableVariables );
380363
EditorPrefs.SetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, searchUnusedMaterialProperties );
381364
EditorPrefs.SetBool( PREFS_LAZY_SCENE_SEARCH, lazySceneSearch );
382365
#if ASSET_USAGE_ADDRESSABLES
@@ -396,10 +379,6 @@ private void LoadPrefs()
396379
searchInAssetsFolder = EditorPrefs.GetBool( PREFS_SEARCH_ASSETS, true );
397380
dontSearchInSourceAssets = EditorPrefs.GetBool( PREFS_DONT_SEARCH_SOURCE_ASSETS, true );
398381
searchInProjectSettings = EditorPrefs.GetBool( PREFS_SEARCH_PROJECT_SETTINGS, true );
399-
searchDepthLimit = EditorPrefs.GetInt( PREFS_SEARCH_DEPTH_LIMIT, 4 );
400-
fieldModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_FIELDS, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
401-
propertyModifiers = (BindingFlags) EditorPrefs.GetInt( PREFS_SEARCH_PROPERTIES, (int) ( BindingFlags.Public | BindingFlags.NonPublic ) );
402-
searchNonSerializableVariables = EditorPrefs.GetBool( PREFS_SEARCH_NON_SERIALIZABLES, true );
403382
searchUnusedMaterialProperties = EditorPrefs.GetBool( PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES, true );
404383
lazySceneSearch = EditorPrefs.GetBool( PREFS_LAZY_SCENE_SEARCH, true );
405384
#if ASSET_USAGE_ADDRESSABLES
@@ -681,10 +660,6 @@ private void InitiateSearch()
681660
dontSearchInSourceAssets = dontSearchInSourceAssets,
682661
excludedScenesFromSearch = !excludedScenes.IsEmpty() ? excludedScenes.ToArray() : null,
683662
searchInProjectSettings = searchInProjectSettings,
684-
//fieldModifiers = fieldModifiers,
685-
//propertyModifiers = propertyModifiers,
686-
//searchDepthLimit = searchDepthLimit,
687-
//searchNonSerializableVariables = searchNonSerializableVariables,
688663
searchUnusedMaterialProperties = searchUnusedMaterialProperties,
689664
searchRefactoring = searchRefactoring,
690665
#if ASSET_USAGE_ADDRESSABLES

Plugins/AssetUsageDetector/Editor/SearchRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected override bool ChangeValue( Object newValue, out bool setContextDirty )
266266

267267
for( int i = 0; i < MonoScriptAllVariables.Length; i++ )
268268
{
269-
if( MonoScriptAllVariables[i].isSerializable && !MonoScriptAllVariables[i].IsProperty )
269+
if (!MonoScriptAllVariables[i].IsProperty)
270270
{
271271
Object variableDefaultValue = monoImporter.GetDefaultReference( MonoScriptAllVariables[i].Name );
272272
if( variableDefaultValue == Value && MonoScriptAllVariables[i].Name == Variable )

0 commit comments

Comments
 (0)