From 6ae2c504bd33fac5b21feb163c55b3f53a862f15 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 4 Jan 2021 17:02:27 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=BC=E3=83=B3?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=83=E3=83=88=E4=BD=9C=E6=88=90=E6=99=82?= =?UTF-8?q?=E3=81=AB=E3=80=81JpegEncode=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E3=81=AE=E3=81=AB=E6=8B=A1=E5=BC=B5=E5=AD=90=E3=81=8C?= =?UTF-8?q?png?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #639 --- Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs b/Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs index d2bc00c114..9be27aa7e7 100644 --- a/Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs +++ b/Assets/VRM/Editor/Meta/VRMMetaObjectEditor.cs @@ -234,7 +234,7 @@ public override void OnInspectorGUI() void TakeScreenShot() { - var dst = SaveDialog(m_target, "png"); + var dst = SaveDialog(m_target, "png", "jpg"); if (string.IsNullOrEmpty(dst)) { return; @@ -251,7 +251,19 @@ void TakeScreenShot() Camera.main.Render(); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); tex.Apply(); - File.WriteAllBytes(dst, tex.EncodeToJPG()); + + var ext = Path.GetExtension(dst).ToLower(); + switch (ext) + { + case ".png": + File.WriteAllBytes(dst, tex.EncodeToPNG()); + break; + + case ".jpg": + File.WriteAllBytes(dst, tex.EncodeToJPG()); + break; + } + var assetPath = MeshUtility.UnityPath.FromFullpath(dst); EditorApplication.delayCall += () => { @@ -268,7 +280,7 @@ void TakeScreenShot() } } - static string SaveDialog(VRMMetaObject meta, string ext) + static string SaveDialog(VRMMetaObject meta, params string[] ext) { var directory = Application.dataPath; var assetPath = AssetDatabase.GetAssetPath(meta); @@ -279,8 +291,8 @@ static string SaveDialog(VRMMetaObject meta, string ext) return EditorUtility.SaveFilePanel( "Save thumbnail", directory, - $"thumbnail.{ext}", - ext); + $"thumbnail.{ext[0]}", + string.Join(",", ext)); } static (Rect, Rect) FixedRight(Rect r, int width)