You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
11 months ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using UniRx;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using UnityEngine.AddressableAssets;
|
||
|
|
||
|
public class MessageBox : MonoBehaviour
|
||
|
{
|
||
|
|
||
|
private static MessageBox Instance;
|
||
|
|
||
|
public Text Message;
|
||
|
public Button SetButton;
|
||
|
public Button CloseButton;
|
||
|
public Action action;
|
||
|
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
SetButton.OnClickAsObservable()
|
||
|
.Subscribe(_ =>
|
||
|
{
|
||
|
action?.Invoke();
|
||
|
Destroy(gameObject);
|
||
|
});
|
||
|
CloseButton.OnClickAsObservable()
|
||
|
.Subscribe(_ =>
|
||
|
{
|
||
|
Destroy(gameObject);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public static void Show(string info, Color Color, Action action = null)
|
||
|
{
|
||
|
Addressables.LoadAssetAsync<GameObject>("MessageBoxPanel").Completed += Loaded =>
|
||
|
{
|
||
|
Instance = Instantiate(Loaded.Result).GetComponent<MessageBox>();
|
||
|
Instance.transform.SetParent(UIManager.GetCanvas().transform.Find("Popup"), false);
|
||
|
Instance.Message.text = info;
|
||
|
Instance.Message.color = Color;
|
||
|
Instance.action = action;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public static void Show(string info, Color Color, float time)
|
||
|
{
|
||
|
|
||
|
Addressables.LoadAssetAsync<GameObject>("MessageBoxPanel").Completed += Loaded =>
|
||
|
{
|
||
|
Instance = Instantiate(Loaded.Result).GetComponent<MessageBox>();
|
||
|
Instance.transform.SetParent(UIManager.GetCanvas().transform.Find("Popup"), false);
|
||
|
Instance. Message.text = info;
|
||
|
Instance. Message.color = Color;
|
||
|
Instance.StartCoroutine(Instance.ShowCoroutine(time));
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
IEnumerator ShowCoroutine(float time)
|
||
|
{
|
||
|
yield return new WaitForSeconds(time);
|
||
|
Destroy(gameObject);
|
||
|
|
||
|
}
|
||
|
}
|