UniVRM/Packages/VRM/Editor/Format/VRMMaterialValidator.cs
Isamu Mogi 40a3a6dbe1 Unity 6.2 以降で ShaderUtil の一部のメンバーが Obsolete 警告を出すのに対応
Unity 6.2 以降で、UniVRMが利用している ShaderUtil の次のメンバーが Obsolete となり警告が出るようになりました。

- [GetPropertyCount](https://docs.unity3d.com/6000.2/Documentation/ScriptReference/ShaderUtil.GetPropertyCount.html)
- [GetPropertyType](https://docs.unity3d.com/6000.2/Documentation/ScriptReference/ShaderUtil.GetPropertyType.html)
- [GetPropertyName](https://docs.unity3d.com/6000.2/Documentation/ScriptReference/ShaderUtil.GetPropertyName.html)
- [ShaderPropertyType](https://docs.unity3d.com/6000.2/Documentation/ScriptReference/ShaderUtil.ShaderPropertyType.html)

これらは `Shader` インスタンスのメソッドと `UnityEngine.Rendering.ShaderPropertyType` に置き換わりました。これらの置き換え後の項目は全て UniVRM の最小サポートバージョンである Unity 2022.3 LTS にも存在するため、そのまま置き換えました。

発生していた警告は次のようなものでした。

```
Packages\VRM10\Runtime\Components\Expression\Preview\PreviewMaterialUtil.cs(19,33): warning CS0618: 'ShaderUtil.GetPropertyCount(Shader)' is obsolete: 'Use Shader.GetPropertyCount instead.'
Packages\VRM10\Runtime\Components\Expression\Preview\PreviewMaterialUtil.cs(21,32): warning CS0618: 'ShaderUtil.GetPropertyType(Shader, int)' is obsolete: 'Use Shader.GetPropertyType instead.'
Packages\VRM10\Runtime\Components\Expression\Preview\PreviewMaterialUtil.cs(22,28): warning CS0618: 'ShaderUtil.GetPropertyName(Shader, int)' is obsolete: 'Use Shader.GetPropertyName instead.'
```
2026-07-04 16:20:25 +09:00

59 lines
2.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace VRM
{
/// <summary>
/// VRM0
/// </summary>
class VRMMaterialValidator : UniGLTF.DefaultMaterialValidator
{
public override string GetGltfMaterialTypeFromUnityShaderName(string shaderName)
{
if (BuiltInVrmMaterialExporter.SupportedShaderNames.Contains(shaderName))
{
return "VRM0X";
}
return base.GetGltfMaterialTypeFromUnityShaderName(shaderName);
}
public override IEnumerable<(string propertyName, Texture texture)> EnumerateTextureProperties(Material m)
{
/// 歴史的経緯により処理ロジックが2種類ある
if (m.shader.name == "VRM/MToon")
{
// [Unity列挙]
// * Shader の Property を列挙する。Editor専用。
// * あらかじめEditorで実行して property 一覧をハードコーディングしてある `Assets\VRMShaders\VRM\IO\Runtime\VRM\PreExportShaders_VRM.cs` 界隈。
// * 今は "VRM/MToon" のみ
//
// extensions.VRM.materialProperties に記録する
//
var prop = PreShaderPropExporter.GetPropsForMToon();
foreach (var kv in prop.Properties)
{
if (kv.ShaderPropertyType == ShaderPropertyType.TexEnv)
{
yield return (kv.Key, m.GetTexture(kv.Key));
}
}
}
else
{
// [Shaderの定義から手で記述]
//
// PBR, Unlit
// * DefaultMaterialValidator.EnumerateTextureProperties
//
// glTF.materials に記録する
//
foreach (var textureProperty in base.EnumerateTextureProperties(m))
{
yield return textureProperty;
}
}
}
}
}