From ae9273f228751e1d58c3c9709c73daf51a961bdb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 20 Jul 2020 15:39:19 +0900 Subject: [PATCH] VRMVersionMenu to EditorWindow --- .../UniVRM/Editor/Format/VRMVersionMenu.cs | 80 ++++++++++++------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMVersionMenu.cs b/Assets/VRM/UniVRM/Editor/Format/VRMVersionMenu.cs index 386c9d414..8cf3b08af 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMVersionMenu.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMVersionMenu.cs @@ -1,10 +1,10 @@ using System.IO; using UnityEditor; - +using UnityEngine; namespace VRM { - public static class VRMVersionMenu + public class VRMVersionMenu : EditorWindow { const string path = "Assets/VRM/UniVRM/Scripts/Format/VRMVersion.cs"; const string template = @" @@ -15,45 +15,63 @@ namespace VRM public const int MAJOR = {0}; public const int MINOR = {1}; public const int PATCH = {2}; - public const string PRE_ID = ""{3}""; - - public const string VERSION = ""{0}.{1}.{2}{4}""; + public const string VERSION = ""{0}.{1}.{2}""; }} }} "; -#if VRM_DEVELOP - [MenuItem(VRMVersion.MENU + "/Increment")] -#endif - static void IncrementVersion() + [SerializeField] + string m_version; + + void OnGUI() { - var source = string.Format( - template, - VRMVersion.MAJOR, - VRMVersion.MINOR + 1, - VRMVersion.PATCH, - VRMVersion.PRE_ID, - VRMVersion.PRE_ID != "" ? string.Format("-{0}", VRMVersion.PRE_ID) : "" - ); - File.WriteAllText(path, source); - AssetDatabase.Refresh(); + GUILayout.Label($"Current version: {VRMVersion.VERSION}"); + + m_version = EditorGUILayout.TextField("Major.Minor.Patch", m_version); + + if (GUILayout.Button("Apply")) + { + if (string.IsNullOrEmpty(m_version)) + { + return; + } + var splitted = m_version.Split('.'); + if (splitted.Length != 3) + { + Debug.LogWarning($"InvalidFormat: {m_version}"); + return; + } + var values = new int[3]; + for (int i = 0; i < 3; ++i) + { + values[i] = int.Parse(splitted[i]); + } + + // generate new VRMVersion.cs + var source = string.Format( + template, + values[0], + values[1], + values[2] + ); + File.WriteAllText(path, source); + AssetDatabase.Refresh(); + } + + if (GUILayout.Button("Close")) + { + Close(); + } } #if VRM_DEVELOP - [MenuItem(VRMVersion.MENU + "/Decrement")] + [MenuItem(VRMVersion.MENU + "/VersionDialog")] #endif - static void DecrementVersion() + static void ShowVersionDialog() { - var source = string.Format( - template, - VRMVersion.MAJOR, - VRMVersion.MINOR - 1, - VRMVersion.PATCH, - VRMVersion.PRE_ID, - VRMVersion.PRE_ID != "" ? string.Format("-{0}", VRMVersion.PRE_ID) : "" - ); - File.WriteAllText(path, source); - AssetDatabase.Refresh(); + var window = ScriptableObject.CreateInstance(); + window.m_version = VRMVersion.VERSION; + window.ShowUtility(); } } }