Compare commits

..

9 Commits

Author SHA1 Message Date
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
yasirkula da921c2e06 "Hide redundant prefab variant links" setting now works as expected, only affecting variables in components and not affecting prefab/MonoScript usages 2023-11-18 17:53:42 +03:00
yasirkula d9cc52cc37 Fixed some properties not being searched in edge cases that may occur when Addressables or VFX Graph packages are present in the project 2023-11-18 17:50:27 +03:00
yasirkula e6641bef48 "Show Root Asset's Name" setting is enabled by default + root asset's name is prepended by "in" word for more clarity 2023-11-18 17:46:28 +03:00
yasirkula a6d91a58a3 Scenes in read-only packages aren't searched since they can't be opened (fixed #36) (closed #37) 2023-11-18 17:45:22 +03:00
8 changed files with 184 additions and 164 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 hideNonOverriddenPrefabVariablesInAssets = true;
public bool hideNonOverriddenPrefabVariablesInScenes = false;
public bool noAssetDatabaseChanges = false; public bool noAssetDatabaseChanges = false;
public bool showDetailedProgressBar = true; public bool showDetailedProgressBar = true;
} }
@@ -514,18 +515,29 @@ namespace AssetUsageDetectorNamespace
} }
} }
// Search scenes for references
foreach( string scenePath in scenesToSearch ) foreach( string scenePath in scenesToSearch )
{ {
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) ) if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) )
throw new Exception( "Search aborted" ); throw new Exception( "Search aborted" );
// Search scene for references
if( string.IsNullOrEmpty( scenePath ) ) if( string.IsNullOrEmpty( scenePath ) )
continue; continue;
if( excludedScenesPathsSet.Contains( scenePath ) ) if( excludedScenesPathsSet.Contains( scenePath ) )
continue; continue;
#if UNITY_2019_2_OR_NEWER
// Skip scenes in read-only packages (Issue #36)
// Credit: https://forum.unity.com/threads/check-if-asset-inside-package-is-readonly.900902/#post-5990822
if( !scenePath.StartsWithFast( "Assets/" ) )
{
var packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath( scenePath );
if( packageInfo != null && packageInfo.source != UnityEditor.PackageManager.PackageSource.Embedded && packageInfo.source != UnityEditor.PackageManager.PackageSource.Local )
continue;
}
#endif
SearchScene( scenePath, searchResult, searchParameters, initialSceneSetup ); SearchScene( scenePath, searchResult, searchParameters, initialSceneSetup );
} }
} }
@@ -700,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 )
{ {
@@ -727,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 );
@@ -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
@@ -1436,110 +1437,119 @@ namespace AssetUsageDetectorNamespace
// Search through variables of an object with SerializedObject // Search through variables of an object with SerializedObject
private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode, bool forceUseSerializedObject = false ) private void SearchVariablesWithSerializedObject( ReferenceNode referenceNode, bool forceUseSerializedObject = false )
{ {
if( !isInPlayMode || referenceNode.nodeObject.IsAsset() || forceUseSerializedObject ) Object unityObject = (Object) referenceNode.nodeObject;
if( !isInPlayMode || unityObject.IsAsset() || forceUseSerializedObject )
{ {
#if ASSET_USAGE_ADDRESSABLES #if ASSET_USAGE_ADDRESSABLES
// See: https://github.com/yasirkula/UnityAssetUsageDetector/issues/29 // See: https://github.com/yasirkula/UnityAssetUsageDetector/issues/29
if( searchParameters.addressablesSupport && ( (Object) referenceNode.nodeObject ).name == "Deprecated EditorExtensionImpl" ) if( searchParameters.addressablesSupport && unityObject.name == "Deprecated EditorExtensionImpl" )
return; return;
#endif #endif
SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject ); SerializedObject so = new SerializedObject( unityObject );
SerializedProperty iterator = so.GetIterator(); SerializedProperty iterator = so.GetIterator();
SerializedProperty iteratorVisible = so.GetIterator(); SerializedProperty iteratorVisible = so.GetIterator();
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 = ( ( searchParameters.hideNonOverriddenPrefabVariablesInAssets && unityObject.IsAsset() ) || ( searchParameters.hideNonOverriddenPrefabVariablesInScenes && !unityObject.IsAsset() ) ) && PrefabUtility.GetCorrespondingObjectFromSource( unityObject ) != null;
#endif
bool enterChildren; bool enterChildren;
do do
{ {
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity // Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
// properties don't have FieldInfos so we are skipping them, which is good because search results found in // properties don't have FieldInfos so we are skipping them, which is good because search results found in
// those properties aren't interesting and mostly confusing) // those properties aren't interesting and mostly confusing)
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible ); bool shouldMoveVisibleIterator = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
if( isVisible ) bool isVisible = shouldMoveVisibleIterator || iterator.type == "Array";
iteratingVisible = iteratorVisible.NextVisible( iteratorVisible.propertyType == SerializedPropertyType.Generic ); if( !isVisible )
else
{ {
Type propFieldType; Type propFieldType;
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null; isVisible = fieldInfoGetter( iterator, out propFieldType ) != null;
} }
if( !isVisible ) if( !isVisible )
{
enterChildren = false; enterChildren = false;
continue; #if UNITY_2018_3_OR_NEWER
} else if( searchPrefabOverridesOnly && !iterator.prefabOverride )
enterChildren = false;
Object propertyValue;
ReferenceNode searchResult;
switch( iterator.propertyType )
{
case SerializedPropertyType.ObjectReference:
propertyValue = iterator.objectReferenceValue;
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false;
break;
case SerializedPropertyType.ExposedReference:
propertyValue = iterator.exposedReferenceValue;
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false;
break;
#if UNITY_2019_3_OR_NEWER
case SerializedPropertyType.ManagedReference:
object managedReferenceValue = GetRawSerializedPropertyValue( iterator );
propertyValue = managedReferenceValue as Object;
searchResult = SearchObject( PreferablyGameObject( managedReferenceValue ) );
enterChildren = false;
break;
#endif #endif
case SerializedPropertyType.Generic: else
#if ASSET_USAGE_ADDRESSABLES {
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference ) Object propertyValue;
{ ReferenceNode searchResult;
propertyValue = GetAddressablesAssetReferenceValue( assetReference ); switch( iterator.propertyType )
{
case SerializedPropertyType.ObjectReference:
propertyValue = iterator.objectReferenceValue;
searchResult = SearchObject( PreferablyGameObject( propertyValue ) ); searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false; enterChildren = false;
} break;
else case SerializedPropertyType.ExposedReference:
propertyValue = iterator.exposedReferenceValue;
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false;
break;
#if UNITY_2019_3_OR_NEWER
case SerializedPropertyType.ManagedReference:
object managedReferenceValue = GetRawSerializedPropertyValue( iterator );
propertyValue = managedReferenceValue as Object;
searchResult = SearchObject( PreferablyGameObject( managedReferenceValue ) );
enterChildren = false;
break;
#endif
case SerializedPropertyType.Generic:
#if ASSET_USAGE_ADDRESSABLES
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference )
{
propertyValue = GetAddressablesAssetReferenceValue( assetReference );
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
enterChildren = false;
}
else
#endif #endif
#if ASSET_USAGE_VFX_GRAPH #if ASSET_USAGE_VFX_GRAPH
if( vfxSerializableObjectValueGetter != null && iterator.type == "VFXSerializableObject" && GetRawSerializedPropertyValue( iterator ) is object vfxSerializableObject ) if( vfxSerializableObjectValueGetter != null && iterator.type == "VFXSerializableObject" && GetRawSerializedPropertyValue( iterator ) is object vfxSerializableObject )
{ {
object vfxSerializableObjectValue = vfxSerializableObjectValueGetter.Invoke( vfxSerializableObject, null ); object vfxSerializableObjectValue = vfxSerializableObjectValueGetter.Invoke( vfxSerializableObject, null );
propertyValue = vfxSerializableObjectValue as Object; propertyValue = vfxSerializableObjectValue as Object;
searchResult = SearchObject( PreferablyGameObject( vfxSerializableObjectValue ) ); searchResult = SearchObject( PreferablyGameObject( vfxSerializableObjectValue ) );
enterChildren = false; enterChildren = false;
} }
else else
#endif #endif
{ {
propertyValue = null;
searchResult = null;
enterChildren = true;
}
break;
default:
propertyValue = null; propertyValue = null;
searchResult = null; searchResult = null;
enterChildren = true; enterChildren = false;
} break;
}
break; if( searchResult != null && searchResult != referenceNode )
default:
propertyValue = null;
searchResult = null;
enterChildren = false;
break;
}
if( searchResult != null && searchResult != referenceNode )
{
string propertyPath = iterator.propertyPath;
// m_RD.texture is a redundant reference that shows up when searching sprites
if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
{ {
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]" string propertyPath = iterator.propertyPath;
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) ) // m_RD.texture is a redundant reference that shows up when searching sprites
searchParameters.searchRefactoring( new SerializedPropertyMatch( (Object) referenceNode.nodeObject, propertyValue, iterator ) ); if( !propertyPath.EndsWithFast( "m_RD.texture" ) )
{
referenceNode.AddLinkTo( searchResult, "Variable: " + propertyPath.Replace( ".Array.data[", "[" ) ); // "arrayVariable.Array.data[0]" becomes "arrayVariable[0]"
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) )
searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) );
}
} }
} }
if( shouldMoveVisibleIterator )
iteratingVisible = iteratorVisible.NextVisible( enterChildren );
} while( iterator.Next( enterChildren ) ); } while( iterator.Next( enterChildren ) );
return; return;
@@ -99,7 +99,7 @@ namespace AssetUsageDetectorNamespace
private static bool? m_showRootAssetName = null; private static bool? m_showRootAssetName = null;
public static bool ShowRootAssetName public static bool ShowRootAssetName
{ {
get { if( m_showRootAssetName == null ) m_showRootAssetName = EditorPrefs.GetBool( "AUD_ShowRootAssetName", false ); return m_showRootAssetName.Value; } get { if( m_showRootAssetName == null ) m_showRootAssetName = EditorPrefs.GetBool( "AUD_ShowRootAssetName", true ); return m_showRootAssetName.Value; }
set { if( m_showRootAssetName == value ) return; m_showRootAssetName = value; EditorPrefs.SetBool( "AUD_ShowRootAssetName", value ); } set { if( m_showRootAssetName == value ) return; m_showRootAssetName = value; EditorPrefs.SetBool( "AUD_ShowRootAssetName", value ); }
} }
@@ -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 );
@@ -35,13 +35,14 @@ namespace AssetUsageDetectorNamespace
private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport"; private const string PREFS_ADDRESSABLES_SUPPORT = "AUD_AddressablesSupport";
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_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS = "AUD_HideRedundantPVariantLinks";
private const string PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES = "AUD_HideRedundantPVarsInScenes";
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 GUIStyle lockButtonStyle; private GUIStyle lockButtonStyle;
@@ -93,7 +94,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 hideNonOverriddenPrefabVariablesInAssets = true;
private bool hideNonOverriddenPrefabVariablesInScenes = false;
private bool noAssetDatabaseChanges = false; private bool noAssetDatabaseChanges = false;
private bool showDetailedProgressBar = true; private bool showDetailedProgressBar = true;
@@ -331,7 +333,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = searchParameters.calculateUnusedObjects; calculateUnusedObjects = searchParameters.calculateUnusedObjects;
hideDuplicateRows = searchParameters.hideDuplicateRows; hideDuplicateRows = searchParameters.hideDuplicateRows;
hideReduntantPrefabVariantLinks = searchParameters.hideReduntantPrefabVariantLinks; hideNonOverriddenPrefabVariablesInAssets = searchParameters.hideNonOverriddenPrefabVariablesInAssets;
hideNonOverriddenPrefabVariablesInScenes = searchParameters.hideNonOverriddenPrefabVariablesInScenes;
noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges; noAssetDatabaseChanges = searchParameters.noAssetDatabaseChanges;
showDetailedProgressBar = searchParameters.showDetailedProgressBar; showDetailedProgressBar = searchParameters.showDetailedProgressBar;
@@ -414,7 +417,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_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS, hideNonOverriddenPrefabVariablesInAssets );
EditorPrefs.SetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES, hideNonOverriddenPrefabVariablesInScenes );
EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar ); EditorPrefs.SetBool( PREFS_SHOW_PROGRESS, showDetailedProgressBar );
} }
@@ -436,7 +440,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 ); hideNonOverriddenPrefabVariablesInAssets = EditorPrefs.GetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_ASSETS, true );
hideNonOverriddenPrefabVariablesInScenes = EditorPrefs.GetBool( PREFS_HIDE_NON_OVERRIDDEN_PREFAB_VARIABLES_IN_SCENES, false );
showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true ); showDetailedProgressBar = EditorPrefs.GetBool( PREFS_SHOW_PROGRESS, true );
} }
@@ -583,7 +588,8 @@ namespace AssetUsageDetectorNamespace
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 #if UNITY_2018_3_OR_NEWER
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 ); hideNonOverriddenPrefabVariablesInAssets = WordWrappingToggleLeft( "Hide non-overridden prefab variables in assets (references found in non-overridden variables of prefab variants/nested prefabs will be hidden)", hideNonOverriddenPrefabVariablesInAssets );
hideNonOverriddenPrefabVariablesInScenes = WordWrappingToggleLeft( "Hide non-overridden prefab variables in scenes (references found in non-overridden variables of prefab instances will be hidden)", hideNonOverriddenPrefabVariablesInScenes );
#endif #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 );
@@ -674,7 +680,7 @@ namespace AssetUsageDetectorNamespace
objectsToSearchDrawer.Draw( objectsToSearch ); objectsToSearchDrawer.Draw( objectsToSearch );
} }
private bool WordWrappingToggleLeft( string label, bool value ) public static bool WordWrappingToggleLeft( string 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 +730,8 @@ namespace AssetUsageDetectorNamespace
#endif #endif
calculateUnusedObjects = calculateUnusedObjects, calculateUnusedObjects = calculateUnusedObjects,
hideDuplicateRows = hideDuplicateRows, hideDuplicateRows = hideDuplicateRows,
hideReduntantPrefabVariantLinks = hideReduntantPrefabVariantLinks, hideNonOverriddenPrefabVariablesInAssets = hideNonOverriddenPrefabVariablesInAssets,
hideNonOverriddenPrefabVariablesInScenes = hideNonOverriddenPrefabVariablesInScenes,
noAssetDatabaseChanges = noAssetDatabaseChanges, noAssetDatabaseChanges = noAssetDatabaseChanges,
showDetailedProgressBar = showDetailedProgressBar showDetailedProgressBar = showDetailedProgressBar
} ); } );
@@ -778,28 +778,47 @@ 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.HideItems( removedRows );
} );
}
} }
} }
@@ -863,6 +882,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 +900,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 )
{ {
@@ -1180,30 +1202,6 @@ namespace AssetUsageDetectorNamespace
} }
} }
internal bool HasLinkToObjectWithDescriptions( int instanceId, List<string> descriptions )
{
for( int i = links.Count - 1; i >= 0; i-- )
{
Link link = links[i];
if( link.targetNode.instanceId == instanceId )
{
List<string> _descriptions = link.descriptions;
if( _descriptions.Count != descriptions.Count )
return false;
for( int j = _descriptions.Count - 1; j >= 0; j-- )
{
if( _descriptions[j] != descriptions[j] )
return false;
}
return true;
}
}
return false;
}
public void CopyReferencesTo( ReferenceNode other ) public void CopyReferencesTo( ReferenceNode other )
{ {
other.links.Clear(); other.links.Clear();
@@ -1232,7 +1230,7 @@ namespace AssetUsageDetectorNamespace
{ {
string mainAssetName = Path.GetFileNameWithoutExtension( AssetDatabase.GetAssetPath( unityObject ) ); string mainAssetName = Path.GetFileNameWithoutExtension( AssetDatabase.GetAssetPath( unityObject ) );
if( unityObject.name != mainAssetName ) if( unityObject.name != mainAssetName )
Label += " <" + mainAssetName + ">"; Label += " <in " + mainAssetName + ">";
} }
} }
else if( nodeObject != null ) else if( nodeObject != 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 ) + ">";
@@ -287,25 +285,6 @@ namespace AssetUsageDetectorNamespace
private bool GenerateRowsRecursive( TreeViewItem parent, ReferenceNode referenceNode, ReferenceNodeData parentData, int siblingIndex, int depth, bool? itemForcedVisibility, List<ReferenceNode> stack, HashSet<ReferenceNode> processedNodes, ref int id ) private bool GenerateRowsRecursive( TreeViewItem parent, ReferenceNode referenceNode, ReferenceNodeData parentData, int siblingIndex, int depth, bool? itemForcedVisibility, List<ReferenceNode> stack, HashSet<ReferenceNode> processedNodes, ref int id )
{ {
#if UNITY_2018_3_OR_NEWER
// If the same reference is found in both a prefab variant and its base prefab, omit the prefab variant to reduce the number of
// redundant links (changing the value in base prefab will automatically change the value in its variants, after all)
if( hideReduntantPrefabVariantLinks && depth > 0 )
{
Object unityObject = referenceNode.UnityObject;
if( unityObject && ( unityObject is Component || unityObject is GameObject ) && unityObject.IsAsset() )
{
List<string> linkDescriptions = parentData.node[siblingIndex].descriptions;
if( linkDescriptions.Count > 0 )
{
Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource( unityObject );
if( prefabObject && parentData.node.HasLinkToObjectWithDescriptions( prefabObject.GetInstanceID(), linkDescriptions ) )
return false;
}
}
}
#endif
TreeViewItem item = new TreeViewItem( id++, depth, "" ); TreeViewItem item = new TreeViewItem( id++, depth, "" );
ReferenceNodeData data = new ReferenceNodeData( item, referenceNode, parentData, siblingIndex ); ReferenceNodeData data = new ReferenceNodeData( item, referenceNode, parentData, siblingIndex );
@@ -1012,7 +991,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 )
{ {
@@ -1177,7 +1156,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)" ) ) ) );
+1 -1
View File
@@ -1,4 +1,4 @@
= Asset Usage Detector (v2.5.0) = = Asset Usage Detector (v2.5.4) =
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.0", "version": "2.5.4",
"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",