Skip to content

Commit 314eeb2

Browse files
fix(lods): fix obsolete ShaderUtil usage in LODGenerator for Unity 2021.2+ (#74)
* Fix Obsolete ShaderUtil usage in LODGenerator for Unity 2021.2+ * style(lod) : add missing neweline at the end of LODGenerator.cs * style: fix indentation --------- Co-authored-by: Whinarn <[email protected]>
1 parent d741912 commit 314eeb2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Runtime/LODGenerator.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,30 @@ private static void DestroyLODMaterialAsset(Material material)
769769
if (shader == null)
770770
return;
771771

772-
// We find all texture properties of materials and delete those assets also
772+
// Find all texture properties of materials and delete those assets also
773+
#if UNITY_2021_2_OR_NEWER
774+
int propertyCount = shader.GetPropertyCount();
775+
for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
776+
{
777+
if (shader.GetPropertyType(propertyIndex) == UnityEngine.Rendering.ShaderPropertyType.Texture)
778+
{
779+
string propertyName = shader.GetPropertyName(propertyIndex);
780+
var texture = material.GetTexture(propertyName);
781+
DestroyLODAsset(texture);
782+
}
783+
}
784+
#else
773785
int propertyCount = UnityEditor.ShaderUtil.GetPropertyCount(shader);
774786
for (int propertyIndex = 0; propertyIndex < propertyCount; propertyIndex++)
775787
{
776-
var propertyType = UnityEditor.ShaderUtil.GetPropertyType(shader, propertyIndex);
777-
if (propertyType == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
788+
if (UnityEditor.ShaderUtil.GetPropertyType(shader, propertyIndex) == UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv)
778789
{
779790
string propertyName = UnityEditor.ShaderUtil.GetPropertyName(shader, propertyIndex);
780791
var texture = material.GetTexture(propertyName);
781792
DestroyLODAsset(texture);
782793
}
783794
}
795+
#endif
784796

785797
DestroyLODAsset(material);
786798
}

0 commit comments

Comments
 (0)