mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-03-24 19:34:42 -05:00
88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using UniGLTF;
|
|
using System.IO;
|
|
using UniGLTF.MeshUtility;
|
|
#if UNITY_2020_2_OR_NEWER
|
|
using UnityEditor.AssetImporters;
|
|
#else
|
|
using UnityEditor.Experimental.AssetImporters;
|
|
#endif
|
|
|
|
|
|
namespace UniVRM10
|
|
{
|
|
[CustomEditor(typeof(VrmScriptedImporter))]
|
|
public class VrmScriptedImporterEditorGUI : ScriptedImporterEditor
|
|
{
|
|
VrmScriptedImporter m_importer;
|
|
GltfParser m_parser;
|
|
VrmLib.Model m_model;
|
|
UniGLTF.Extensions.VRMC_vrm.VRMC_vrm m_vrm;
|
|
|
|
string m_message;
|
|
|
|
public override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
|
|
m_importer = target as VrmScriptedImporter;
|
|
if (!VrmScriptedImporterImpl.TryParseOrMigrate(m_importer.assetPath, m_importer.MigrateToVrm1, out m_parser, out m_message))
|
|
{
|
|
// error
|
|
return;
|
|
}
|
|
if (!UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(m_parser.GLTF.extensions, out m_vrm))
|
|
{
|
|
// error
|
|
m_message = "no vrm1";
|
|
m_parser = null;
|
|
return;
|
|
}
|
|
m_model = ModelReader.Read(m_parser);
|
|
}
|
|
|
|
enum Tabs
|
|
{
|
|
Model,
|
|
Materials,
|
|
Vrm,
|
|
}
|
|
static Tabs s_currentTab;
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
if (!string.IsNullOrEmpty(m_message))
|
|
{
|
|
EditorGUILayout.HelpBox(m_message, MessageType.Error);
|
|
}
|
|
|
|
s_currentTab = TabBar.OnGUI(s_currentTab);
|
|
GUILayout.Space(10);
|
|
|
|
switch (s_currentTab)
|
|
{
|
|
case Tabs.Model:
|
|
base.OnInspectorGUI();
|
|
break;
|
|
|
|
case Tabs.Materials:
|
|
if (m_parser != null && m_vrm != null)
|
|
{
|
|
EditorMaterial.OnGUI(m_importer, m_parser, new Vrm10TextureDescriptorGenerator(m_parser),
|
|
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures",
|
|
assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials");
|
|
}
|
|
break;
|
|
|
|
case Tabs.Vrm:
|
|
if (m_parser != null && m_vrm != null)
|
|
{
|
|
EditorVrm.OnGUI(m_importer, m_parser, m_vrm);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|