Skip to content

Commit 9fddcab

Browse files
committed
Added 'Hide unused sub-assets in "Unused Objects" list if their parent assets are used' option to Settings (closed #39)
1 parent 66dd667 commit 9fddcab

6 files changed

Lines changed: 38 additions & 21 deletions

File tree

Plugins/AssetUsageDetector/Editor/AssetUsageDetector.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,19 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
711711
continue;
712712

713713
string assetPath = AssetDatabase.GetAssetPath( obj );
714+
715+
// Omit unused sub-assets whose parent assets are used (configurable via Settings)
716+
if( AssetUsageDetectorSettings.MarkUsedAssetsSubAssetsAsUsed && AssetDatabase.IsSubAsset( obj ) && usedObjectsSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
717+
continue;
718+
719+
// Omit meshes of an imported model asset
720+
if( obj is Mesh && !string.IsNullOrEmpty( assetPath ) && AssetDatabase.GetMainAssetTypeAtPath( assetPath ) == typeof( GameObject ) && objectsToSearchSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
721+
continue;
722+
723+
// Omit MonoScripts whose types can't be determined
724+
if( obj is MonoScript && ( (MonoScript) obj ).GetClass() == null )
725+
continue;
726+
714727
GameObject searchedTopmostGameObject = null;
715728
if( obj is GameObject )
716729
{
@@ -738,14 +751,6 @@ private void CalculateUnusedObjects( List<SearchResultGroup> searchResult, out H
738751
continue;
739752
}
740753

741-
// Omit meshes of an imported model asset
742-
if( obj is Mesh && !string.IsNullOrEmpty( assetPath ) && AssetDatabase.GetMainAssetTypeAtPath( assetPath ) == typeof( GameObject ) && objectsToSearchSet.Contains( AssetDatabase.LoadMainAssetAtPath( assetPath ) ) )
743-
continue;
744-
745-
// Omit MonoScripts whose types can't be determined
746-
if( obj is MonoScript && ( (MonoScript) obj ).GetClass() == null )
747-
continue;
748-
749754
// 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
750755
// (i.e. we don't use actual ReferenceNodes of these objects (GetReferenceNode) because these may have links to other nodes in unknown circumstances)
751756
ReferenceNode node = PopReferenceNode( obj );

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSettings.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ public static bool SelectDoubleClickedObjects
124124
set { if( m_selectDoubleClickedObjects == value ) return; m_selectDoubleClickedObjects = value; EditorPrefs.SetBool( "AUD_SelectDoubleClickedObj", value ); }
125125
}
126126

127+
private static bool? m_markUsedAssetsSubAssetsAsUsed = null;
128+
public static bool MarkUsedAssetsSubAssetsAsUsed
129+
{
130+
get { if( m_markUsedAssetsSubAssetsAsUsed == null ) m_markUsedAssetsSubAssetsAsUsed = EditorPrefs.GetBool( "AUD_MarkUsedAssetsSubAssetsAsUsed", true ); return m_markUsedAssetsSubAssetsAsUsed.Value; }
131+
set { if( m_markUsedAssetsSubAssetsAsUsed == value ) return; m_markUsedAssetsSubAssetsAsUsed = value; EditorPrefs.SetBool( "AUD_MarkUsedAssetsSubAssetsAsUsed", value ); }
132+
}
133+
127134
private static bool? m_showUnityTooltip = null;
128135
public static bool ShowUnityTooltip
129136
{
@@ -186,20 +193,22 @@ public static void PreferencesGUI()
186193

187194
EditorGUI.BeginChangeCheck();
188195

189-
EditorGUIUtility.labelWidth += 140f;
190-
ShowRootAssetName = EditorGUILayout.Toggle( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
191-
EditorGUIUtility.labelWidth -= 140f;
196+
ShowRootAssetName = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
197+
198+
EditorGUILayout.Space();
199+
200+
PingClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Ping Clicked Objects", PingClickedObjects );
201+
SelectClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Clicked Objects", SelectClickedObjects );
202+
SelectDoubleClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Double Clicked Objects", SelectDoubleClickedObjects );
192203

193204
EditorGUILayout.Space();
194205

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

199208
EditorGUILayout.Space();
200209

201-
ShowUnityTooltip = EditorGUILayout.Toggle( "Show Unity Tooltip", ShowUnityTooltip );
202-
ShowCustomTooltip = EditorGUILayout.Toggle( "Show Custom Tooltip", ShowCustomTooltip );
210+
ShowUnityTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Unity Tooltip", ShowUnityTooltip );
211+
ShowCustomTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Custom Tooltip", ShowCustomTooltip );
203212
EditorGUI.indentLevel++;
204213
CustomTooltipDelay = FloatField( "Delay", CustomTooltipDelay, 0.7f );
205214
EditorGUI.indentLevel--;
@@ -223,7 +232,7 @@ public static void PreferencesGUI()
223232
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 ) );
224233
SearchMatchingTextColor = ColorField( "Matching Search Text Color", SearchMatchingTextColor, Color.red );
225234

226-
ShowTreeLines = EditorGUILayout.Toggle( "Show Tree Lines", ShowTreeLines );
235+
ShowTreeLines = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Tree Lines", ShowTreeLines );
227236
EditorGUI.indentLevel++;
228237
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 ) );
229238
HighlightedTreeLinesColor = ColorField( "Highlighted Color", HighlightedTreeLinesColor, Color.cyan );

Plugins/AssetUsageDetector/Editor/AssetUsageDetectorWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private enum WindowFilter { AlwaysReturnActive, ReturnActiveIfNotLocked, AlwaysR
4141
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
4242
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f );
4343

44-
private readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );
44+
private static readonly GUILayoutOption GL_WIDTH_12 = GUILayout.Width( 12f );
4545

4646
private GUIStyle lockButtonStyle;
4747

@@ -674,7 +674,7 @@ private void DrawObjectsToSearchSection()
674674
objectsToSearchDrawer.Draw( objectsToSearch );
675675
}
676676

677-
private bool WordWrappingToggleLeft( string label, bool value )
677+
public static bool WordWrappingToggleLeft( string label, bool value )
678678
{
679679
GUILayout.BeginHorizontal();
680680
bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 );

Plugins/AssetUsageDetector/Editor/SearchResult.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ public float DrawOnGUI( SearchResult searchResult, EditorWindow window, float sc
863863
if( searchResult != null && searchResult.SearchParameters.dontSearchInSourceAssets && searchResult.SearchParameters.objectsToSearch.Length > 1 )
864864
EditorGUILayout.HelpBox( "'Don't search \"SEARCHED OBJECTS\" themselves for references' is enabled, some of these objects might be used by \"SEARCHED OBJECTS\".", MessageType.Warning );
865865

866+
if( !AssetUsageDetectorSettings.MarkUsedAssetsSubAssetsAsUsed )
867+
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 );
868+
866869
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 );
867870
}
868871

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Asset Usage Detector (v2.5.2) =
1+
= Asset Usage Detector (v2.5.3) =
22

33
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
44
E-mail: yasirkula@gmail.com

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.assetusagedetector",
33
"displayName": "Asset Usage Detector",
4-
"version": "2.5.2",
4+
"version": "2.5.3",
55
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
66
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)