mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-24 15:08:02 -05:00
MigrationMenu
This commit is contained in:
parent
564727e0f5
commit
24ff0d3fd1
46
Assets/VRM10/Editor/MigrationMenu.cs
Normal file
46
Assets/VRM10/Editor/MigrationMenu.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class MigrationMenu
|
||||
{
|
||||
static string s_lastPath = Application.dataPath;
|
||||
|
||||
const string CONTEXT_MENU = "Assets/Migration: Vrm1";
|
||||
|
||||
[MenuItem(CONTEXT_MENU, true)]
|
||||
static bool Enable()
|
||||
{
|
||||
var path = UniGLTF.UnityPath.FromAsset(Selection.activeObject);
|
||||
var isVrm = path.Extension.ToLower() == ".vrm";
|
||||
return isVrm;
|
||||
}
|
||||
|
||||
[MenuItem(CONTEXT_MENU, false)]
|
||||
static void Exec()
|
||||
{
|
||||
var path = UniGLTF.UnityPath.FromAsset(Selection.activeObject);
|
||||
var isVrm = path.Extension.ToLower() == ".vrm";
|
||||
|
||||
var vrm1Bytes = Migration.Migrate(File.ReadAllBytes(path.FullPath));
|
||||
|
||||
var dst = EditorUtility.SaveFilePanel(
|
||||
"Save vrm1 file",
|
||||
s_lastPath,
|
||||
$"{path.FileName}_vrm1",
|
||||
"vrm");
|
||||
if (string.IsNullOrEmpty(dst))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_lastPath = Path.GetDirectoryName(dst);
|
||||
File.WriteAllBytes(dst, vrm1Bytes);
|
||||
|
||||
// immediately import for GUI update
|
||||
UniGLTF.UnityPath.FromFullpath(dst).ImportAsset();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Editor/MigrationMenu.cs.meta
Normal file
11
Assets/VRM10/Editor/MigrationMenu.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c0be718f3aba6ad4282a4b74eae9045b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue
Block a user