86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
/********************************************************************
|
||
文件: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;
|
||
}
|
||
}
|
||
|
||
}
|