From 4a4d40272f281becdbe380bdc550ecac57f85ba0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 24 Mar 2021 19:25:11 +0900 Subject: [PATCH] MaterialName --- .../UniGLTF/IO/MaterialIO/MaterialFactory.cs | 18 ++++++------------ .../UniGLTF/IO/MaterialIO/PBRMaterialItem.cs | 6 ++++-- .../UniGLTF/IO/MaterialIO/UnlitMaterialItem.cs | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs index 8768b560f..85e31b785 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/MaterialFactory.cs @@ -156,19 +156,13 @@ namespace UniGLTF } } - public static Material CreateMaterial(int index, glTFMaterial src, string shaderName) + public static string MaterialName(int index, glTFMaterial src) { - var material = new Material(Shader.Find(shaderName)); -#if UNITY_EDITOR - // textureImporter.SaveAndReimport(); may destroy this material - material.hideFlags = HideFlags.DontUnloadUnusedAsset; -#endif - material.name = (src == null || string.IsNullOrEmpty(src.name)) - ? string.Format("material_{0:00}", index) - : src.name - ; - - return material; + if(src!=null && !string.IsNullOrEmpty(src.name)) + { + return src.name; + } + return $"material_{index:00}"; } public static void SetTextureOffsetAndScale(Material material, glTFTextureInfo textureInfo, string propertyName) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/PBRMaterialItem.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/PBRMaterialItem.cs index 90b1d9ac5..cd4538c6a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/PBRMaterialItem.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/PBRMaterialItem.cs @@ -77,13 +77,15 @@ namespace UniGLTF getTexture = (IAwaitCaller _awaitCaller, glTF _gltf, TextureImportParam _param) => Task.FromResult(null); } + var material = new Material(Shader.Find(ShaderName)); if (i < 0 || i >= parser.GLTF.materials.Count) { - return MaterialFactory.CreateMaterial(i, null, ShaderName); + material.name = MaterialFactory.MaterialName(i, null); + return material; } var src = parser.GLTF.materials[i]; - var material = MaterialFactory.CreateMaterial(i, src, ShaderName); + material.name = MaterialFactory.MaterialName(i, src); var standardParam = default(TextureImportParam); if (src.pbrMetallicRoughness != null || src.occlusionTexture != null) { diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/UnlitMaterialItem.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/UnlitMaterialItem.cs index f04643b4f..03f7b9a6c 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/UnlitMaterialItem.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/UnlitMaterialItem.cs @@ -16,7 +16,8 @@ namespace UniGLTF } var src = parser.GLTF.materials[i]; - var material = MaterialFactory.CreateMaterial(i, src, ShaderName); + var material = new Material(Shader.Find(ShaderName)); + material.name = MaterialFactory.MaterialName(i, src); // texture if (src.pbrMetallicRoughness.baseColorTexture != null)