Compare commits

..

5 Commits

7 changed files with 96 additions and 118 deletions
@@ -514,18 +514,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 );
} }
} }
@@ -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.hideReduntantPrefabVariantLinks && 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 ); }
} }
@@ -1180,30 +1180,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 +1208,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 )
@@ -287,25 +287,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 );
+1 -1
View File
@@ -1,4 +1,4 @@
= Asset Usage Detector (v2.5.0) = = Asset Usage Detector (v2.5.2) =
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.2",
"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",