From f2df475e1ee2e1643e54a0ff44a9172aff1298a0 Mon Sep 17 00:00:00 2001 From: Felix Herbst Date: Sun, 1 May 2022 16:57:50 +0200 Subject: [PATCH] feat: use correct default materials on URP/HDRP simplify: use pipelineAsset.defaultMaterial --- Packages/jp.keijiro.metamesh/Editor/MetameshImporter.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Packages/jp.keijiro.metamesh/Editor/MetameshImporter.cs b/Packages/jp.keijiro.metamesh/Editor/MetameshImporter.cs index 2135dd7..9f7e45d 100644 --- a/Packages/jp.keijiro.metamesh/Editor/MetameshImporter.cs +++ b/Packages/jp.keijiro.metamesh/Editor/MetameshImporter.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEditor; +using UnityEngine.Rendering; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -32,9 +33,11 @@ public override void OnImportAsset(AssetImportContext context) var meshFilter = gameObject.AddComponent(); meshFilter.sharedMesh = mesh; + var pipelineAsset = GraphicsSettings.currentRenderPipeline; + var baseMaterial = pipelineAsset ? pipelineAsset.defaultMaterial : AssetDatabase.GetBuiltinExtraResource("Default-Diffuse.mat"); + var meshRenderer = gameObject.AddComponent(); - meshRenderer.sharedMaterial = - AssetDatabase.GetBuiltinExtraResource("Default-Diffuse.mat"); + meshRenderer.sharedMaterial = baseMaterial; context.AddObjectToAsset("prefab", gameObject); if (mesh != null) context.AddObjectToAsset("mesh", mesh);