IndieGame/client/Assets/Ether/Editor/ConfirmWindow.cs

86 lines
2.3 KiB
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
/********************************************************************
ConfirmWindow.cs
1982614048@qq.com
2024/02/21 16:24:12
*********************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Ether
{
/// <summary>
/// 确认框配置
/// </summary>
public static class ConfirmConfig
{
public static string tips; //显示的提示
public static Action confirmAction; //确认回调
public static Action cancelAction; //取消回调
public static void ShowConfirmWindow()
{
if (confirmAction != null)
{
EditorWindow.GetWindowWithRect<ConfirmWindow>(new Rect(0, 0, 300, 100), true, "确认操作", true);
}
}
}
/// <summary>
/// 确认框弹窗
/// </summary>
public class ConfirmWindow : EditorWindow
{
GUIStyle fontTitleStyle = new GUIStyle();
private void Awake()
{
fontTitleStyle.alignment = TextAnchor.MiddleCenter;
fontTitleStyle.fontSize = 15;
fontTitleStyle.normal.textColor = new Color(255, 255, 255);
}
private void OnGUI()
{
GUILayout.BeginVertical();
GUILayout.Space(20);
if (ConfirmConfig.tips == null)
{
ConfirmConfig.tips = "是否确认该操作?";
}
GUILayout.Label(ConfirmConfig.tips, fontTitleStyle);
GUILayout.Space(20);
GUILayout.BeginHorizontal();
GUILayout.Space(50);
if (GUILayout.Button("确定", GUILayout.Width(80)))
{
ConfirmConfig.confirmAction?.Invoke();
Close();
}
GUILayout.Space(50);
if (GUILayout.Button("取消", GUILayout.Width(80)))
{
ConfirmConfig.cancelAction?.Invoke();
Close();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
private void OnDestroy()
{
ConfirmConfig.confirmAction = null;
ConfirmConfig.tips = null;
}
}
}