Skip to content

Commit

Permalink
Added 'Hide unused sub-assets in "Unused Objects" list if their paren…
Browse files Browse the repository at this point in the history
…t assets are used' option to Settings (closed #39)
  • Loading branch information
yasirkula committed Aug 4, 2024
1 parent 66dd667 commit 9fddcab
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
21 changes: 13 additions & 8 deletions Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,19 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
continue;

string assetPath = AssetDatabase.GetAssetPath( obj );

// Omit unused sub-assets whose parent assets are used (configurable via Settings)
if( AssetUsageDetectorSettings.MarkUsedAssetsSubAssetsAsUsed && AssetDatabase.IsSubAsset( obj ) && usedObjectsSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
continue;

// Omit meshes of an imported model asset
if( obj is Mesh && !string.IsNullOrEmpty( assetPath ) && AssetDatabase.GetMainAssetTypeAtPath( assetPath ) == typeof( GameObject ) && objectsToSearchSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
continue;

// Omit MonoScripts whose types can't be determined
if( obj is MonoScript && ( (MonoScript) obj ).GetClass() == null )
continue;

GameObject searchedTopmostGameObject = null;
if( obj is GameObject )
{
Expand Down Expand Up @@ -738,14 +751,6 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
continue;
}

// Omit meshes of an imported model asset
if( obj is Mesh && !string.IsNullOrEmpty( assetPath ) && AssetDatabase.GetMainAssetTypeAtPath( assetPath ) == typeof( GameObject ) && objectsToSearchSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
continue;

// Omit MonoScripts whose types can't be determined
if( obj is MonoScript && ( (MonoScript) obj ).GetClass() == null )
continue;

// Use new ReferenceNodes in UnusedObjects search result group because we don't want these nodes to be linked to the actual ReferenceNodes in any way
// (i.e. we don't use actual ReferenceNodes of these objects (GetReferenceNode) because these may have links to other nodes in unknown circumstances)
ReferenceNode node = PopReferenceNode( obj );
Expand Down
27 changes: 18 additions & 9 deletions Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ public static bool SelectDoubleClickedObjects
set { if( m_selectDoubleClickedObjects == value ) return; m_selectDoubleClickedObjects = value; EditorPrefs.SetBool( "AUD_SelectDoubleClickedObj", value ); }
}

private static bool? m_markUsedAssetsSubAssetsAsUsed = null;
public static bool MarkUsedAssetsSubAssetsAsUsed
{
get { if( m_markUsedAssetsSubAssetsAsUsed == null ) m_markUsedAssetsSubAssetsAsUsed = EditorPrefs.GetBool( "AUD_MarkUsedAssetsSubAssetsAsUsed", true ); return m_markUsedAssetsSubAssetsAsUsed.Value; }
set { if( m_markUsedAssetsSubAssetsAsUsed == value ) return; m_markUsedAssetsSubAssetsAsUsed = value; EditorPrefs.SetBool( "AUD_MarkUsedAssetsSubAssetsAsUsed", value ); }
}

private static bool? m_showUnityTooltip = null;
public static bool ShowUnityTooltip
{
Expand Down Expand Up @@ -186,20 +193,22 @@ public static void PreferencesGUI()

EditorGUI.BeginChangeCheck();

EditorGUIUtility.labelWidth += 140f;
ShowRootAssetName = EditorGUILayout.Toggle( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
EditorGUIUtility.labelWidth -= 140f;
ShowRootAssetName = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );

EditorGUILayout.Space();

PingClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Ping Clicked Objects", PingClickedObjects );
SelectClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Clicked Objects", SelectClickedObjects );
SelectDoubleClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Double Clicked Objects", SelectDoubleClickedObjects );

EditorGUILayout.Space();

PingClickedObjects = EditorGUILayout.Toggle( "Ping Clicked Objects", PingClickedObjects );
SelectClickedObjects = EditorGUILayout.Toggle( "Select Clicked Objects", SelectClickedObjects );
SelectDoubleClickedObjects = EditorGUILayout.Toggle( "Select Double Clicked Objects", SelectDoubleClickedObjects );
MarkUsedAssetsSubAssetsAsUsed = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Hide unused sub-assets in \"Unused Objects\" list if their parent assets are used (Requires Refresh)", MarkUsedAssetsSubAssetsAsUsed );

EditorGUILayout.Space();

ShowUnityTooltip = EditorGUILayout.Toggle( "Show Unity Tooltip", ShowUnityTooltip );
ShowCustomTooltip = EditorGUILayout.Toggle( "Show Custom Tooltip", ShowCustomTooltip );
ShowUnityTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Unity Tooltip", ShowUnityTooltip );
ShowCustomTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Custom Tooltip", ShowCustomTooltip );
EditorGUI.indentLevel++;
CustomTooltipDelay = FloatField( "Delay", CustomTooltipDelay, 0.7f );
EditorGUI.indentLevel--;
Expand All @@ -223,7 +232,7 @@ public static void PreferencesGUI()
SelectedRowOccurrencesColor = ColorField( "Selected Row All Occurrences Tint", SelectedRowOccurrencesColor, EditorGUIUtility.isProSkin ? new Color( 0f, 0.3f, 0.75f, 1f ) : new Color( 0.25f, 0.75f, 1f, 1f ) );
SearchMatchingTextColor = ColorField( "Matching Search Text Color", SearchMatchingTextColor, Color.red );

ShowTreeLines = EditorGUILayout.Toggle( "Show Tree Lines", ShowTreeLines );
ShowTreeLines = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Tree Lines", ShowTreeLines );
EditorGUI.indentLevel++;
TreeLinesColor = ColorField( "Normal Color", TreeLinesColor, EditorGUIUtility.isProSkin ? new Color( 0.65f, 0.65f, 0.65f, 1f ) : new Color( 0.375f, 0.375f, 0.375f, 1f ) );
HighlightedTreeLinesColor = ColorField( "Highlighted Color", HighlightedTreeLinesColor, Color.cyan );
Expand Down
4 changes: 2 additions & 2 deletions Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private enum WindowFilter { AlwaysReturnActive, ReturnActiveIfNotLocked, AlwaysR
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f );

private readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );
private static readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );

private GUIStyle lockButtonStyle;

Expand Down Expand Up @@ -674,7 +674,7 @@ private void DrawObjectsToSearchSection()
objectsToSearchDrawer.Draw( objectsToSearch );
}

private bool WordWrappingToggleLeft( string label, bool value )
public static bool WordWrappingToggleLeft( string label, bool value )
{
GUILayout.BeginHorizontal();
bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 );
Expand Down
3 changes: 3 additions & 0 deletions Plugins/AssetUsageDetector/Editor/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,9 @@ public float DrawOnGUI( SearchResult searchResult, EditorWindow window, float sc
if( searchResult != null && searchResult.SearchParameters.dontSearchInSourceAssets && searchResult.SearchParameters.objectsToSearch.Length > 1 )
EditorGUILayout.HelpBox( "'Don't search \"SEARCHED OBJECTS\" themselves for references' is enabled, some of these objects might be used by \"SEARCHED OBJECTS\".", MessageType.Warning );

if( !AssetUsageDetectorSettings.MarkUsedAssetsSubAssetsAsUsed )
EditorGUILayout.HelpBox( "'Hide unused sub-assets in \"Unused Objects\" list if their parent assets are used' is disabled, unused sub-assets' parent assets might be used.", MessageType.Warning );

EditorGUILayout.HelpBox( "Although no references to these objects are found, they might still be used somewhere (e.g. via Resources.Load). If you intend to delete these objects, consider creating a backup of your project first.", MessageType.Info );
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/AssetUsageDetector/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Asset Usage Detector (v2.5.2) =
= Asset Usage Detector (v2.5.3) =

Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
E-mail: [email protected]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector",
"version": "2.5.2",
"version": "2.5.3",
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 9fddcab

Please sign in to comment.