mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-09 11:07:26 -05:00
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.' ```
63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UniGLTF;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
|
|
namespace UniVRM10
|
|
{
|
|
public static class PreviewMaterialUtil
|
|
{
|
|
public static bool TryCreateForPreview(Material material, out PreviewMaterialItem item)
|
|
{
|
|
item = new PreviewMaterialItem(material);
|
|
|
|
var propNames = new List<string>();
|
|
var hasError = false;
|
|
for (int i = 0; i < material.shader.GetPropertyCount(); ++i)
|
|
{
|
|
var propType = material.shader.GetPropertyType(i);
|
|
var name = material.shader.GetPropertyName(i);
|
|
|
|
switch (propType)
|
|
{
|
|
case UnityEngine.Rendering.ShaderPropertyType.Color:
|
|
// 色
|
|
{
|
|
if (!PreviewMaterialItem.TryGetBindType(name, out var bindType))
|
|
{
|
|
UniGLTFLogger.Error($"{material.shader.name}.{name} is unsupported property name");
|
|
hasError = true;
|
|
continue;
|
|
}
|
|
|
|
if (!Enum.TryParse(propType.ToString(), true, out ShaderPropertyType propertyType))
|
|
{
|
|
UniGLTFLogger.Error($"{material.shader.name}.{propertyType.ToString()} is unsupported property type");
|
|
hasError = true;
|
|
continue;
|
|
}
|
|
|
|
item.PropMap.Add(bindType, new PropItem
|
|
{
|
|
Name = name,
|
|
PropertyType = propertyType,
|
|
DefaultValues = material.GetColor(name),
|
|
});
|
|
propNames.Add(name);
|
|
}
|
|
break;
|
|
|
|
case UnityEngine.Rendering.ShaderPropertyType.Texture:
|
|
break;
|
|
}
|
|
}
|
|
item.PropNames = propNames.ToArray();
|
|
|
|
return !hasError;
|
|
}
|
|
}
|
|
}
|
|
#endif |