From 430ec700fc16e24568c9f26ab4e809f8459a9c89 Mon Sep 17 00:00:00 2001 From: Felix Herbst Date: Wed, 5 Oct 2022 16:33:15 +0200 Subject: [PATCH 1/2] feat: allow importing KTX2 textures as sprites --- Editor/Scripts/BaseImporter.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Editor/Scripts/BaseImporter.cs b/Editor/Scripts/BaseImporter.cs index 413104a..bf5d5ef 100644 --- a/Editor/Scripts/BaseImporter.cs +++ b/Editor/Scripts/BaseImporter.cs @@ -57,6 +57,11 @@ public abstract class TextureImporter : ScriptedImporter { /// in linear color space (sRGB otherwise) /// public bool linear; + + /// + /// If true, an additional sprite asset will be generated. + /// + public bool importAsSprite; // ReSharper disable once NotAccessedField.Local [SerializeField][HideInInspector] @@ -85,8 +90,15 @@ public override void OnImportAsset(AssetImportContext ctx) if (result.errorCode == ErrorCode.Success) { result.texture.name = name; result.texture.alphaIsTransparency = true; - ctx.AddObjectToAsset("result", result.texture); + ctx.AddObjectToAsset("result", result.texture, result.texture); ctx.SetMainObject(result.texture); + + if (importAsSprite) { + var sprite = Sprite.Create(result.texture, new Rect(0, 0, result.texture.width, result.texture.height), new Vector2(50, 50), 100, 0, SpriteMeshType.FullRect); + sprite.name = result.texture.name; + ctx.AddObjectToAsset("sprite", sprite); + } + reportItems = new string[] { }; } else { var errorMessage = ErrorMessage.GetErrorMessage(result.errorCode); From e9c15d4088b3d17249345c12a5d0dc1e188561ff Mon Sep 17 00:00:00 2001 From: Felix Herbst Date: Tue, 6 Dec 2022 11:25:48 +0100 Subject: [PATCH 2/2] fix: rm thumbnails from ktx textures, huge performance impact with stored assetdb metadata --- Editor/Scripts/BaseImporter.cs | 2 +- Editor/Scripts/KtxImporter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/Scripts/BaseImporter.cs b/Editor/Scripts/BaseImporter.cs index bf5d5ef..d260e44 100644 --- a/Editor/Scripts/BaseImporter.cs +++ b/Editor/Scripts/BaseImporter.cs @@ -90,7 +90,7 @@ public override void OnImportAsset(AssetImportContext ctx) if (result.errorCode == ErrorCode.Success) { result.texture.name = name; result.texture.alphaIsTransparency = true; - ctx.AddObjectToAsset("result", result.texture, result.texture); + ctx.AddObjectToAsset("result", result.texture); ctx.SetMainObject(result.texture); if (importAsSprite) { diff --git a/Editor/Scripts/KtxImporter.cs b/Editor/Scripts/KtxImporter.cs index fb9ffe7..9cfd734 100644 --- a/Editor/Scripts/KtxImporter.cs +++ b/Editor/Scripts/KtxImporter.cs @@ -22,7 +22,7 @@ namespace KtxUnity { - [ScriptedImporter(0, new []{ ".ktx2" })] + [ScriptedImporter(1, new []{ ".ktx2" })] public class KtxImporter : TextureImporter { protected override TextureBase CreateTextureBase() {