using UnityEditor; using UnityEngine; public class InputDialog : EditorWindow { private string userInput = ""; private System.Action callback; public static void ShowWindow(string text, System.Action callback) { var dialog = GetWindow(); dialog.userInput = text; dialog.callback = callback; } public static string Show(string title, string message, string defaultInput) { InputDialog window = ScriptableObject.CreateInstance(); 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(); } }