Files
KOF/Assets/_KOF/Scripts/UI/HUDPanel.cs

134 lines
3.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
}
//修改
//获取剩余时间并处理倒计时
float remainingTime = GameManager.Ins.GetLessTimeSeconds();
if (remainingTime <= 0)
{
//确保游戏结束逻辑只触发一次
if (GameManager.Ins.gameState == GameState.Playing)
{
GameManager.Ins.GameOver(GameState.Failur);
}
LessTimeText.text = "00:00";//强制设置为0000
}
else
{
//正常更新时间显示
LessTimeText.text = GameManager.Ins.GetLessTimeStr();
//警告提示
if (remainingTime <= 60)
{
TimingWarning.SetActive(true);
}
}
//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);
}
}