Files
Loong/Assets/_Loong/Scripts/UI/HUDPanel.cs
2025-07-01 14:54:02 +08:00

110 lines
3.0 KiB
C#

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;
/// <summary>
/// 警告节点
/// </summary>
public GameObject TimingWarning;
/// <summary>
/// 第几波显示
/// </summary>
public GameObject Round;
public Sprite[] RoundIcon;
public Image icon;
public GameObject JoinControlNode;
public static void Show()
{
OverlayUIManager.Ins.Cover("UI/HUDPanel", false);
}
public void Start()
{
// LoginPanel.Show();
// EventDispatcher.AddEventListener<int>("NewWaveStart", NewWaveStart);
// //打开联控动画
// EventDispatcher.AddEventListener<int>("JoinControlStart", JoinControlStart);
// //关闭联控动画
// EventDispatcher.AddEventListener<int>("JoinControlEnd", JoinControlEnd);
}
public void JoinControlStart(int playerIndex)
{
// if (GameLocal.Ins.self.index == playerIndex)
// {
// JoinControlNode.SetActive(true);
// }
}
public void JoinControlEnd(int playerIndex)
{
// if (GameLocal.Ins.self.index == playerIndex)
// {
// JoinControlNode.SetActive(false);
// }
}
// Update is called once per frame
void Update()
{
if (GameManager.Ins.gameState == GameState.Playing)
{
Dictionary<string, SettleInfo> tempDictionary = JsonMapper.ToObject<Dictionary<string, SettleInfo>>(GameManager.Ins.settleData);
if (tempDictionary != null)
{
Dictionary<int, SettleInfo> playerDictionary = new Dictionary<int, SettleInfo>();
foreach (var entry in tempDictionary)
{
int key = int.Parse(entry.Key);
playerDictionary[key] = entry.Value;
}
// ScoreText.text = playerDictionary[GameLocal.Ins.self.index].Score.ToString();
}
if (GameManager.Ins.GetLessTimeSeconds() <= 60)
{
//时间警告提示出现
TimingWarning.SetActive(true);
}
if (GameManager.Ins.GetLessTimeSeconds() <= 0)
{
GameManager.Ins.GameOver(GameState.Failur);
LessTimeText.text = "00:00";
}
else
{
LessTimeText.text = GameManager.Ins.GetLessTimeStr();
}
}
}
public void NewWaveStart(int wave)
{
Round.SetActive(true);
icon.sprite = RoundIcon[GameManager.Ins.roundIndex];
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
{
Round.SetActive(false);
}, 4f);
}
}