module-project-validator/Editor/Validators/Assets/AssetValidatorMaterialTexture.cs
Anders Ejlersen eb46c22ffc Validator: Skipping render pipeline check on shader, fi no RenderPipeline tag is found
Validator: Skipping textures in material, if marked as PerRendererData, HideInInspector or NonModifiableTextureData
Validator: Fixed issue, where arrays weren't iterated correctly, which resulted in an exception
Window: Added warning and error count
2026-05-27 21:50:04 +02:00

34 lines
No EOL
1.2 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace Module.ProjectValidator.Editor
{
internal sealed class AssetValidatorMaterialTexture : IAssetValidator<Material>
{
public void Validate(Material obj, List<ValidatorResult> results)
{
if (obj.shader == null)
return;
var count = obj.shader.GetPropertyCount();
for (var i = 0; i < count; i++)
{
var propertyType = obj.shader.GetPropertyType(i);
var propertyFlags = obj.shader.GetPropertyFlags(i);
if (propertyType != ShaderPropertyType.Texture)
continue;
if ((propertyFlags & (ShaderPropertyFlags.PerRendererData | ShaderPropertyFlags.HideInInspector | ShaderPropertyFlags.NonModifiableTextureData)) != 0)
continue;
var propertyName = obj.shader.GetPropertyName(i);
var propertyValue = obj.GetTexture(propertyName);
if (propertyValue == null)
results.Add(ValidatorResult.Create(EValidatorSeverity.Warning, $"Texture property '{propertyName}' is Null"));
}
}
}
}