From 352b3bc2f60037c927ddf7b56ad9f518fb7dfd87 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 22 Mar 2021 12:28:24 +0900 Subject: [PATCH] =?UTF-8?q?UniGLTFVersion=20=E3=81=8C=E3=80=81=20VRMVersio?= =?UTF-8?q?n=20=E3=81=8B=E3=82=89=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=AB?= =?UTF-8?q?=E6=B1=BA=E3=81=BE=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM/Editor/Format/VRMVersionMenu.cs | 89 ++++++++++++++-------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/Assets/VRM/Editor/Format/VRMVersionMenu.cs b/Assets/VRM/Editor/Format/VRMVersionMenu.cs index a660ed0d6..99b36469b 100644 --- a/Assets/VRM/Editor/Format/VRMVersionMenu.cs +++ b/Assets/VRM/Editor/Format/VRMVersionMenu.cs @@ -3,9 +3,20 @@ using System.Text; using UnityEditor; using UnityEngine; using UniGLTF; +using System; namespace VRM { + /// + /// VersionDialog + /// + /// UniGLTFVersion は、 VRMVersion から自動的に決まる。 + /// + /// Major = 2 + /// Minor = VRMVersion.MINOR - 64 + /// Patch = VRMVersion.PATCH + /// + /// public class VRMVersionMenu : EditorWindow { /// @@ -120,30 +131,50 @@ namespace VRM [SerializeField] string m_vrmVersion; - [SerializeField] - string m_uniGltfVersion; + (int, int, int) m_uniGltfVersion + { + get + { + if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion)) + { + return (2, vrmVersion.Item2 - 64, vrmVersion.Item3); + } + else + { + return (0, 0, 0); + } + } + } static bool TryGetVersion(string src, out (int, int, int) version) { - if (string.IsNullOrEmpty(src)) + try + { + if (string.IsNullOrEmpty(src)) + { + version = default; + return false; + } + + var splitted = src.Split('.'); + if (splitted.Length != 3) + { + version = default; + return false; + } + + version = ( + int.Parse(splitted[0]), + int.Parse(splitted[1]), + int.Parse(splitted[2]) + ); + return true; + } + catch (Exception) { version = default; return false; } - - var splitted = src.Split('.'); - if (splitted.Length != 3) - { - version = default; - return false; - } - - version = ( - int.Parse(splitted[0]), - int.Parse(splitted[1]), - int.Parse(splitted[2]) - ); - return true; } /// @@ -158,24 +189,22 @@ namespace VRM GUILayout.Label("UniGLTF"); GUILayout.Label($"Current version: {UniGLTFVersion.VERSION}"); - m_uniGltfVersion = EditorGUILayout.TextField("Major.Minor.Patch", m_uniGltfVersion); + { + var enabled = GUI.enabled; + GUI.enabled = false; + EditorGUILayout.TextField("Major.Minor.Patch", $"{m_uniGltfVersion}"); + GUI.enabled = enabled; + } GUILayout.Space(30); if (GUILayout.Button("Apply")) { if (TryGetVersion(m_vrmVersion, out (int, int, int) vrmVersion)) { - if (TryGetVersion(m_uniGltfVersion, out (int, int, int) uniGltfVersion)) - { - UpdateVrmVersion(uniGltfVersion, vrmVersion); - UpdateUniGLTFVersion(uniGltfVersion, vrmVersion); - AssetDatabase.Refresh(); - Debug.Log($"{uniGltfVersion}, {vrmVersion}"); - } - else - { - Debug.LogWarning($"InvalidFormat: {m_uniGltfVersion}"); - } + UpdateVrmVersion(m_uniGltfVersion, vrmVersion); + UpdateUniGLTFVersion(m_uniGltfVersion, vrmVersion); + AssetDatabase.Refresh(); + Debug.Log($"{m_uniGltfVersion}, {vrmVersion}"); } else { @@ -228,7 +257,7 @@ namespace VRM { var window = ScriptableObject.CreateInstance(); window.m_vrmVersion = VRMVersion.VERSION; - window.m_uniGltfVersion = UniGLTFVersion.VERSION; + // window.m_uniGltfVersion = UniGLTFVersion.VERSION; window.ShowUtility(); } }