diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs new file mode 100644 index 000000000..93d9a4996 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs @@ -0,0 +1,46 @@ +using System; +using UnityEngine; + +namespace UniGLTF +{ + public class UrpUnlitMaterialExporter + { + public Shader Shader { get; set; } + + /// + /// "Universal Render Pipeline/Unlit" シェーダのマテリアルをエクスポートする。 + /// + /// プロパティに互換性がある他のシェーダを指定することもできる。 + /// + public UrpUnlitMaterialExporter(Shader shader = null) + { + Shader = shader != null ? shader : Shader.Find("Universal Render Pipeline/Unlit"); + } + + public bool TryExportMaterial(Material src, ITextureExporter textureExporter, out glTFMaterial dst) + { + try + { + if (src == null) throw new ArgumentNullException(nameof(src)); + if (src.shader != Shader) throw new ArgumentException(nameof(src)); + if (textureExporter == null) throw new ArgumentNullException(nameof(textureExporter)); + + dst = glTF_KHR_materials_unlit.CreateDefault(); + dst.name = src.name; + + var context = new UrpLitContext(src); + + UrpLitMaterialExporter.ExportSurfaceSettings(context, dst, textureExporter); + UrpLitMaterialExporter.ExportBaseColor(context, dst, textureExporter); + + return true; + } + catch (Exception e) + { + Debug.LogException(e); + dst = default; + return false; + } + } + } +} \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta new file mode 100644 index 000000000..9924e9e80 --- /dev/null +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpUnlitMaterialExporter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a90bb1e911744bbab916950324c70e52 +timeCreated: 1722614768 \ No newline at end of file diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs index f15cc756d..e1f1d5921 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/UrpGltfMaterialExporter.cs @@ -5,12 +5,14 @@ namespace UniGLTF public class UrpGltfMaterialExporter : IMaterialExporter { public UrpLitMaterialExporter UrpLitExporter { get; set; } = new(); + public UrpUnlitMaterialExporter UrpUnlitExporter { get; set; } = new(); public UrpUniUnlitMaterialExporter UrpUniUnlitExporter { get; set; } = new(); public UrpFallbackMaterialExporter FallbackExporter { get; set; } = new(); public glTFMaterial ExportMaterial(Material m, ITextureExporter textureExporter, GltfExportSettings settings) { if (UrpLitExporter.TryExportMaterial(m, textureExporter, out var dst)) return dst; + if (UrpUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; if (UrpUniUnlitExporter.TryExportMaterial(m, textureExporter, out dst)) return dst; Debug.Log($"Material `{m.name}` fallbacks.");