UniversalViewer/Assets/Scripts/ModelViewerBase/UI/UIPopupMessage.cs

38 lines
1012 B
C#
Raw Permalink Normal View History

2024-04-21 22:38:26 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIPopupMessage : MonoBehaviour
{
public UnityEngine.Events.UnityEvent OnConfirm;
public UnityEngine.Events.UnityEvent OnDeny;
public TMPro.TextMeshProUGUI Text;
public static UIPopupMessage Create(string message, System.Action onConfirm, System.Action onDeny)
{
var popup = Instantiate(SharedResources.Instance.PopupMessage, ModelViewerInterface.GetInstance().MainCanvas.transform);
popup.transform.SetAsLastSibling();
popup.SetMessage(message);
popup.OnConfirm.AddListener(() => onConfirm.Invoke());
popup.OnDeny.AddListener(() => onDeny.Invoke());
return popup;
}
public void SetMessage(string text)
{
Text.text = text;
}
public void Deny()
{
OnDeny?.Invoke();
Destroy(this.gameObject);
}
public void Confirm()
{
OnConfirm?.Invoke();
Destroy(this.gameObject);
}
}