159 lines
3.5 KiB
C#
159 lines
3.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
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 gunCountTxt;
|
|
|
|
/// <summary>
|
|
/// 枪械种类
|
|
/// </summary>
|
|
public Sprite[] gunIcons;
|
|
|
|
/// <summary>
|
|
/// 枪图片
|
|
/// </summary>
|
|
public Image gunImage;
|
|
|
|
|
|
/// <summary>
|
|
/// 警告节点
|
|
/// </summary>
|
|
public GameObject TimingWarning;
|
|
|
|
/// <summary>
|
|
/// 血条
|
|
/// </summary>
|
|
public Image blood2;
|
|
|
|
public GameObject hitEffect;
|
|
|
|
/// <summary>
|
|
/// 复活倒计时
|
|
/// </summary>
|
|
public GameObject dieUI;
|
|
|
|
public TextMeshProUGUI enemyDieCountTxt;
|
|
|
|
/// <summary>
|
|
/// 下一波倒计时
|
|
/// </summary>
|
|
public GameObject Round;
|
|
|
|
public Sprite[] RoundIcon;
|
|
|
|
public Image icon;
|
|
|
|
public GameObject JoinControlNode;
|
|
public static void Show()
|
|
{
|
|
OverlayUIManager.Ins.Cover("UI/HUDPanel", false);
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
GameLocal.Ins.HitUI = hitEffect;
|
|
GameLocal.Ins.DieUI = dieUI;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
// LoginPanel.Show();
|
|
EventDispatcher.AddEventListener<int>("NewWaveStart", NewWaveStart);
|
|
EventDispatcher.AddEventListener<float, float>("HpChange", HpChange);
|
|
EventDispatcher.AddEventListener<int>("UserGun", UserGun);
|
|
EventDispatcher.AddEventListener<int>("WinRound", ShowWinRound);
|
|
EventDispatcher.AddEventListener<int>("ChangeGunIcon", ChangeGunIcon);
|
|
}
|
|
|
|
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 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.isStart)
|
|
{
|
|
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);
|
|
StartCoroutine(RoundWaveTime());
|
|
}
|
|
|
|
IEnumerator RoundWaveTime()
|
|
{
|
|
int time = 3;
|
|
while (time>0)
|
|
{
|
|
icon.sprite = RoundIcon[time-1];
|
|
yield return new WaitForSeconds(1f);
|
|
time--;
|
|
}
|
|
Round.SetActive(false);
|
|
GameManager.Ins.PlaySound2DRPC("");
|
|
}
|
|
|
|
|
|
public void ChangeGunIcon(int bulletIndex)
|
|
{
|
|
gunImage.sprite = gunIcons[GameLocal.Ins.self.NowGunIndex];
|
|
gunCountTxt.text = bulletIndex.ToString();
|
|
}
|
|
|
|
public void UserGun(int bullet)
|
|
{
|
|
gunCountTxt.text = bullet.ToString();
|
|
}
|
|
|
|
public void ShowWinRound(int index)
|
|
{
|
|
|
|
}
|
|
}
|