From 01241ac7be663920a7b3593f8aad14d571cd24a1 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 20 Apr 2021 14:03:06 +0900 Subject: [PATCH] =?UTF-8?q?StandardMap=20=E3=81=AE=20AssetKey=20=E3=81=AE?= =?UTF-8?q?=E6=AF=94=E8=BC=83=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniGLTF/ScriptedImporter/TextureExtractor.cs | 10 +++++++--- Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs index 3ec448ba4..d474f79b8 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/TextureExtractor.cs @@ -63,10 +63,14 @@ namespace UniGLTF case TextureImportTypes.StandardMap: { // write converted texture - var (_, subAsset) = m_subAssets.FirstOrDefault(x => x.Equals(key)); + var (_, subAsset) = m_subAssets.FirstOrDefault(kv => kv.Key.Equals(key)); + if (subAsset == null) + { + throw new KeyNotFoundException(); + } targetPath = m_textureDirectory.Child($"{key.Name}.png"); File.WriteAllBytes(targetPath.FullPath, subAsset.EncodeToPNG().ToArray()); - // targetPath.ImportAsset(); + targetPath.ImportAsset(); break; } @@ -75,7 +79,7 @@ namespace UniGLTF // write original bytes targetPath = m_textureDirectory.Child($"{key.Name}{param.Ext}"); File.WriteAllBytes(targetPath.FullPath, param.Index0().Result.ToArray()); - // targetPath.ImportAsset(); + targetPath.ImportAsset(); break; } } diff --git a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs index 01180fabd..3b5eb1f65 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/TextureTests.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using NUnit.Framework; @@ -92,7 +93,8 @@ namespace UniGLTF // extractor var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), loader.TextureFactory.Textures.Select(x => (new SubAssetKey(typeof(Texture2D), x.Texture.name), x.Texture)).ToArray()); var m = GltfTextureEnumerator.EnumerateTexturesForMaterial(parser, 0).FirstOrDefault(x => x.Item1.Name == "texture_1.standard"); - extractor.Extract(m.Item1, m.Item2); + + Assert.Catch(() => extractor.Extract(m.Item1, m.Item2)); } } }