Files
MRCS/Assets/_MrCs/Scripts/UI/HUDPanel.cs

106 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using DragonLi.Core;
using LitJson;
using Mirror;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class HUDPanel : MonoBehaviour
{
/// <summary>
/// 倒计时文本
/// </summary>
public TextMeshProUGUI LessTimeText;
/// <summary>
/// 得分文本
/// </summary>
public TextMeshProUGUI ScoreText;
public GameObject Round;
public Sprite[] RoundIcon;
public Image icon;
/// <summary>
/// 血条
/// </summary>
public Image blood2;
public GameObject hitEffect;
/// <summary>
/// 复活倒计时
/// </summary>
public GameObject dieUI;
public static void Show()
{
OverlayUIManager.Ins.Cover("UI/HUDPanel", false);
}
private void Awake()
{
GameLocal.Ins.HitUI = hitEffect;
GameLocal.Ins.DieUI = dieUI;
}
public void Start()
{
EventDispatcher.AddEventListener<int>("ScoreSound", UpdateScore);
EventDispatcher.AddEventListener<float, float>("HpChange", HpChange);
EventDispatcher.AddEventListener<int>("NewWaveStart", NewWaveStart);
LessTimeText.text = GameManager.Ins.GetLessTimeStr();
ScoreText.text = "0";
}
public void HpChange(float currentHp, float maxHp)
{
blood2.fillAmount = currentHp / maxHp;
//DOTween.To(() => blood1.fillAmount, x => blood1.fillAmount = x, currentHp / maxHp, 0.5f);//血量变化
}
public void UpdateScore(int score)
{
ScoreText.text= score.ToString();
}
public void NewWaveStart(int wave)
{
Round.SetActive(true);
StartCoroutine(RoundWaveTime());
}
IEnumerator RoundWaveTime()
{
GameManager.Ins.PlaySound2DRPC("1.1");
int time = 3;
while (time>0)
{
icon.sprite = RoundIcon[time-1];
yield return new WaitForSeconds(1f);
time--;
}
Round.SetActive(false);
}
void Update()
{
if (GameManager.Ins.gameState== GameState.Playing)
{
if (GameManager.Ins.GetLessTimeSeconds() <= 0)
{
LessTimeText.text = "00:00";
}
else
{
LessTimeText.text = GameManager.Ins.GetLessTimeStr();
}
}
}
}