void TextField(MpcArgument args, Func <MpcArgument, string> getter, Action <MpcArgument, string> setter) { var current = getter(args); var newValue = EditorGUILayout.TextField(current); if (newValue != current) { setter(args, newValue); args.Save(); } }
async void OnGUI() { if (!processInitialized) { GUILayout.Label("Check .NET Core SDK/CodeGen install status."); return; } if (mpcArgument == null) { return; } if (!isDotnetInstalled) { GUILayout.Label(".NET Core SDK not found."); GUILayout.Label("MessagePack CodeGen requires .NET Core Runtime."); if (GUILayout.Button("Open .NET Core install page.")) { Application.OpenURL("https://dotnet.microsoft.com/download"); } return; } if (!isInstalledMpc) { GUILayout.Label("MessagePack CodeGen does not instaled."); EditorGUI.BeginDisabledGroup(installingMpc); if (GUILayout.Button("Install MessagePack CodeGen.")) { installingMpc = true; try { var log = await ProcessHelper.InstallMpc(); if (!string.IsNullOrWhiteSpace(log)) { UnityEngine.Debug.Log(log); } if (log != null && log.Contains("error")) { isInstalledMpc = false; } else { isInstalledMpc = true; } } finally { installingMpc = false; } return; } EditorGUI.EndDisabledGroup(); return; } EditorGUILayout.LabelField("-i input path(csproj or directory):"); TextField(mpcArgument, x => x.Input, (x, y) => x.Input = y); EditorGUILayout.LabelField("-o output filepath(.cs) or directory(multiple):"); TextField(mpcArgument, x => x.Output, (x, y) => x.Output = y); EditorGUILayout.LabelField("-m(optional) use map mode:"); var newToggle = EditorGUILayout.Toggle(mpcArgument.UseMapMode); if (mpcArgument.UseMapMode != newToggle) { mpcArgument.UseMapMode = newToggle; mpcArgument.Save(); } EditorGUILayout.LabelField("-c(optional) conditional compiler symbols(split with ','):"); TextField(mpcArgument, x => x.ConditionalSymbol, (x, y) => x.ConditionalSymbol = y); EditorGUILayout.LabelField("-r(optional) generated resolver name:"); TextField(mpcArgument, x => x.ResolverName, (x, y) => x.ResolverName = y); EditorGUILayout.LabelField("-n(optional) namespace root name:"); TextField(mpcArgument, x => x.Namespace, (x, y) => x.Namespace = y); EditorGUILayout.LabelField("-ms(optional) Generate #if-- files by symbols, split with ','"); TextField(mpcArgument, x => x.MultipleIfDirectiveOutputSymbols, (x, y) => x.MultipleIfDirectiveOutputSymbols = y); EditorGUI.BeginDisabledGroup(invokingMpc); if (GUILayout.Button("Generate")) { var commnadLineArguments = mpcArgument.ToString(); UnityEngine.Debug.Log("Generate MessagePack Files, command:" + commnadLineArguments); invokingMpc = true; try { var log = await ProcessHelper.InvokeProcessStartAsync("dotnet", "mpc " + commnadLineArguments); UnityEngine.Debug.Log(log); } finally { invokingMpc = false; } } EditorGUI.EndDisabledGroup(); }