Health/Assets/Scripts/UI/HudUI.cs

66 lines
1.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HudUI : UIHudBase
{
private static Queue<Msg> _msgHintQueue = new Queue<Msg>();
private NotificationPopupUI _hintPannel;
private bool _isHintShowing = false;
private void Awake()
{
_hintPannel = transform.Find("PopupNotification").GetComponent<NotificationPopupUI>();
_hintPannel.GetComponent<CanvasGroup>().alpha = 0;
_msgHintQueue.Clear();
}
private void OnEnable()
{
EventManager.Instance.AddEventListener(YogaEventType.ShowHint, PushHint);
}
private void OnDisable()
{
EventManager.Instance.RemoveEventListener(YogaEventType.ShowHint, PushHint);
}
private void PushHint(object[] args)
{
var msg = new Msg();
if (args.Length < 2)
throw new Exception("²ÎÊý´íÎó");
msg.Title = args[0].ToString();
msg.Content = args[1].ToString();
_msgHintQueue.Enqueue(msg);
}
public override void Init(object[] pageData)
{
base.Init(pageData);
}
private void Update()
{
if (_msgHintQueue.Count > 0 && !_isHintShowing)
{
var msg = _msgHintQueue.Dequeue();
StartCoroutine(ShowHint(msg));
}
}
private IEnumerator ShowHint(Msg msg)
{
_isHintShowing = true;
yield return _hintPannel.Show(msg.Title, msg.Content);
_isHintShowing = false;
}
}
internal class Msg
{
public string Title { get; set; }
public string Content { get; set; }
}