Compare commits

...

12 Commits

Author SHA1 Message Date
yasirkula 962f6e04d4 Changed "Hide non-overridden prefab variables" options to "Hide redundant prefab references" which now also apply to C# scripts' and prefab assets' usages (#42) 2024-12-10 19:58:09 +03:00
yasirkula 204de979ba SearchResultGroup's "Hide Search Results" context menu button automatically exits the search 2024-12-10 19:13:58 +03:00
yasirkula 50ce6f56c9 Tiny fix for a switch-case that couldn't be properly auto indentated 2024-12-10 19:05:58 +03:00
yasirkula 0f872ef04d Fix for a tiny warning 2024-12-10 19:04:28 +03:00
yasirkula f68c8a1375 Added AssetUsageDetectorWindow.BeginIndentedGUI and EndIndentedGUI functions to reduce duplicate OnGUI code 2024-12-10 19:04:04 +03:00
yasirkula ecfb1adf88 Added Utilities.DrawHeader function to reduce duplicate OnGUI code 2024-12-10 19:01:23 +03:00
yasirkula e63ebd7f85 Simplifications in Utilities.IsEmpty 2024-12-10 18:59:28 +03:00
yasirkula d5b082c093 Added "Hide Search Results" to search result groups' context menu if their search results are filtered via a search term (i.e. text filtering). For example, you can filter search results with term "[Prefab object]" and then right click the group and select this option to hide all prefab instance occurrences in that group 2024-11-03 12:52:18 +03:00
yasirkula 1faa789f48 Removed an unused variable 2024-11-02 14:56:30 +03:00
yasirkula 610fffc763 Added "Hide non-overridden prefab variables in scenes" setting (closed #42) + Renamed "Hide redundant prefab variant links" to "Hide non-overridden prefab variables in assets" 2024-11-02 14:55:40 +03:00
yasirkula 9fddcab6fa Added 'Hide unused sub-assets in "Unused Objects" list if their parent assets are used' option to Settings (closed #39) 2024-08-04 13:24:44 +03:00
yasirkula 66dd66787c Fixed NullReferenceException on newest Unity versions if VFX Graph package is installed 2024-05-12 13:02:28 +03:00
9 changed files with 308 additions and 132 deletions
@@ -53,7 +53,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
public bool calculateUnusedObjects = false; public bool calculateUnusedObjects = false;
public bool hideDuplicateRows = true; public bool hideDuplicateRows = true;
public bool hideReduntantPrefabVariantLinks = true; public bool hideRedundantPrefabReferencesInAssets = false;
public bool hideRedundantPrefabReferencesInScenes = false;
public bool noAssetDatabaseChanges = false; public bool noAssetDatabaseChanges = false;
public bool showDetailedProgressBar = true; public bool showDetailedProgressBar = true;
} }
@@ -453,7 +454,7 @@ namespace AssetUsageDetectorNamespace
} }
// If a reference is found in the Project view, save the results // If a reference is found in the Project view, save the results
if( currentSearchResultGroup.NumberOfReferences > 0 ) if( currentSearchResultGroup.AnyReferencesFound )
searchResult.Add( currentSearchResultGroup ); searchResult.Add( currentSearchResultGroup );
} }
@@ -478,7 +479,7 @@ namespace AssetUsageDetectorNamespace
} }
} }
if( currentSearchResultGroup.NumberOfReferences > 0 ) if( currentSearchResultGroup.AnyReferencesFound )
searchResult.Add( currentSearchResultGroup ); searchResult.Add( currentSearchResultGroup );
} }
@@ -553,7 +554,7 @@ namespace AssetUsageDetectorNamespace
for( int i = 0; i < rootGameObjects.Length; i++ ) for( int i = 0; i < rootGameObjects.Length; i++ )
SearchGameObjectRecursively( rootGameObjects[i] ); SearchGameObjectRecursively( rootGameObjects[i] );
if( currentSearchResultGroup.NumberOfReferences > 0 ) if( currentSearchResultGroup.AnyReferencesFound )
searchResult.Add( currentSearchResultGroup ); searchResult.Add( currentSearchResultGroup );
} }
@@ -662,7 +663,7 @@ namespace AssetUsageDetectorNamespace
searchResult[i].InitializeNodes( objectsToSearchSet ); searchResult[i].InitializeNodes( objectsToSearchSet );
// Remove empty search result groups // Remove empty search result groups
if( !searchResult[i].PendingSearch && searchResult[i].NumberOfReferences == 0 ) if( !searchResult[i].PendingSearch && !searchResult[i].AnyReferencesFound )
searchResult.RemoveAt( i-- ); searchResult.RemoveAt( i-- );
} }
} }
@@ -711,6 +712,19 @@ namespace AssetUsageDetectorNamespace
continue; continue;
string assetPath = AssetDatabase.GetAssetPath( obj ); 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; GameObject searchedTopmostGameObject = null;
if( obj is GameObject ) if( obj is GameObject )
{ {
@@ -738,14 +752,6 @@ namespace AssetUsageDetectorNamespace
continue; 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 // 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) // (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 ); ReferenceNode node = PopReferenceNode( obj );
@@ -976,11 +982,9 @@ namespace AssetUsageDetectorNamespace
EditorSceneManager.CloseScene( scene, true ); EditorSceneManager.CloseScene( scene, true );
} }
} }
else
{ if( currentSearchResultGroup.AnyReferencesFound )
// Some references are found in this scene, save the results
searchResult.Add( currentSearchResultGroup ); searchResult.Add( currentSearchResultGroup );
}
} }
// Search a GameObject and its children for references recursively // Search a GameObject and its children for references recursively
@@ -217,8 +217,9 @@ namespace AssetUsageDetectorNamespace
#endif #endif
#if ASSET_USAGE_VFX_GRAPH #if ASSET_USAGE_VFX_GRAPH
private readonly Func<string, object> vfxResourceGetter = (Func<string, object>) Delegate.CreateDelegate( typeof( Func<string, object> ), typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ).GetMethod( "GetResourceAtPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) ); private static Type vfxResourceType => typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ) ?? Array.Find( AppDomain.CurrentDomain.GetAssemblies(), ( assembly ) => assembly.GetName().Name == "UnityEditor.VFXModule" ).GetType( "UnityEditor.VFX.VisualEffectResource" );
private readonly MethodInfo vfxResourceContentsGetter = typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ).GetMethod( "GetContents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ); private readonly Func<string, object> vfxResourceGetter = (Func<string, object>) Delegate.CreateDelegate( typeof( Func<string, object> ), vfxResourceType.GetMethod( "GetResourceAtPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
private readonly MethodInfo vfxResourceContentsGetter = vfxResourceType.GetMethod( "GetContents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
private readonly MethodInfo vfxSerializableObjectValueGetter = Array.Find( Array.Find( AppDomain.CurrentDomain.GetAssemblies(), ( assembly ) => assembly.GetName().Name == "Unity.VisualEffectGraph.Editor" ).GetType( "UnityEditor.VFX.VFXSerializableObject" ).GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ), ( methodInfo ) => methodInfo.Name == "Get" && !methodInfo.IsGenericMethod ); private readonly MethodInfo vfxSerializableObjectValueGetter = Array.Find( Array.Find( AppDomain.CurrentDomain.GetAssemblies(), ( assembly ) => assembly.GetName().Name == "Unity.VisualEffectGraph.Editor" ).GetType( "UnityEditor.VFX.VFXSerializableObject" ).GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance ), ( methodInfo ) => methodInfo.Name == "Get" && !methodInfo.IsGenericMethod );
#endif #endif
@@ -396,16 +397,21 @@ namespace AssetUsageDetectorNamespace
// Check if this GameObject's prefab is one of the selected assets // Check if this GameObject's prefab is one of the selected assets
if( searchPrefabConnections ) if( searchPrefabConnections )
{ {
#if UNITY_2018_3_OR_NEWER bool? skipFurtherPrefabReferences = null;
Object prefab = go; for( GameObject goPrefab = go.GetPrefabParent(), prefab = goPrefab; prefab != null; prefab = prefab.GetPrefabParent() )
while( prefab = PrefabUtility.GetCorrespondingObjectFromSource( prefab ) )
#else
Object prefab = PrefabUtility.GetPrefabParent( go );
if( prefab )
#endif
{ {
if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab as GameObject ) ) if( objectsToSearchSet.Contains( prefab ) && assetsToSearchRootPrefabs.ContainsFast( prefab ) )
{ {
if( goPrefab != prefab && !skipFurtherPrefabReferences.HasValue )
{
skipFurtherPrefabReferences = ShouldExcludeRedundantPrefabReferences( go ) && !go.HasAnyPrefabOverrides();
if( skipFurtherPrefabReferences.Value )
{
currentSearchResultGroup.NumberOfRedundantReferences++;
break;
}
}
referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" ); referenceNode.AddLinkTo( GetReferenceNode( prefab ), "Prefab object" );
if( searchParameters.searchRefactoring != null ) if( searchParameters.searchRefactoring != null )
@@ -439,10 +445,15 @@ namespace AssetUsageDetectorNamespace
MonoScript script = MonoScript.FromMonoBehaviour( (MonoBehaviour) component ); MonoScript script = MonoScript.FromMonoBehaviour( (MonoBehaviour) component );
if( objectsToSearchSet.Contains( script ) ) if( objectsToSearchSet.Contains( script ) )
{ {
referenceNode.AddLinkTo( GetReferenceNode( script ) ); if( ShouldExcludeRedundantPrefabReferences( component ) && !component.HasAnyPrefabOverrides() )
currentSearchResultGroup.NumberOfRedundantReferences++;
else
{
referenceNode.AddLinkTo( GetReferenceNode( script ) );
if( searchParameters.searchRefactoring != null ) if( searchParameters.searchRefactoring != null )
searchParameters.searchRefactoring( new BehaviourUsageMatch( component.gameObject, script, component ) ); searchParameters.searchRefactoring( new BehaviourUsageMatch( component.gameObject, script, component ) );
}
} }
} }
@@ -1451,9 +1462,7 @@ namespace AssetUsageDetectorNamespace
if( iterator.Next( true ) ) if( iterator.Next( true ) )
{ {
bool iteratingVisible = iteratorVisible.NextVisible( true ); bool iteratingVisible = iteratorVisible.NextVisible( true );
#if UNITY_2018_3_OR_NEWER bool searchPrefabOverridesOnly = ShouldExcludeRedundantPrefabReferences( unityObject );
bool searchPrefabOverridesOnly = searchParameters.hideReduntantPrefabVariantLinks && unityObject.IsAsset() && PrefabUtility.GetCorrespondingObjectFromSource( unityObject ) != null;
#endif
bool enterChildren; bool enterChildren;
do do
{ {
@@ -1470,10 +1479,6 @@ namespace AssetUsageDetectorNamespace
if( !isVisible ) if( !isVisible )
enterChildren = false; enterChildren = false;
#if UNITY_2018_3_OR_NEWER
else if( searchPrefabOverridesOnly && !iterator.prefabOverride )
enterChildren = false;
#endif
else else
{ {
Object propertyValue; Object propertyValue;
@@ -1499,6 +1504,7 @@ namespace AssetUsageDetectorNamespace
break; break;
#endif #endif
case SerializedPropertyType.Generic: case SerializedPropertyType.Generic:
{
#if ASSET_USAGE_ADDRESSABLES #if ASSET_USAGE_ADDRESSABLES
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference ) if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference )
{ {
@@ -1525,6 +1531,7 @@ namespace AssetUsageDetectorNamespace
} }
break; break;
}
default: default:
propertyValue = null; propertyValue = null;
searchResult = null; searchResult = null;
@@ -1539,10 +1546,18 @@ namespace AssetUsageDetectorNamespace
// m_RD.texture is a redundant reference that shows up when searching sprites // m_RD.texture is a redundant reference that shows up when searching sprites
if( !propertyPath.EndsWithFast( "m_RD.texture" ) ) if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
{ {
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]" if( searchPrefabOverridesOnly && !iterator.prefabOverride )
{
currentSearchResultGroup.NumberOfRedundantReferences++;
enterChildren = false;
}
else
{
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) ) if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) )
searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) ); searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) );
}
} }
} }
} }
@@ -1921,6 +1936,11 @@ namespace AssetUsageDetectorNamespace
} }
#endif #endif
private bool ShouldExcludeRedundantPrefabReferences( Object obj )
{
return ( ( searchParameters.hideRedundantPrefabReferencesInAssets && obj.IsAsset() ) || ( searchParameters.hideRedundantPrefabReferencesInScenes && !obj.IsAsset() ) ) && obj.GetPrefabParent() != null;
}
// Iterates over all occurrences of specific key-value pairs in string // Iterates over all occurrences of specific key-value pairs in string
// Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar=" // Example1: #include "VALUE" valuePrefix=#include, valueWrapperChar="
// Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar=" // Example2: "guid": "VALUE" valuePrefix="guid", valueWrapperChar="
@@ -124,6 +124,13 @@ namespace AssetUsageDetectorNamespace
set { if( m_selectDoubleClickedObjects == value ) return; m_selectDoubleClickedObjects = value; EditorPrefs.SetBool( "AUD_SelectDoubleClickedObj", value ); } 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; private static bool? m_showUnityTooltip = null;
public static bool ShowUnityTooltip public static bool ShowUnityTooltip
{ {
@@ -186,20 +193,22 @@ namespace AssetUsageDetectorNamespace
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
EditorGUIUtility.labelWidth += 140f; ShowRootAssetName = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
ShowRootAssetName = EditorGUILayout.Toggle( "Show Root Asset's Name For Sub-Assets (Requires Refresh)", ShowRootAssetName );
EditorGUIUtility.labelWidth -= 140f;
EditorGUILayout.Space(); EditorGUILayout.Space();
PingClickedObjects = EditorGUILayout.Toggle( "Ping Clicked Objects", PingClickedObjects ); PingClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Ping Clicked Objects", PingClickedObjects );
SelectClickedObjects = EditorGUILayout.Toggle( "Select Clicked Objects", SelectClickedObjects ); SelectClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Clicked Objects", SelectClickedObjects );
SelectDoubleClickedObjects = EditorGUILayout.Toggle( "Select Double Clicked Objects", SelectDoubleClickedObjects ); SelectDoubleClickedObjects = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Select Double Clicked Objects", SelectDoubleClickedObjects );
EditorGUILayout.Space(); EditorGUILayout.Space();
ShowUnityTooltip = EditorGUILayout.Toggle( "Show Unity Tooltip", ShowUnityTooltip ); MarkUsedAssetsSubAssetsAsUsed = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Hide unused sub-assets in \"Unused Objects\" list if their parent assets are used (Requires Refresh)", MarkUsedAssetsSubAssetsAsUsed );
ShowCustomTooltip = EditorGUILayout.Toggle( "Show Custom Tooltip", ShowCustomTooltip );
EditorGUILayout.Space();
ShowUnityTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Unity Tooltip", ShowUnityTooltip );
ShowCustomTooltip = AssetUsageDetectorWindow.WordWrappingToggleLeft( "Show Custom Tooltip", ShowCustomTooltip );
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
CustomTooltipDelay = FloatField( "Delay", CustomTooltipDelay, 0.7f ); CustomTooltipDelay = FloatField( "Delay", CustomTooltipDelay, 0.7f );
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
@@ -223,7 +232,7 @@ namespace AssetUsageDetectorNamespace
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 ) ); 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 ); 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++; 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 ) ); 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 ); HighlightedTreeLinesColor = ColorField( "Highlighted Color", HighlightedTreeLinesColor, Color.cyan );
@@ -32,16 +32,29 @@ namespace AssetUsageDetectorNamespace
private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables"; private const string PREFS_SEARCH_NON_SERIALIZABLES = "AUD_NonSerializables";
private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps"; private const string PREFS_SEARCH_UNUSED_MATERIAL_PROPERTIES = "AUD_SearchUnusedMaterialProps";
private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch"; private const string PREFS_LAZY_SCENE_SEARCH = "AUD_LazySceneSearch";
#if ASSET_USAGE_ADDRESSABLES
private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport"; private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport";
#endif
private const string PREFS_CALCULATE_UNUSED_OBJECTS = "AUD_FindUnusedObjs"; private const string PREFS_CALCULATE_UNUSED_OBJECTS = "AUD_FindUnusedObjs";
private const string PREFS_HIDE_DUPLICATE_ROWS = "AUD_HideDuplicates"; private const string PREFS_HIDE_DUPLICATE_ROWS = "AUD_HideDuplicates";
private const string PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS = "AUD_HideRedundantPVariantLinks"; private const string PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS = "AUD_HideRedundantPRefsInAssets";
private const string PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES = "AUD_HideRedundantPRefsInScenes";
private const string PREFS_SHOW_PROGRESS = "AUD_Progress"; private const string PREFS_SHOW_PROGRESS = "AUD_Progress";
private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" ); private static readonly GUIContent windowTitle = new GUIContent( "Asset Usage Detector" );
private static readonly Vector2 windowMinSize = new Vector2( 325f, 220f ); 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 static readonly GUIContent sharedGUIContent = new GUIContent();
private readonly GUIContent hideRedundantPrefabReferencesInAssetsLabel = new GUIContent( "Hide redundant prefab references in Assets", "Hides redundant/non-overridden references in prefab variants and nested prefabs. " +
"This will help focus on only the references that actually matter. For example:\n\n" +
"- Material CloudMat is assigned to prefab Cloud and its variant CloudBig. Since changing Cloud's material will also affect CloudBig, search results won't show CloudBig's reference" );
private readonly GUIContent hideRedundantPrefabReferencesInScenesLabel = new GUIContent( "Hide redundant prefab references in Scenes", "Hides redundant/non-overridden references in prefab instances. " +
"This will help focus on only the references that actually matter. For example:\n\n" +
"- Prefab Healthbar is nested inside prefab Player. An instance of Player exists in the current scene and its Healthbar isn't modified. Since modifying Healthbar in Player prefab will also affect " +
"the instance in the scene, search results won't show the instance in the scene while searching for Healthbar's references" );
private GUIStyle lockButtonStyle; private GUIStyle lockButtonStyle;
@@ -93,7 +106,8 @@ namespace AssetUsageDetectorNamespace
private bool searchUnusedMaterialProperties = true; private bool searchUnusedMaterialProperties = true;
private bool calculateUnusedObjects = false; private bool calculateUnusedObjects = false;
private bool hideDuplicateRows = true; private bool hideDuplicateRows = true;
private bool hideReduntantPrefabVariantLinks = true; private bool hideRedundantPrefabReferencesInAssets = false;
private bool hideRedundantPrefabReferencesInScenes = false;
private bool noAssetDatabaseChanges = false; private bool noAssetDatabaseChanges = false;
private bool showDetailedProgressBar = true; private bool showDetailedProgressBar = true;
@@ -331,7 +345,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = searchParameters.calculateUnusedObjects; calculateUnusedObjects = searchParameters.calculateUnusedObjects;
hideDuplicateRows = searchParameters.hideDuplicateRows; hideDuplicateRows = searchParameters.hideDuplicateRows;
hideReduntantPrefabVariantLinks = searchParameters.hideReduntantPrefabVariantLinks; hideRedundantPrefabReferencesInAssets = searchParameters.hideRedundantPrefabReferencesInAssets;
hideRedundantPrefabReferencesInScenes = searchParameters.hideRedundantPrefabReferencesInScenes;
noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges; noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
showDetailedProgressBar = searchParameters.showDetailedProgressBar; showDetailedProgressBar = searchParameters.showDetailedProgressBar;
@@ -414,7 +429,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
EditorPrefs.SetBool( PREFS_CALCULATE_UNUSED_OBJECTS, calculateUnusedObjects ); EditorPrefs.SetBool( PREFS_CALCULATE_UNUSED_OBJECTS, calculateUnusedObjects );
EditorPrefs.SetBool( PREFS_HIDE_DUPLICATE_ROWS, hideDuplicateRows ); EditorPrefs.SetBool( PREFS_HIDE_DUPLICATE_ROWS, hideDuplicateRows );
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, hideReduntantPrefabVariantLinks ); EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS, hideRedundantPrefabReferencesInAssets );
EditorPrefs.SetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES, hideRedundantPrefabReferencesInScenes );
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar ); EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
} }
@@ -436,7 +452,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = EditorPrefs.GetBool( PREFS_CALCULATE_UNUSED_OBJECTS, false ); calculateUnusedObjects = EditorPrefs.GetBool( PREFS_CALCULATE_UNUSED_OBJECTS, false );
hideDuplicateRows = EditorPrefs.GetBool( PREFS_HIDE_DUPLICATE_ROWS, true ); hideDuplicateRows = EditorPrefs.GetBool( PREFS_HIDE_DUPLICATE_ROWS, true );
hideReduntantPrefabVariantLinks = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_VARIANT_LINKS, true ); hideRedundantPrefabReferencesInAssets = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_ASSETS, hideRedundantPrefabReferencesInAssets );
hideRedundantPrefabReferencesInScenes = EditorPrefs.GetBool( PREFS_HIDE_REDUNDANT_PREFAB_REFERENCES_IN_SCENES, hideRedundantPrefabReferencesInScenes );
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true ); showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true );
} }
@@ -497,24 +514,16 @@ namespace AssetUsageDetectorNamespace
GUILayout.Space( 10f ); GUILayout.Space( 10f );
Color c = GUI.backgroundColor; Utilities.DrawHeader( "<b>SEARCH IN</b>" );
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
GUILayout.Box( "<b>SEARCH IN</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.backgroundColor = c;
searchInAssetsFolder = WordWrappingToggleLeft( "Project window (Assets folder)", searchInAssetsFolder ); searchInAssetsFolder = WordWrappingToggleLeft( "Project window (Assets folder)", searchInAssetsFolder );
if( searchInAssetsFolder ) if( searchInAssetsFolder )
{ {
GUILayout.BeginHorizontal(); BeginIndentedGUI();
GUILayout.Space( 35f );
GUILayout.BeginVertical();
searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset ); searchInAssetsSubsetDrawer.Draw( searchInAssetsSubset );
excludedAssetsDrawer.Draw( excludedAssets ); excludedAssetsDrawer.Draw( excludedAssets );
EndIndentedGUI();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
} }
GUILayout.Space( 5f ); GUILayout.Space( 5f );
@@ -535,13 +544,10 @@ namespace AssetUsageDetectorNamespace
if( searchInScenesInBuild ) if( searchInScenesInBuild )
{ {
GUILayout.BeginHorizontal(); BeginIndentedGUI( false );
GUILayout.Space( 35f );
searchInScenesInBuildTickedOnly = EditorGUILayout.ToggleLeft( "Ticked only", searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 ); searchInScenesInBuildTickedOnly = EditorGUILayout.ToggleLeft( "Ticked only", searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
searchInScenesInBuildTickedOnly = !EditorGUILayout.ToggleLeft( "All", !searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 ); searchInScenesInBuildTickedOnly = !EditorGUILayout.ToggleLeft( "All", !searchInScenesInBuildTickedOnly, Utilities.GL_WIDTH_100 );
EndIndentedGUI( false );
GUILayout.EndHorizontal();
} }
GUI.enabled = true; GUI.enabled = true;
@@ -549,14 +555,9 @@ namespace AssetUsageDetectorNamespace
searchInAllScenes = WordWrappingToggleLeft( "All scenes in the project", searchInAllScenes ); searchInAllScenes = WordWrappingToggleLeft( "All scenes in the project", searchInAllScenes );
} }
GUILayout.BeginHorizontal(); BeginIndentedGUI();
GUILayout.Space( 35f );
GUILayout.BeginVertical();
excludedScenesDrawer.Draw( excludedScenes ); excludedScenesDrawer.Draw( excludedScenes );
EndIndentedGUI();
GUILayout.EndVertical();
GUILayout.EndHorizontal();
EditorGUI.BeginDisabledGroup( !searchInOpenScenes && !searchInScenesInBuild && !searchInAllScenes ); EditorGUI.BeginDisabledGroup( !searchInOpenScenes && !searchInScenesInBuild && !searchInAllScenes );
searchInSceneLightingSettings = WordWrappingToggleLeft( "Scene Lighting Settings (WARNING: This may change the active scene during search)", searchInSceneLightingSettings ); searchInSceneLightingSettings = WordWrappingToggleLeft( "Scene Lighting Settings (WARNING: This may change the active scene during search)", searchInSceneLightingSettings );
@@ -568,9 +569,7 @@ namespace AssetUsageDetectorNamespace
GUILayout.Space( 10f ); GUILayout.Space( 10f );
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor; Utilities.DrawHeader( "<b>SETTINGS</b>" );
GUILayout.Box( "<b>SETTINGS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.backgroundColor = c;
#if ASSET_USAGE_ADDRESSABLES #if ASSET_USAGE_ADDRESSABLES
EditorGUI.BeginDisabledGroup( addressablesSupport ); EditorGUI.BeginDisabledGroup( addressablesSupport );
@@ -582,9 +581,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = WordWrappingToggleLeft( "Calculate unused objects", calculateUnusedObjects ); calculateUnusedObjects = WordWrappingToggleLeft( "Calculate unused objects", calculateUnusedObjects );
hideDuplicateRows = WordWrappingToggleLeft( "Hide duplicate rows in search results", hideDuplicateRows ); hideDuplicateRows = WordWrappingToggleLeft( "Hide duplicate rows in search results", hideDuplicateRows );
#if UNITY_2018_3_OR_NEWER hideRedundantPrefabReferencesInAssets = WordWrappingToggleLeft( hideRedundantPrefabReferencesInAssetsLabel, hideRedundantPrefabReferencesInAssets );
hideReduntantPrefabVariantLinks = WordWrappingToggleLeft( "Hide redundant prefab variant links (when the same value is assigned to the same Component of a prefab and its variant(s))", hideReduntantPrefabVariantLinks ); hideRedundantPrefabReferencesInScenes = WordWrappingToggleLeft( hideRedundantPrefabReferencesInScenesLabel, hideRedundantPrefabReferencesInScenes );
#endif
noAssetDatabaseChanges = WordWrappingToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges ); noAssetDatabaseChanges = WordWrappingToggleLeft( "I haven't modified any assets/scenes since the last search (faster search)", noAssetDatabaseChanges );
showDetailedProgressBar = WordWrappingToggleLeft( "Update search progress bar more often (cancelable search) (slower search)", showDetailedProgressBar ); showDetailedProgressBar = WordWrappingToggleLeft( "Update search progress bar more often (cancelable search) (slower search)", showDetailedProgressBar );
@@ -658,10 +656,7 @@ namespace AssetUsageDetectorNamespace
private void DrawObjectsToSearchSection() private void DrawObjectsToSearchSection()
{ {
Color c = GUI.backgroundColor; Utilities.DrawHeader( "<b>SEARCHED OBJECTS</b>" );
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
GUILayout.Box( "<b>SEARCHED OBJECTS</b>", Utilities.BoxGUIStyle, Utilities.GL_EXPAND_WIDTH );
GUI.backgroundColor = c;
Rect searchedObjectsHeaderRect = GUILayoutUtility.GetLastRect(); Rect searchedObjectsHeaderRect = GUILayoutUtility.GetLastRect();
searchedObjectsHeaderRect.x += 5f; searchedObjectsHeaderRect.x += 5f;
@@ -674,7 +669,31 @@ namespace AssetUsageDetectorNamespace
objectsToSearchDrawer.Draw( objectsToSearch ); objectsToSearchDrawer.Draw( objectsToSearch );
} }
private bool WordWrappingToggleLeft( string label, bool value ) private void BeginIndentedGUI( bool isVertical = true )
{
GUILayout.BeginHorizontal();
GUILayout.Space( 35f );
if( isVertical )
GUILayout.BeginVertical();
}
private void EndIndentedGUI( bool isVertical = true )
{
if( isVertical )
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
public static bool WordWrappingToggleLeft( string label, bool value )
{
sharedGUIContent.text = label;
sharedGUIContent.tooltip = null;
return WordWrappingToggleLeft( sharedGUIContent, value );
}
public static bool WordWrappingToggleLeft( GUIContent label, bool value )
{ {
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 ); bool result = EditorGUILayout.ToggleLeft( GUIContent.none, value, GL_WIDTH_12 );
@@ -724,7 +743,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = calculateUnusedObjects, calculateUnusedObjects = calculateUnusedObjects,
hideDuplicateRows = hideDuplicateRows, hideDuplicateRows = hideDuplicateRows,
hideReduntantPrefabVariantLinks = hideReduntantPrefabVariantLinks, hideRedundantPrefabReferencesInAssets = hideRedundantPrefabReferencesInAssets,
hideRedundantPrefabReferencesInScenes = hideRedundantPrefabReferencesInScenes && searchInAssetsFolder,
noAssetDatabaseChanges = noAssetDatabaseChanges, noAssetDatabaseChanges = noAssetDatabaseChanges,
showDetailedProgressBar = showDetailedProgressBar showDetailedProgressBar = showDetailedProgressBar
} ); } );
@@ -23,6 +23,7 @@ namespace AssetUsageDetectorNamespace
public SearchResultGroup.GroupType type; public SearchResultGroup.GroupType type;
public bool isExpanded; public bool isExpanded;
public bool pendingSearch; public bool pendingSearch;
public int redundantReferences;
public SearchResultTreeViewState treeViewState; public SearchResultTreeViewState treeViewState;
public List<int> initialSerializedNodes; public List<int> initialSerializedNodes;
@@ -576,6 +577,9 @@ namespace AssetUsageDetectorNamespace
public int NumberOfReferences { get { return references.Count; } } public int NumberOfReferences { get { return references.Count; } }
public ReferenceNode this[int index] { get { return references[index]; } } public ReferenceNode this[int index] { get { return references[index]; } }
public int NumberOfRedundantReferences { get; internal set; }
public bool AnyReferencesFound { get { return NumberOfReferences > 0 || NumberOfRedundantReferences > 0; } }
public SearchResultGroup( string title, GroupType type, bool isExpanded = true, bool pendingSearch = false ) public SearchResultGroup( string title, GroupType type, bool isExpanded = true, bool pendingSearch = false )
{ {
Title = title.StartsWith( "<b>" ) ? title : string.Concat( "<b>", title, "</b>" ); Title = title.StartsWith( "<b>" ) ? title : string.Concat( "<b>", title, "</b>" );
@@ -778,28 +782,48 @@ namespace AssetUsageDetectorNamespace
IsExpanded = true; IsExpanded = true;
} ); } );
if( searchResult != null && searchResult.NumberOfGroups > 1 && !string.IsNullOrEmpty( treeViewState.searchTerm ) ) if( !string.IsNullOrEmpty( treeViewState.searchTerm ) )
{ {
if( contextMenu.GetItemCount() > 0 ) if( contextMenu.GetItemCount() > 0 )
contextMenu.AddSeparator( "" ); contextMenu.AddSeparator( "" );
contextMenu.AddItem( new GUIContent( "Apply Search to All Results" ), false, () => if( searchResult != null && searchResult.NumberOfGroups > 1 )
{ {
for( int i = 0; i < searchResult.NumberOfGroups; i++ ) contextMenu.AddItem( new GUIContent( "Apply Search to All Results" ), false, () =>
{ {
if( searchResult[i].treeView == null ) for( int i = 0; i < searchResult.NumberOfGroups; i++ )
continue; {
if( searchResult[i].treeView == null )
continue;
string previousSearchTerm = searchResult[i].treeViewState.searchTerm ?? ""; string previousSearchTerm = searchResult[i].treeViewState.searchTerm ?? "";
SearchResultTreeView.SearchMode previousSearchMode = searchResult[i].treeViewState.searchMode; SearchResultTreeView.SearchMode previousSearchMode = searchResult[i].treeViewState.searchMode;
searchResult[i].treeViewState.searchTerm = treeViewState.searchTerm ?? ""; searchResult[i].treeViewState.searchTerm = treeViewState.searchTerm ?? "";
searchResult[i].treeViewState.searchMode = treeViewState.searchMode; searchResult[i].treeViewState.searchMode = treeViewState.searchMode;
if( treeViewState.searchTerm != previousSearchTerm || treeViewState.searchMode != previousSearchMode ) if( treeViewState.searchTerm != previousSearchTerm || treeViewState.searchMode != previousSearchMode )
searchResult[i].treeView.RefreshSearch( previousSearchTerm ); searchResult[i].treeView.RefreshSearch( previousSearchTerm );
} }
} ); } );
}
IList<TreeViewItem> treeViewRows = treeView.GetRows();
if( treeViewRows.Count > 1 ) // References are at depth 1 so if there are any references, at least 2 rows must exist
{
contextMenu.AddItem( new GUIContent( "Hide Search Results" ), false, () =>
{
List<int> removedRows = new List<int>( treeViewRows.Count );
for( int i = treeViewRows.Count - 1; i >= 0; i-- )
{
if( treeViewRows[i].depth > 0 )
removedRows.Add( treeViewRows[i].id );
}
treeView.ClearSearch();
treeView.HideItems( removedRows );
} );
}
} }
} }
@@ -849,6 +873,9 @@ namespace AssetUsageDetectorNamespace
if( IsExpanded ) if( IsExpanded )
{ {
if( NumberOfRedundantReferences > 0 )
EditorGUILayout.HelpBox( string.Concat( NumberOfRedundantReferences.ToString(), " redundant prefab reference(s) were skipped. Disable \"Hide redundant prefab references in ", ( Type == GroupType.Scene || Type == GroupType.DontDestroyOnLoad ) ? "Scenes" : "Assets", "\" to see them." ), MessageType.Info );
if( PendingSearch ) if( PendingSearch )
GUILayout.Box( "Lazy Search: this scene potentially has some references, hit Refresh to find them", Utilities.BoxGUIStyle ); GUILayout.Box( "Lazy Search: this scene potentially has some references, hit Refresh to find them", Utilities.BoxGUIStyle );
else if( references.Count == 0 ) else if( references.Count == 0 )
@@ -863,6 +890,9 @@ namespace AssetUsageDetectorNamespace
if( searchResult != null && searchResult.SearchParameters.dontSearchInSourceAssets && searchResult.SearchParameters.objectsToSearch.Length > 1 ) 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 ); 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 ); 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 );
} }
@@ -878,7 +908,7 @@ namespace AssetUsageDetectorNamespace
if( shouldUpdateInitialTreeViewNodeId ) if( shouldUpdateInitialTreeViewNodeId )
treeViewState.initialNodeId = searchResult.nextTreeViewId; treeViewState.initialNodeId = searchResult.nextTreeViewId;
treeView = new SearchResultTreeView( treeViewState, references, ( Type == GroupType.UnusedObjects ) ? SearchResultTreeView.TreeType.UnusedObjects : SearchResultTreeView.TreeType.Normal, searchResult != null ? searchResult.UsedObjects : null, searchResult != null && searchResult.SearchParameters.hideDuplicateRows, searchResult != null && searchResult.SearchParameters.hideReduntantPrefabVariantLinks, true ); treeView = new SearchResultTreeView( treeViewState, references, ( Type == GroupType.UnusedObjects ) ? SearchResultTreeView.TreeType.UnusedObjects : SearchResultTreeView.TreeType.Normal, searchResult != null ? searchResult.UsedObjects : null, searchResult != null && searchResult.SearchParameters.hideDuplicateRows, true );
if( isFirstInitialization ) if( isFirstInitialization )
{ {
@@ -1042,6 +1072,7 @@ namespace AssetUsageDetectorNamespace
type = Type, type = Type,
isExpanded = IsExpanded, isExpanded = IsExpanded,
pendingSearch = PendingSearch, pendingSearch = PendingSearch,
redundantReferences = NumberOfRedundantReferences,
treeViewState = treeViewState treeViewState = treeViewState
}; };
@@ -1059,6 +1090,7 @@ namespace AssetUsageDetectorNamespace
// Deserialize this result group from the serialized data // Deserialize this result group from the serialized data
internal void Deserialize( SearchResult.SerializableResultGroup serializedResultGroup, List<ReferenceNode> allNodes ) internal void Deserialize( SearchResult.SerializableResultGroup serializedResultGroup, List<ReferenceNode> allNodes )
{ {
NumberOfRedundantReferences = serializedResultGroup.redundantReferences;
treeViewState = serializedResultGroup.treeViewState; treeViewState = serializedResultGroup.treeViewState;
if( serializedResultGroup.initialSerializedNodes != null ) if( serializedResultGroup.initialSerializedNodes != null )
@@ -124,7 +124,6 @@ namespace AssetUsageDetectorNamespace
private readonly TreeType treeType; private readonly TreeType treeType;
private readonly bool hideDuplicateRows; private readonly bool hideDuplicateRows;
private readonly bool hideReduntantPrefabVariantLinks;
private bool isSearching; private bool isSearching;
@@ -164,13 +163,12 @@ namespace AssetUsageDetectorNamespace
[System.Obsolete] private new string searchString { get; } [System.Obsolete] private new string searchString { get; }
[System.Obsolete] private new bool hasSearch { get; } [System.Obsolete] private new bool hasSearch { get; }
public SearchResultTreeView( SearchResultTreeViewState state, List<ReferenceNode> references, TreeType treeType, HashSet<Object> usedObjectsSet, bool hideDuplicateRows, bool hideReduntantPrefabVariantLinks, bool usesExternalScrollView ) : base( state ) public SearchResultTreeView( SearchResultTreeViewState state, List<ReferenceNode> references, TreeType treeType, HashSet<Object> usedObjectsSet, bool hideDuplicateRows, bool usesExternalScrollView ) : base( state )
{ {
this.state = state; this.state = state;
this.references = references; this.references = references;
this.treeType = treeType; this.treeType = treeType;
this.hideDuplicateRows = hideDuplicateRows; this.hideDuplicateRows = hideDuplicateRows;
this.hideReduntantPrefabVariantLinks = hideReduntantPrefabVariantLinks;
highlightedSearchTextColor = "<color=#" + ColorUtility.ToHtmlStringRGBA( AssetUsageDetectorSettings.SearchMatchingTextColor ) + ">"; highlightedSearchTextColor = "<color=#" + ColorUtility.ToHtmlStringRGBA( AssetUsageDetectorSettings.SearchMatchingTextColor ) + ">";
@@ -202,6 +200,13 @@ namespace AssetUsageDetectorNamespace
RefreshSelectedNodes( GetSelection() ); RefreshSelectedNodes( GetSelection() );
} }
public void ClearSearch()
{
string prevSearchTerm = state.searchTerm;
state.searchTerm = "";
RefreshSearch( prevSearchTerm );
}
public void RefreshSearch( string prevSearchTerm ) public void RefreshSearch( string prevSearchTerm )
{ {
bool wasSearchTermEmpty = string.IsNullOrEmpty( prevSearchTerm ); bool wasSearchTermEmpty = string.IsNullOrEmpty( prevSearchTerm );
@@ -993,7 +998,7 @@ namespace AssetUsageDetectorNamespace
return referenceNodes.Contains( GetDataFromId( item.id ).node ); return referenceNodes.Contains( GetDataFromId( item.id ).node );
} }
private void HideItems( IList<int> ids ) public void HideItems( IList<int> ids )
{ {
if( ids.Count > 0 ) if( ids.Count > 0 )
{ {
@@ -1158,7 +1163,7 @@ namespace AssetUsageDetectorNamespace
if( selectedNodes.Count > 0 ) if( selectedNodes.Count > 0 )
{ {
SearchResultTreeView isolatedTreeView = new SearchResultTreeView( new SearchResultTreeViewState(), selectedNodes, TreeType.IsolatedView, null, hideDuplicateRows, hideReduntantPrefabVariantLinks, false ); SearchResultTreeView isolatedTreeView = new SearchResultTreeView( new SearchResultTreeViewState(), selectedNodes, TreeType.IsolatedView, null, hideDuplicateRows, false );
isolatedTreeView.ExpandMainReferences(); isolatedTreeView.ExpandMainReferences();
SearchResultTreeViewIsolatedView.Show( new Vector2( EditorWindow.focusedWindow.position.width, Mathf.Max( isolatedTreeView.totalHeight, EditorGUIUtility.singleLineHeight * 5f ) + 1f ), isolatedTreeView, new GUIContent( selectedNodes[0].Label + ( selectedNodes.Count <= 1 ? "" : ( " (and " + ( selectedNodes.Count - 1 ) + " more)" ) ) ) ); SearchResultTreeViewIsolatedView.Show( new Vector2( EditorWindow.focusedWindow.position.width, Mathf.Max( isolatedTreeView.totalHeight, EditorGUIUtility.singleLineHeight * 5f ) + 1f ), isolatedTreeView, new GUIContent( selectedNodes[0].Label + ( selectedNodes.Count <= 1 ? "" : ( " (and " + ( selectedNodes.Count - 1 ) + " more)" ) ) ) );
+107 -21
View File
@@ -51,6 +51,10 @@ namespace AssetUsageDetectorNamespace
private static MethodInfo screenFittedRectGetter; private static MethodInfo screenFittedRectGetter;
#if UNITY_2018_3_OR_NEWER
private static readonly Func<Object, bool, bool> prefabHasAnyOverridesGetter = (Func<Object, bool, bool>) Delegate.CreateDelegate( typeof( Func<Object, bool, bool> ), typeof( PrefabUtility ).GetMethod( "HasObjectOverride", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static ) );
#endif
private static readonly HashSet<string> folderContentsSet = new HashSet<string>(); private static readonly HashSet<string> folderContentsSet = new HashSet<string>();
internal static readonly StringBuilder stringBuilder = new StringBuilder( 400 ); internal static readonly StringBuilder stringBuilder = new StringBuilder( 400 );
@@ -114,6 +118,97 @@ namespace AssetUsageDetectorNamespace
return obj is DefaultAsset && AssetDatabase.IsValidFolder( AssetDatabase.GetAssetPath( obj ) ); return obj is DefaultAsset && AssetDatabase.IsValidFolder( AssetDatabase.GetAssetPath( obj ) );
} }
public static T GetPrefabParent<T>( this T obj ) where T : Object
{
#if UNITY_2018_3_OR_NEWER
return PrefabUtility.GetCorrespondingObjectFromSource( obj );
#else
return PrefabUtility.GetPrefabParent( obj ) as T;
#endif
}
public static bool HasAnyPrefabOverrides( this Object obj )
{
if( obj.GetPrefabParent() == null )
return false;
#if UNITY_2018_3_OR_NEWER
return prefabHasAnyOverridesGetter( obj, false );
#else
SerializedProperty iterator = new SerializedObject( obj ).GetIterator();
if( iterator.Next( true ) )
{
do
{
if( iterator.prefabOverride )
return true;
} while( iterator.NextVisible( false ) );
}
return false;
#endif
}
public static bool HasAnyPrefabOverrides( this GameObject gameObject )
{
if( gameObject.GetPrefabParent() == null )
return false;
#if UNITY_2018_3_OR_NEWER
if( !PrefabUtility.HasPrefabInstanceAnyOverrides( gameObject, false ) )
return false;
#endif
Transform rootTransform = gameObject.transform;
List<Component> components = new List<Component>( 8 );
Stack<Transform> stack = new Stack<Transform>( 8 );
stack.Push( rootTransform );
while( stack.Count > 0 )
{
Transform transform = stack.Pop();
Transform prefab = transform.GetPrefabParent();
if( prefab == null ) // GameObject is added as override
return true;
if( transform.childCount != prefab.childCount ) // Has some added/destroyed children as override
return true;
bool isRootTransform = ReferenceEquals( transform, rootTransform );
if( !isRootTransform && ( transform.gameObject as Object ).HasAnyPrefabOverrides() ) // GameObject's properties are modified (e.g. name or tag) (excluding root GameObject)
return true;
components.Clear();
transform.GetComponents( components );
foreach( Component component in components )
{
if( component == null )
continue;
if( component.GetPrefabParent() == null ) // Component is added as override
return true;
if( ( !isRootTransform || !( component is Transform ) ) && component.HasAnyPrefabOverrides() ) // Component is modified (excluding root Transform)
return true;
}
int componentCount = components.Count;
components.Clear();
prefab.GetComponents( components );
if( components.Count != componentCount ) // Has some destroyed components as override
return true;
for( int i = 0, childCount = transform.childCount; i < childCount; i++ )
{
Transform child = transform.GetChild( i );
if( child != null )
stack.Push( child );
}
}
return false;
}
// Returns an enumerator to iterate through all asset paths in the folder // Returns an enumerator to iterate through all asset paths in the folder
public static IEnumerable<string> EnumerateFolderContents( Object folderAsset ) public static IEnumerable<string> EnumerateFolderContents( Object folderAsset )
{ {
@@ -446,6 +541,15 @@ namespace AssetUsageDetectorNamespace
return stringBuilder.ToString(); return stringBuilder.ToString();
} }
// Draw header inside OnGUI
public static void DrawHeader( string label )
{
Color c = GUI.backgroundColor;
GUI.backgroundColor = AssetUsageDetectorSettings.SettingsHeaderColor;
GUILayout.Box( label, BoxGUIStyle, GL_EXPAND_WIDTH );
GUI.backgroundColor = c;
}
// Draw horizontal line inside OnGUI // Draw horizontal line inside OnGUI
public static void DrawSeparatorLine() public static void DrawSeparatorLine()
{ {
@@ -471,7 +575,7 @@ namespace AssetUsageDetectorNamespace
for( int i = 0; i < objectsToSearch.Count; i++ ) for( int i = 0; i < objectsToSearch.Count; i++ )
{ {
if( objectsToSearch[i].obj != null && !objectsToSearch[i].obj.Equals( null ) ) if( objectsToSearch[i].obj != null )
return false; return false;
} }
@@ -479,38 +583,20 @@ namespace AssetUsageDetectorNamespace
} }
// Check if all the objects inside the list are null // Check if all the objects inside the list are null
public static bool IsEmpty( this List<Object> objects ) public static bool IsEmpty<T>( this List<T> objects ) where T : Object
{ {
if( objects == null ) if( objects == null )
return true; return true;
for( int i = 0; i < objects.Count; i++ ) for( int i = 0; i < objects.Count; i++ )
{ {
if( objects[i] != null && !objects[i].Equals( null ) ) if( objects[i] != null )
return false; return false;
} }
return true; return true;
} }
// Check if all the objects that are enumerated are null
public static bool IsEmpty( this IEnumerable<Object> objects )
{
if( objects == null )
return true;
using( IEnumerator<Object> enumerator = objects.GetEnumerator() )
{
while( enumerator.MoveNext() )
{
if( enumerator.Current != null && !enumerator.Current.Equals( null ) )
return false;
}
}
return true;
}
// Returns true is str starts with prefix // Returns true is str starts with prefix
public static bool StartsWithFast( this string str, string prefix ) public static bool StartsWithFast( this string str, string prefix )
{ {
+1 -1
View File
@@ -1,4 +1,4 @@
= Asset Usage Detector (v2.5.1) = = Asset Usage Detector (v2.5.5) =
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
E-mail: yasirkula@gmail.com E-mail: yasirkula@gmail.com
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "com.yasirkula.assetusagedetector", "name": "com.yasirkula.assetusagedetector",
"displayName": "Asset Usage Detector", "displayName": "Asset Usage Detector",
"version": "2.5.1", "version": "2.5.5",
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector", "documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases", "changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt", "licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",