UniVRM/Assets/VRM/Editor/Format/VRMImporterMenu.cs
ousttrue b216a5bbc0 メニューの表記、順番調整
- `-1.0` => ` 1.0`
- `Import` and `Export`
- `Export < Import < MeshUtility` order
2023-11-15 18:24:02 +09:00

60 lines
1.8 KiB
C#

using System.IO;
using UnityEditor;
using UnityEngine;
using UniGLTF;
namespace VRM
{
public static class VRMImporterMenu
{
public const string MENU_NAME = "Import VRM 0.x...";
public static void OpenImportMenu()
{
var path = EditorUtility.OpenFilePanel(MENU_NAME + ": open vrm", "", "vrm");
if (string.IsNullOrEmpty(path))
{
return;
}
if (Application.isPlaying)
{
// import vrm to scene without asset creation
ImportRuntime(path);
}
else
{
// import vrm to asset
if (path.StartsWithUnityAssetPath())
{
Debug.LogWarningFormat("disallow import from folder under the Assets");
return;
}
var prefabPath = EditorUtility.SaveFilePanel("save prefab", "Assets", Path.GetFileNameWithoutExtension(path), "prefab");
if (string.IsNullOrEmpty(path))
{
return;
}
vrmAssetPostprocessor.ImportVrmAndCreatePrefab(path, UnityPath.FromFullpath(prefabPath));
}
}
/// <summary>
/// load into scene
/// </summary>
/// <param name="path">vrm path</param>
static void ImportRuntime(string path)
{
using (var data = new GlbFileParser(path).Parse())
using (var context = new VRMImporterContext(new VRMData(data)))
{
var loaded = context.Load();
loaded.EnableUpdateWhenOffscreen();
loaded.ShowMeshes();
Selection.activeGameObject = loaded.gameObject;
}
}
}
}