IndieGame/client/Assets/Plugins/zbitmap/zbitmapfont/Editor/InputDialog.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2024-10-22 17:38:59 +08:00
using UnityEditor;
using UnityEngine;
public class InputDialog : EditorWindow
{
private string userInput = "";
private System.Action<string> callback;
public static void ShowWindow(string text, System.Action<string> callback)
{
var dialog = GetWindow<InputDialog>();
dialog.userInput = text;
dialog.callback = callback;
}
public static string Show(string title, string message, string defaultInput)
{
InputDialog window = ScriptableObject.CreateInstance<InputDialog>();
window.titleContent = new GUIContent(title);
window.userInput = defaultInput;
window.ShowModal();
return window.userInput;
}
void OnGUI()
{
EditorGUILayout.LabelField("Message", EditorStyles.wordWrappedLabel);
userInput = EditorGUILayout.TextField("Input", userInput);
GUILayout.BeginHorizontal();
if (GUILayout.Button("OK"))
{
callback?.Invoke(userInput);
this.Close();
}
if (GUILayout.Button("Cancel"))
{
userInput = null;
this.Close();
}
GUILayout.EndHorizontal();
}
}