mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-09 12:11:35 -05:00
Importerが対応するまでの簡易な方法 #587
This commit is contained in:
parent
e1690d0681
commit
2db2999a7b
51
Assets/MeshUtility/Editor/TextureSaver.cs
Normal file
51
Assets/MeshUtility/Editor/TextureSaver.cs
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/MeshUtility/Editor/TextureSaver.cs.meta
Normal file
11
Assets/MeshUtility/Editor/TextureSaver.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 01c8541cb3fd27f4882e3d32c37a45aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue
Block a user