BITKit/Packages/Runtime~/Unity/Scripts/UX/Alert/UXAlert.cs

52 lines
1.5 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.UIElements;
namespace BITKit.UX
{
[System.Serializable]
public record AlertMessage
{
public string title = "Alert";
public string message = "message";
}
public static class Alert
{
public static void Print(AlertMessage message)
{
UXAlert.Singleton.PrintAlertMessage(message);
}
}
public class UXAlert : MonoBehaviour
{
internal static UXAlert Singleton;
[SerializeField] private UIDocument document;
Label titleLabel;
Label contextLabel;
Button comfirmButton;
private void Awake()
{
Singleton = this;
var container = document.rootVisualElement;
titleLabel = container.Q<Label>(UXConstant.TitleLabel);
contextLabel = container.Q<Label>(UXConstant.ContextLabel);
comfirmButton = container.Q<Button>(UXConstant.MainButton);
comfirmButton.clicked += Close;
Close();
}
internal void PrintAlertMessage(AlertMessage message)
{
document.rootVisualElement.SetActive(true);
titleLabel.text = message.title;
contextLabel.text = message.message;
}
void Close()
{
document.rootVisualElement.SetActive(false);
}
}
}