From 2db2999a7b3b89867d95fa00db0c8e624bdbbde0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 28 Oct 2020 17:26:17 +0900 Subject: [PATCH] =?UTF-8?q?Importer=E3=81=8C=E5=AF=BE=E5=BF=9C=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=81=BE=E3=81=A7=E3=81=AE=E7=B0=A1=E6=98=93=E3=81=AA?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20#587?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/MeshUtility/Editor/TextureSaver.cs | 51 +++++++++++++++++++ .../MeshUtility/Editor/TextureSaver.cs.meta | 11 ++++ 2 files changed, 62 insertions(+) create mode 100644 Assets/MeshUtility/Editor/TextureSaver.cs create mode 100644 Assets/MeshUtility/Editor/TextureSaver.cs.meta diff --git a/Assets/MeshUtility/Editor/TextureSaver.cs b/Assets/MeshUtility/Editor/TextureSaver.cs new file mode 100644 index 000000000..cffbd39f0 --- /dev/null +++ b/Assets/MeshUtility/Editor/TextureSaver.cs @@ -0,0 +1,51 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace MeshUtility +{ + public static class EditorChangeTextureType + { + [MenuItem("Assets/SaveAsPng", true)] + static bool IsTextureAsset() + { + return Selection.activeObject is Texture2D; + } + + [MenuItem("Assets/SaveAsPng")] + static void SaveAsPng() + { + var texture = Selection.activeObject as Texture2D; + var path = SaveDialog(texture.name); + if (string.IsNullOrEmpty(path)) + { + return; + } + + File.WriteAllBytes(path, texture.EncodeToPNG()); + Debug.Log($"save: ${path}"); + } + + private static string m_lastExportDir; + static string SaveDialog(string name) + { + string directory; + if (string.IsNullOrEmpty(m_lastExportDir)) + directory = Directory.GetParent(Application.dataPath).ToString(); + else + directory = m_lastExportDir; + + // save dialog + var path = EditorUtility.SaveFilePanel( + "Save png", + directory, + $"{name}.png", + "png"); + if (!string.IsNullOrEmpty(path)) + { + m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/"); + } + return path; + } + } +} diff --git a/Assets/MeshUtility/Editor/TextureSaver.cs.meta b/Assets/MeshUtility/Editor/TextureSaver.cs.meta new file mode 100644 index 000000000..733e8bdc1 --- /dev/null +++ b/Assets/MeshUtility/Editor/TextureSaver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01c8541cb3fd27f4882e3d32c37a45aa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: