Forest_Client/Forest/Assets/Editor/Level/CustomPopUpWindow.cs

50 lines
1.2 KiB
C#
Raw Normal View History

2024-06-12 15:01:54 +08:00
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using System;
using UnityEditor;
using UnityEngine;
public class CustomPopUpWindow : EditorWindow
{
private string _content;
private Action _onAgree;
private Action _onDisagree;
public static void PopUp(string content, Action onAgree = null, Action onDisagree = null)
{
CustomPopUpWindow window = ScriptableObject.CreateInstance<CustomPopUpWindow>();
window._content = content;
window._onAgree = onAgree;
window._onDisagree = onDisagree;
window.position = GUIHelper.GetEditorWindowRect().AlignCenter(220, 100);
window.ShowPopup();
}
void OnGUI()
{
GUILayout.Space(10);
EditorGUILayout.LabelField(_content, EditorStyles.wordWrappedLabel);
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Yes!"))
{
_onAgree?.Invoke();
this.Close();
}
if (GUILayout.Button("No!"))
{
_onDisagree?.Invoke();
this.Close();
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
}
}