mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-19 22:42:37 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66dd66787c | |||
| da921c2e06 | |||
| d9cc52cc37 | |||
| e6641bef48 | |||
| a6d91a58a3 |
@@ -514,18 +514,29 @@ namespace AssetUsageDetectorNamespace
|
||||
}
|
||||
}
|
||||
|
||||
// Search scenes for references
|
||||
foreach( string scenePath in scenesToSearch )
|
||||
{
|
||||
if( EditorUtility.DisplayCancelableProgressBar( "Please wait...", "Searching scene: " + scenePath, (float) ++searchProgress / searchTotalProgress ) )
|
||||
throw new Exception( "Search aborted" );
|
||||
|
||||
// Search scene for references
|
||||
if( string.IsNullOrEmpty( scenePath ) )
|
||||
continue;
|
||||
|
||||
if( excludedScenesPathsSet.Contains( scenePath ) )
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,8 +217,9 @@ namespace AssetUsageDetectorNamespace
|
||||
#endif
|
||||
|
||||
#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 readonly MethodInfo vfxResourceContentsGetter = typeof( Editor ).Assembly.GetType( "UnityEditor.VFX.VisualEffectResource" ).GetMethod( "GetContents", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance );
|
||||
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 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 );
|
||||
#endif
|
||||
|
||||
@@ -1436,110 +1437,119 @@ namespace AssetUsageDetectorNamespace
|
||||
// Search through variables of an object with SerializedObject
|
||||
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
|
||||
// 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;
|
||||
#endif
|
||||
|
||||
SerializedObject so = new SerializedObject( (Object) referenceNode.nodeObject );
|
||||
SerializedObject so = new SerializedObject( unityObject );
|
||||
SerializedProperty iterator = so.GetIterator();
|
||||
SerializedProperty iteratorVisible = so.GetIterator();
|
||||
if( iterator.Next( 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;
|
||||
do
|
||||
{
|
||||
// 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
|
||||
// those properties aren't interesting and mostly confusing)
|
||||
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
|
||||
if( isVisible )
|
||||
iteratingVisible = iteratorVisible.NextVisible( iteratorVisible.propertyType == SerializedPropertyType.Generic );
|
||||
else
|
||||
bool shouldMoveVisibleIterator = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
|
||||
bool isVisible = shouldMoveVisibleIterator || iterator.type == "Array";
|
||||
if( !isVisible )
|
||||
{
|
||||
Type propFieldType;
|
||||
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
|
||||
isVisible = fieldInfoGetter( iterator, out propFieldType ) != null;
|
||||
}
|
||||
|
||||
if( !isVisible )
|
||||
{
|
||||
enterChildren = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
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;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
else if( searchPrefabOverridesOnly && !iterator.prefabOverride )
|
||||
enterChildren = false;
|
||||
#endif
|
||||
case SerializedPropertyType.Generic:
|
||||
#if ASSET_USAGE_ADDRESSABLES
|
||||
if( searchParameters.addressablesSupport && iterator.type.StartsWithFast( "AssetReference" ) && GetRawSerializedPropertyValue( iterator ) is AssetReference assetReference )
|
||||
{
|
||||
propertyValue = GetAddressablesAssetReferenceValue( assetReference );
|
||||
else
|
||||
{
|
||||
Object propertyValue;
|
||||
ReferenceNode searchResult;
|
||||
switch( iterator.propertyType )
|
||||
{
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
propertyValue = iterator.objectReferenceValue;
|
||||
searchResult = SearchObject( PreferablyGameObject( propertyValue ) );
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
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
|
||||
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
|
||||
#if ASSET_USAGE_VFX_GRAPH
|
||||
if( vfxSerializableObjectValueGetter != null && iterator.type == "VFXSerializableObject" && GetRawSerializedPropertyValue( iterator ) is object vfxSerializableObject )
|
||||
{
|
||||
object vfxSerializableObjectValue = vfxSerializableObjectValueGetter.Invoke( vfxSerializableObject, null );
|
||||
propertyValue = vfxSerializableObjectValue as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( vfxSerializableObjectValue ) );
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
if( vfxSerializableObjectValueGetter != null && iterator.type == "VFXSerializableObject" && GetRawSerializedPropertyValue( iterator ) is object vfxSerializableObject )
|
||||
{
|
||||
object vfxSerializableObjectValue = vfxSerializableObjectValueGetter.Invoke( vfxSerializableObject, null );
|
||||
propertyValue = vfxSerializableObjectValue as Object;
|
||||
searchResult = SearchObject( PreferablyGameObject( vfxSerializableObjectValue ) );
|
||||
enterChildren = false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
{
|
||||
propertyValue = null;
|
||||
searchResult = null;
|
||||
enterChildren = true;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
propertyValue = null;
|
||||
searchResult = null;
|
||||
enterChildren = true;
|
||||
}
|
||||
enterChildren = false;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
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" ) )
|
||||
if( searchResult != null && searchResult != referenceNode )
|
||||
{
|
||||
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 ) )
|
||||
searchParameters.searchRefactoring( new SerializedPropertyMatch( (Object) referenceNode.nodeObject, propertyValue, iterator ) );
|
||||
// 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]"
|
||||
|
||||
if( searchParameters.searchRefactoring != null && objectsToSearchSet.Contains( propertyValue ) )
|
||||
searchParameters.searchRefactoring( new SerializedPropertyMatch( unityObject, propertyValue, iterator ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( shouldMoveVisibleIterator )
|
||||
iteratingVisible = iteratorVisible.NextVisible( enterChildren );
|
||||
} while( iterator.Next( enterChildren ) );
|
||||
|
||||
return;
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace AssetUsageDetectorNamespace
|
||||
private static bool? m_showRootAssetName = null;
|
||||
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 ); }
|
||||
}
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
other.links.Clear();
|
||||
@@ -1232,7 +1208,7 @@ namespace AssetUsageDetectorNamespace
|
||||
{
|
||||
string mainAssetName = Path.GetFileNameWithoutExtension( AssetDatabase.GetAssetPath( unityObject ) );
|
||||
if( unityObject.name != mainAssetName )
|
||||
Label += " <" + mainAssetName + ">";
|
||||
Label += " <in " + mainAssetName + ">";
|
||||
}
|
||||
}
|
||||
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 )
|
||||
{
|
||||
#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, "" );
|
||||
ReferenceNodeData data = new ReferenceNodeData( item, referenceNode, parentData, siblingIndex );
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= Asset Usage Detector (v2.5.0) =
|
||||
= Asset Usage Detector (v2.5.2) =
|
||||
|
||||
Documentation: https://github.com/yasirkula/UnityAssetUsageDetector
|
||||
E-mail: yasirkula@gmail.com
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.yasirkula.assetusagedetector",
|
||||
"displayName": "Asset Usage Detector",
|
||||
"version": "2.5.0",
|
||||
"version": "2.5.2",
|
||||
"documentationUrl": "https://github.com/yasirkula/UnityAssetUsageDetector",
|
||||
"changelogUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/releases",
|
||||
"licensesUrl": "https://github.com/yasirkula/UnityAssetUsageDetector/blob/master/LICENSE.txt",
|
||||
|
||||
Reference in New Issue
Block a user