IndieGame/client/Assets/Ether/Editor/ConfirmWindow.cs
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

86 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************
文件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;
}
}
}