From 01ec2a633c398fe51c4fc280e2724bf3792c93f0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 7 Aug 2020 16:29:44 +0900 Subject: [PATCH] VRMExporterWizard use VRMMetaObjectEditor --- .../UniVRM/Editor/Format/VRMEditorExporter.cs | 10 +- .../UniVRM/Editor/Format/VRMExportSettings.cs | 94 +++++++++---------- .../UniVRM/Editor/Format/VRMExporterWizard.cs | 55 +++++++++-- 3 files changed, 100 insertions(+), 59 deletions(-) diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs index 3bb10dce9..a8c30903b 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMEditorExporter.cs @@ -213,11 +213,11 @@ namespace VRM ExportOnlyBlendShapePosition = settings.OnlyBlendshapePosition, RemoveVertexColor = settings.RemoveVertexColor }); - vrm.extensions.VRM.meta.title = settings.Title; - vrm.extensions.VRM.meta.version = settings.Version; - vrm.extensions.VRM.meta.author = settings.Author; - vrm.extensions.VRM.meta.contactInformation = settings.ContactInformation; - vrm.extensions.VRM.meta.reference = settings.Reference; + // vrm.extensions.VRM.meta.title = settings.Title; + // vrm.extensions.VRM.meta.version = settings.Version; + // vrm.extensions.VRM.meta.author = settings.Author; + // vrm.extensions.VRM.meta.contactInformation = settings.ContactInformation; + // vrm.extensions.VRM.meta.reference = settings.Reference; var bytes = vrm.ToGlbBytes(settings.UseExperimentalExporter ? SerializerTypes.Generated : SerializerTypes.UniJSON); File.WriteAllBytes(path, bytes); diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs index 893824370..10c17bfea 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExportSettings.cs @@ -16,32 +16,32 @@ namespace VRM /// public GameObject Source; - #region Meta - /// - /// エクスポート名 - /// - public string Title; + // #region Meta + // /// + // /// エクスポート名 + // /// + // public string Title; - /// - /// エクスポートバージョン(エクスポートするModelのバージョン) - /// - public string Version; + // /// + // /// エクスポートバージョン(エクスポートするModelのバージョン) + // /// + // public string Version; - /// - /// 作者 - /// - public string Author; + // /// + // /// 作者 + // /// + // public string Author; - /// - /// 作者連絡先 - /// - public string ContactInformation; + // /// + // /// 作者連絡先 + // /// + // public string ContactInformation; - /// - /// 作品引用 - /// - public string Reference; - #endregion + // /// + // /// 作品引用 + // /// + // public string Reference; + // #endregion #region Settings /// @@ -189,18 +189,18 @@ namespace VRM yield return Validation.Warning("There is a bone with the same name in the hierarchy. If exported, these bones will be automatically renamed."); } - if (string.IsNullOrEmpty(Title)) - { - yield return Validation.Error("Require Title. "); - } - if (string.IsNullOrEmpty(Version)) - { - yield return Validation.Error("Require Version. "); - } - if (string.IsNullOrEmpty(Author)) - { - yield return Validation.Error("Require Author. "); - } + // if (string.IsNullOrEmpty(Title)) + // { + // yield return Validation.Error("Require Title. "); + // } + // if (string.IsNullOrEmpty(Version)) + // { + // yield return Validation.Error("Require Version. "); + // } + // if (string.IsNullOrEmpty(Author)) + // { + // yield return Validation.Error("Require Author. "); + // } if (ReduceBlendshape && Source.GetComponent() == null) { @@ -331,19 +331,19 @@ namespace VRM // Meta // var meta = Source == null ? null : go.GetComponent(); - if (meta != null && meta.Meta != null) - { - Title = meta.Meta.Title; - Version = string.IsNullOrEmpty(meta.Meta.Version) ? "0.0" : meta.Meta.Version; - Author = meta.Meta.Author; - ContactInformation = meta.Meta.ContactInformation; - Reference = meta.Meta.Reference; - } - else - { - Title = go.name; - Version = "0.0"; - } + // if (meta != null && meta.Meta != null) + // { + // Title = meta.Meta.Title; + // Version = string.IsNullOrEmpty(meta.Meta.Version) ? "0.0" : meta.Meta.Version; + // Author = meta.Meta.Author; + // ContactInformation = meta.Meta.ContactInformation; + // Reference = meta.Meta.Reference; + // } + // else + // { + // Title = go.name; + // Version = "0.0"; + // } } } } \ No newline at end of file diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs index 60340d3ae..0b52436d2 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs @@ -14,6 +14,29 @@ namespace VRM /// public class VRMExporterWizard : EditorWindow { + [SerializeField] + public VRMExportSettings m_settings = new VRMExportSettings(); + + VRMMetaObject m_meta; + VRMMetaObject Meta + { + get { return m_meta; } + set + { + if (m_meta == value) return; + if (m_meta != null) + { + UnityEditor.Editor.DestroyImmediate(m_metaEditor); + } + m_meta = value; + if (m_meta != null) + { + m_metaEditor = Editor.CreateEditor(m_meta); + } + } + } + + Editor m_metaEditor; Editor m_Inspector; private string m_HelpString = ""; @@ -26,6 +49,7 @@ namespace VRM private void OnDestroy() { UnityEditor.Editor.DestroyImmediate(m_Inspector); + Meta = null; } private void InvokeWizardUpdate() @@ -118,11 +142,17 @@ namespace VRM protected virtual bool DrawWizardGUI() { - if (m_Inspector == null) + if (m_metaEditor != null) { - m_Inspector = Editor.CreateEditor(this); + m_metaEditor.OnInspectorGUI(); + } + { + if (m_Inspector == null) + { + m_Inspector = Editor.CreateEditor(this); + } + m_Inspector.OnInspectorGUI(); } - m_Inspector.OnInspectorGUI(); return true; } @@ -251,12 +281,8 @@ namespace VRM const string EXTENSION = ".vrm"; - VRMMeta m_meta; - private static string m_lastExportDir; - public VRMExportSettings m_settings = new VRMExportSettings(); - public static void CreateWizard() { var wiz = VRMExporterWizard.DisplayWizard( @@ -326,6 +352,21 @@ namespace VRM helpString = helpBuilder.ToString(); errorString = errorBuilder.ToString(); + + if (m_settings.Source == null) + { + Meta = null; + } + else + { + var meta = m_settings.Source.GetComponent(); + if (meta != null) + { + Meta = meta.Meta; + } + } + + Repaint(); } } }