From 8a6fe822d665f8b59de69a469d8edbe750952a45 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Wed, 5 Jan 2022 10:17:07 +0300 Subject: [PATCH] Materials instantiated (cloned) at runtime are now searched correctly --- .../Editor/AssetUsageDetectorSearchFunctions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs index c0448bc..c637e84 100644 --- a/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs +++ b/Plugins/AssetUsageDetector/Editor/AssetUsageDetectorSearchFunctions.cs @@ -571,6 +571,23 @@ namespace AssetUsageDetectorNamespace referenceNode.RemoveLink( i ); } + // At runtime, Textures assigned to clone materials can't be searched with reflection, search them manually here + if( searchTextureReferences && isInPlayMode && !AssetDatabase.Contains( material ) ) + { + Shader shader = material.shader; + int shaderPropertyCount = ShaderUtil.GetPropertyCount( shader ); + for( int i = 0; i < shaderPropertyCount; i++ ) + { + if( ShaderUtil.GetPropertyType( shader, i ) == ShaderUtil.ShaderPropertyType.TexEnv ) + { + string propertyName = ShaderUtil.GetPropertyName( shader, i ); + Texture assignedTexture = material.GetTexture( propertyName ); + if( objectsToSearchSet.Contains( assignedTexture ) ) + referenceNode.AddLinkTo( GetReferenceNode( assignedTexture ), "Shader property: " + propertyName ); + } + } + } + return referenceNode; }