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)); } } }