mirror of
https://github.com/yasirkula/UnityAssetUsageDetector.git
synced 2026-11-21 07:22:37 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 45b0f6f1d9 | |||
| c599ea6273 | |||
| 7ba33e2d4e | |||
| ac294324dd | |||
| 8dc7d5508b | |||
| c9131811e2 | |||
| 133b8b1227 | |||
| 1db9dbf9b0 | |||
| a6b0f5ae92 | |||
| 8e7369e44e |
@@ -51,10 +51,35 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( fileSizes == null || fileSizes.Length != dependencies.Length )
|
if( fileSizes == null || fileSizes.Length != dependencies.Length )
|
||||||
fileSizes = new long[dependencies.Length];
|
fileSizes = new long[dependencies.Length];
|
||||||
|
|
||||||
for( int i = 0; i < dependencies.Length; i++ )
|
int length = dependencies.Length;
|
||||||
|
for( int i = 0; i < length; i++ )
|
||||||
{
|
{
|
||||||
FileInfo assetFile = new FileInfo( dependencies[i] );
|
if( !string.IsNullOrEmpty( dependencies[i] ) )
|
||||||
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
{
|
||||||
|
FileInfo assetFile = new FileInfo( dependencies[i] );
|
||||||
|
fileSizes[i] = assetFile.Exists ? assetFile.Length : 0L;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// This dependency is empty which causes issues when passed to FileInfo constructor
|
||||||
|
// Find a non-empty dependency and move it to this index
|
||||||
|
for( int j = length - 1; j > i; j--, length-- )
|
||||||
|
{
|
||||||
|
if( !string.IsNullOrEmpty( dependencies[j] ) )
|
||||||
|
{
|
||||||
|
dependencies[i--] = dependencies[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( length != fileSizes.Length )
|
||||||
|
{
|
||||||
|
Array.Resize( ref dependencies, length );
|
||||||
|
Array.Resize( ref fileSizes, length );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -400,7 +400,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ParticleSystem.CollisionModule collisionModule = particleSystem.collision;
|
ParticleSystem.CollisionModule collisionModule = particleSystem.collision;
|
||||||
|
#if UNITY_2020_2_OR_NEWER
|
||||||
|
for( int i = 0, j = collisionModule.planeCount; i < j; i++ )
|
||||||
|
#else
|
||||||
for( int i = 0, j = collisionModule.maxPlaneCount; i < j; i++ )
|
for( int i = 0, j = collisionModule.maxPlaneCount; i < j; i++ )
|
||||||
|
#endif
|
||||||
referenceNode.AddLinkTo( SearchObject( collisionModule.GetPlane( i ) ), "Collision Module: Plane" );
|
referenceNode.AddLinkTo( SearchObject( collisionModule.GetPlane( i ) ), "Collision Module: Plane" );
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@@ -408,10 +412,35 @@ namespace AssetUsageDetectorNamespace
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
ParticleSystem.TriggerModule triggerModule = particleSystem.trigger;
|
ParticleSystem.TriggerModule triggerModule = particleSystem.trigger;
|
||||||
|
#if UNITY_2020_2_OR_NEWER
|
||||||
|
for( int i = 0, j = triggerModule.colliderCount; i < j; i++ )
|
||||||
|
#else
|
||||||
for( int i = 0, j = triggerModule.maxColliderCount; i < j; i++ )
|
for( int i = 0, j = triggerModule.maxColliderCount; i < j; i++ )
|
||||||
|
#endif
|
||||||
referenceNode.AddLinkTo( SearchObject( triggerModule.GetCollider( i ) ), "Trigger Module: Collider" );
|
referenceNode.AddLinkTo( SearchObject( triggerModule.GetCollider( i ) ), "Trigger Module: Collider" );
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
||||||
|
#if UNITY_2017_1_OR_NEWER
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ParticleSystem.TextureSheetAnimationModule textureSheetAnimationModule = particleSystem.textureSheetAnimation;
|
||||||
|
for( int i = 0, j = textureSheetAnimationModule.spriteCount; i < j; i++ )
|
||||||
|
referenceNode.AddLinkTo( SearchObject( textureSheetAnimationModule.GetSprite( i ) ), "Texture Sheet Animation Module: Sprite" );
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if UNITY_5_5_OR_NEWER
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ParticleSystem.SubEmittersModule subEmittersModule = particleSystem.subEmitters;
|
||||||
|
for( int i = 0, j = subEmittersModule.subEmittersCount; i < j; i++ )
|
||||||
|
referenceNode.AddLinkTo( SearchObject( subEmittersModule.GetSubEmitterSystem( i ) ), "Sub Emitters Module: ParticleSystem" );
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if( searchRenderers && component is Renderer )
|
else if( searchRenderers && component is Renderer )
|
||||||
{
|
{
|
||||||
@@ -715,19 +744,61 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( packables != null )
|
if( packables != null )
|
||||||
{
|
{
|
||||||
for( int i = 0; i < packables.Length; i++ )
|
for( int i = 0; i < packables.Length; i++ )
|
||||||
referenceNode.AddLinkTo( SearchObject( packables[i] ), "Packed Texture" );
|
SearchSpriteAtlas( referenceNode, packables[i] );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
SerializedProperty packables = spriteAtlasSO.FindProperty( "m_EditorData.packables" );
|
SerializedProperty packables = spriteAtlasSO.FindProperty( "m_EditorData.packables" );
|
||||||
if( packables != null )
|
if( packables != null )
|
||||||
{
|
{
|
||||||
for( int i = 0, length = packables.arraySize; i < length; i++ )
|
for( int i = 0, length = packables.arraySize; i < length; i++ )
|
||||||
referenceNode.AddLinkTo( SearchObject( packables.GetArrayElementAtIndex( i ).objectReferenceValue ), "Packed Texture" );
|
SearchSpriteAtlas( referenceNode, packables.GetArrayElementAtIndex( i ).objectReferenceValue );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return referenceNode;
|
return referenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SearchSpriteAtlas( ReferenceNode referenceNode, Object packedAsset )
|
||||||
|
{
|
||||||
|
if( packedAsset == null || packedAsset.Equals( null ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
referenceNode.AddLinkTo( SearchObject( packedAsset ), "Packed Texture" );
|
||||||
|
|
||||||
|
if( packedAsset is Texture )
|
||||||
|
{
|
||||||
|
// Search the Texture's sprites if the Texture asset isn't included in the "Find references of:" list (i.e. user has
|
||||||
|
// added only a Sprite sub-asset of the Texture to the list, not the Texture asset itself). Otherwise, references to
|
||||||
|
// both the Texture and its sprites will be found which can be considered as duplicate references
|
||||||
|
if( AssetDatabase.IsMainAsset( packedAsset ) && !assetsToSearchSet.Contains( packedAsset ) )
|
||||||
|
{
|
||||||
|
Object[] textureSubAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath( AssetDatabase.GetAssetPath( packedAsset ) );
|
||||||
|
for( int i = 0; i < textureSubAssets.Length; i++ )
|
||||||
|
{
|
||||||
|
if( textureSubAssets[i] is Sprite )
|
||||||
|
referenceNode.AddLinkTo( SearchObject( textureSubAssets[i] ), "Packed Texture" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( packedAsset.IsFolder() )
|
||||||
|
{
|
||||||
|
// Search all Sprites in the folder
|
||||||
|
string[] texturesInFolder = AssetDatabase.FindAssets( "t:Texture2D", new string[] { AssetDatabase.GetAssetPath( packedAsset ) } );
|
||||||
|
if( texturesInFolder != null )
|
||||||
|
{
|
||||||
|
for( int i = 0; i < texturesInFolder.Length; i++ )
|
||||||
|
{
|
||||||
|
string texturePath = AssetDatabase.GUIDToAssetPath( texturesInFolder[i] );
|
||||||
|
TextureImporter textureImporter = AssetImporter.GetAtPath( texturePath ) as TextureImporter;
|
||||||
|
if( textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite )
|
||||||
|
{
|
||||||
|
// Search the Texture and its sprites
|
||||||
|
SearchSpriteAtlas( referenceNode, AssetDatabase.LoadMainAssetAtPath( texturePath ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNITY_2017_3_OR_NEWER
|
#if UNITY_2017_3_OR_NEWER
|
||||||
@@ -1021,26 +1092,38 @@ namespace AssetUsageDetectorNamespace
|
|||||||
SerializedProperty iteratorVisible = so.GetIterator();
|
SerializedProperty iteratorVisible = so.GetIterator();
|
||||||
if( iterator.Next( true ) )
|
if( iterator.Next( true ) )
|
||||||
{
|
{
|
||||||
|
string assetPath = AssetDatabase.GetAssetPath( (Object) referenceNode.nodeObject );
|
||||||
|
bool isProjectSettings = !string.IsNullOrEmpty( assetPath ) && assetPath.StartsWithFast( "ProjectSettings/" );
|
||||||
|
|
||||||
bool iteratingVisible = iteratorVisible.NextVisible( true );
|
bool iteratingVisible = iteratorVisible.NextVisible( true );
|
||||||
bool enterChildren;
|
bool enterChildren;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
|
if( isProjectSettings )
|
||||||
// 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)
|
// Search Project Settings in full because for some reason, important settings like SRP asset
|
||||||
bool isVisible = iteratingVisible && SerializedProperty.EqualContents( iterator, iteratorVisible );
|
// slot in Quality Settings aren't searched when iterating over only visible properties
|
||||||
if( isVisible )
|
enterChildren = true;
|
||||||
iteratingVisible = iteratorVisible.NextVisible( true );
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Type propFieldType;
|
// Iterate over NextVisible properties AND the properties that have corresponding FieldInfos (internal Unity
|
||||||
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
|
// 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( true );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Type propFieldType;
|
||||||
|
isVisible = iterator.type == "Array" || fieldInfoGetter( iterator, out propFieldType ) != null;
|
||||||
|
}
|
||||||
|
|
||||||
if( !isVisible )
|
if( !isVisible )
|
||||||
{
|
{
|
||||||
enterChildren = false;
|
enterChildren = false;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReferenceNode searchResult;
|
ReferenceNode searchResult;
|
||||||
|
|||||||
@@ -86,12 +86,18 @@ namespace AssetUsageDetectorNamespace
|
|||||||
Object prevObject = GetObjectFromElement( element );
|
Object prevObject = GetObjectFromElement( element );
|
||||||
Object newObject = EditorGUILayout.ObjectField( "", prevObject, typeof( Object ), acceptSceneObjects );
|
Object newObject = EditorGUILayout.ObjectField( "", prevObject, typeof( Object ), acceptSceneObjects );
|
||||||
|
|
||||||
if( GUI.changed && prevObject != newObject )
|
if( GUI.changed )
|
||||||
{
|
{
|
||||||
hasChanged = true;
|
hasChanged = true;
|
||||||
SetObjectOfElement( list, i, newObject );
|
SetObjectOfElement( list, i, newObject );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( guiEnabled && newObject && ev.type == EventType.ContextClick && GUILayoutUtility.GetLastRect().Contains( ev.mousePosition ) )
|
||||||
|
{
|
||||||
|
OnElementRightClicked( list, i, newObject );
|
||||||
|
ev.Use();
|
||||||
|
}
|
||||||
|
|
||||||
if( guiEnabled )
|
if( guiEnabled )
|
||||||
{
|
{
|
||||||
if( GUILayout.Button( "+", Utilities.GL_WIDTH_25 ) )
|
if( GUILayout.Button( "+", Utilities.GL_WIDTH_25 ) )
|
||||||
@@ -121,6 +127,7 @@ namespace AssetUsageDetectorNamespace
|
|||||||
protected abstract T CreateElement( Object source );
|
protected abstract T CreateElement( Object source );
|
||||||
protected abstract Object GetObjectFromElement( T element );
|
protected abstract Object GetObjectFromElement( T element );
|
||||||
protected abstract void SetObjectOfElement( List<T> list, int index, Object value );
|
protected abstract void SetObjectOfElement( List<T> list, int index, Object value );
|
||||||
|
protected abstract void OnElementRightClicked( List<T> list, int index, Object value );
|
||||||
protected abstract bool IsElementNull( T element );
|
protected abstract bool IsElementNull( T element );
|
||||||
protected abstract void PostElementDrawer( T element );
|
protected abstract void PostElementDrawer( T element );
|
||||||
}
|
}
|
||||||
@@ -146,6 +153,10 @@ namespace AssetUsageDetectorNamespace
|
|||||||
list[index] = value;
|
list[index] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnElementRightClicked( List<Object> list, int index, Object value )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool IsElementNull( Object element )
|
protected override bool IsElementNull( Object element )
|
||||||
{
|
{
|
||||||
return element == null || element.Equals( null );
|
return element == null || element.Equals( null );
|
||||||
@@ -178,6 +189,13 @@ namespace AssetUsageDetectorNamespace
|
|||||||
list[index].RefreshSubAssets();
|
list[index].RefreshSubAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnElementRightClicked( List<ObjectToSearch> list, int index, Object value )
|
||||||
|
{
|
||||||
|
GenericMenu contextMenu = new GenericMenu();
|
||||||
|
contextMenu.AddItem( new GUIContent( "Refresh" ), false, () => SetObjectOfElement( list, index, value ) );
|
||||||
|
contextMenu.ShowAsContext();
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool IsElementNull( ObjectToSearch element )
|
protected override bool IsElementNull( ObjectToSearch element )
|
||||||
{
|
{
|
||||||
return element == null || element.obj == null || element.obj.Equals( null );
|
return element == null || element.obj == null || element.obj.Equals( null );
|
||||||
|
|||||||
@@ -924,7 +924,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
if( !string.IsNullOrEmpty( description ) )
|
if( !string.IsNullOrEmpty( description ) )
|
||||||
{
|
{
|
||||||
if( !string.IsNullOrEmpty( links[i].description ) )
|
if( !string.IsNullOrEmpty( links[i].description ) )
|
||||||
links[i] = new Link( links[i].targetNode, string.Concat( links[i].description, Environment.NewLine, description ) );
|
{
|
||||||
|
// Avoid duplicate descriptions
|
||||||
|
if( !links[i].description.Contains( description ) )
|
||||||
|
links[i] = new Link( links[i].targetNode, string.Concat( links[i].description, Environment.NewLine, description ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
links[i] = new Link( links[i].targetNode, description );
|
links[i] = new Link( links[i].targetNode, description );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,11 @@ namespace AssetUsageDetectorNamespace
|
|||||||
m_boxGUIStyle.focused.textColor = textColor;
|
m_boxGUIStyle.focused.textColor = textColor;
|
||||||
m_boxGUIStyle.active.textColor = textColor;
|
m_boxGUIStyle.active.textColor = textColor;
|
||||||
|
|
||||||
|
#if !UNITY_2019_1_OR_NEWER || UNITY_2019_3_OR_NEWER
|
||||||
|
// On 2019.1 and 2019.2 versions, GUI.skin.button.fontSize returns 0 on some devices
|
||||||
|
// https://forum.unity.com/threads/asset-usage-detector-find-references-to-an-asset-object-open-source.408134/page-3#post-7285954
|
||||||
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
|
m_boxGUIStyle.fontSize = ( m_boxGUIStyle.fontSize + GUI.skin.button.fontSize ) / 2;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_boxGUIStyle;
|
return m_boxGUIStyle;
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "com.yasirkula.assetusagedetector",
|
"name": "com.yasirkula.assetusagedetector",
|
||||||
"displayName": "Asset Usage Detector",
|
"displayName": "Asset Usage Detector",
|
||||||
"version": "1.9.2",
|
"version": "1.9.7",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user