74 lines
1.9 KiB
C#
74 lines
1.9 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
namespace Octopus.Simulator.UI.Popup
|
|
{
|
|
public class AlertManager : UnitySingleton<AlertManager>
|
|
{
|
|
private GameObject prefab;
|
|
private UIAlert alert;
|
|
|
|
|
|
private void Create()
|
|
{
|
|
|
|
if (alert == null)
|
|
{
|
|
if (prefab == null)
|
|
{
|
|
prefab = Resources.Load("UIPrefab/UIAlert", typeof(GameObject)) as GameObject;
|
|
}
|
|
GameObject go = UnityEngine.Object.Instantiate(prefab);
|
|
alert = go.GetComponent<UIAlert>();
|
|
}
|
|
var canvas = FindAnyObjectByType<Canvas_Main>();
|
|
alert.transform.SetParent(canvas.transform, false);
|
|
}
|
|
|
|
public async UniTask ShowAlert(string title, string message, string okButtonTitle = "OK")
|
|
{
|
|
Create();
|
|
|
|
bool isClosed = false;
|
|
|
|
alert.Init(title: title, message: message, okButtonText: okButtonTitle, showCancelButton: false);
|
|
alert.OnOk.AddListener(() =>
|
|
{
|
|
isClosed = true;
|
|
});
|
|
alert.Open();
|
|
await UniTask.WaitUntil(() => isClosed == true);
|
|
}
|
|
|
|
public async UniTask<bool> ShowConfirm(string title, string message, string okButtonTitle = "OK", string cancelButtonTitle = "CANCEL")
|
|
{
|
|
Create();
|
|
|
|
bool isClosed = false;
|
|
bool result = false;
|
|
|
|
alert.Init(title, message, okButtonTitle, cancelButtonTitle, true);
|
|
|
|
alert.OnOk.AddListener(() =>
|
|
{
|
|
result = true;
|
|
isClosed = true;
|
|
});
|
|
|
|
alert.OnCancel.AddListener(() =>
|
|
{
|
|
result = false;
|
|
isClosed = true;
|
|
});
|
|
|
|
alert.Open();
|
|
|
|
|
|
await UniTask.WaitUntil(() => isClosed == true);
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
}
|