备份CatanBuilding瘦身独立工程
This commit is contained in:
53
Assets/Scripts/UI/ToastPanel.cs
Normal file
53
Assets/Scripts/UI/ToastPanel.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class ToastPanel : MonoBehaviour
|
||||
{
|
||||
private TMP_Text text_toast;
|
||||
private CanvasGroup canvasGroup;
|
||||
static ToastPanel _instance;
|
||||
static bool isShowing = false;
|
||||
public static async void Show(string text)
|
||||
{
|
||||
await ShowInit();
|
||||
if (_instance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_instance.gameObject.SetActive(false);
|
||||
_instance.transform.SetAsLastSibling();
|
||||
_instance.SetToast(text);
|
||||
_instance.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private static async Task ShowInit()
|
||||
{
|
||||
if (!isShowing)
|
||||
{
|
||||
isShowing = true;
|
||||
GameObject loading = await UIManager.Instance.GetUIAsync(UITypes.ToastPanel);
|
||||
|
||||
if (loading != null)
|
||||
{
|
||||
_instance = loading.GetComponent<ToastPanel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
isShowing = false;
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
text_toast = transform.Find("resource/p_text").GetComponent<TMP_Text>();
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
void SetToast(string text)
|
||||
{
|
||||
text_toast.text = text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user