using Core.Utilities;
|
using System;
|
using TMPro;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using MoreMountains.NiceVibrations;
|
using TowerDefense.Level;
|
using KTGMGemClient;
|
|
/// <summary>
|
/// 无尽模式用自己的EndlessUIStart
|
/// </summary>
|
public class EndlessUIStart : Singleton<EndlessUIStart>
|
{
|
public TextMeshProUGUI countDownTextNew = null;
|
|
public TextMeshProUGUI timeTextNew = null;
|
|
public TextMeshProUGUI timeStatic = null;
|
|
/// <summary>
|
/// 结算界面
|
/// </summary>
|
public GameObject SettlementUI;
|
|
/// <summary>
|
/// 倒计时整体的背景图片Mask
|
/// </summary>
|
public Image uiStartMssk = null;
|
|
public AudioSource bgMusic;
|
|
public static bool bFirstLoaded = false;
|
|
public static bool bGameStart = false;
|
|
protected float secToDo = 3f;
|
|
protected float startTime = 0.0f;
|
|
protected bool bossCreate = false;
|
|
protected bool[] bVibrate;
|
|
private bool isPause;
|
|
// Start is called before the first frame update
|
void Start()
|
{
|
bVibrate = new bool[4];
|
bVibrate[0] = bVibrate[1] = bVibrate[2] = bVibrate[3] = false;
|
|
// 设置为顶层渲染:
|
countDownTextNew.transform.SetAsLastSibling();
|
|
if (timeStatic)
|
timeStatic.gameObject.SetActive(false);
|
EndlessBuffSelect.instance.HideBuffUI();
|
EndlessBossHPManager.instance.HideHP();
|
EndlessSettlement settlement = SettlementUI.transform.GetChild(0).GetComponent<EndlessSettlement>();
|
settlement.Init();
|
SettlementUI.SetActive(false);
|
}
|
|
/// <summary>
|
/// 当前游戏局的开始时间.
|
/// </summary>
|
public float GameStartTime
|
{
|
get { return startTime; }
|
}
|
|
protected string ConvertSec(float sec)
|
{
|
if (sec < 10)
|
return "0" + Math.Floor(sec).ToString();
|
else
|
return Math.Floor(sec).ToString();
|
}
|
|
/// <summary>
|
/// 把当前的秒数变成字符串.
|
/// </summary>
|
/// <param name="sec"></param>
|
/// <returns></returns>
|
protected string ConvertTime(float sec)
|
{
|
if (sec < 60)
|
{
|
return "00:" + ConvertSec(sec);
|
}
|
else
|
{
|
float min = sec / 60;
|
if (min < 10)
|
{
|
return "0" + Math.Floor(min).ToString() + ":" + ConvertSec(sec % 60);
|
}
|
else
|
{
|
return Math.Floor(min).ToString() + ":" + ConvertSec(sec % 60);
|
}
|
}
|
}
|
|
public void Pause()
|
{
|
isPause = true;
|
}
|
|
public void Restart()
|
{
|
isPause = false;
|
}
|
|
public bool IsGameRunning { get { return !isPause; } }
|
|
// Update is called once per frame
|
void Update()
|
{
|
if (isPause) return;
|
|
if (bGameStart)
|
{
|
startTime += Time.deltaTime;
|
timeTextNew.text = ConvertTime((float)Math.Ceiling(startTime));
|
}
|
|
if (!bFirstLoaded && !bGameStart)
|
{
|
bFirstLoaded = true;
|
secToDo = 4;
|
}
|
|
if (bFirstLoaded && !bGameStart)
|
{
|
secToDo -= Time.deltaTime;
|
countDownTextNew.gameObject.SetActive(true);
|
|
if (secToDo >= 3)
|
{
|
countDownTextNew.text = "3";
|
if (!bVibrate[3])
|
{
|
bVibrate[3] = true;
|
MMVibrationManager.Haptic(HapticTypes.SoftImpact);
|
}
|
}
|
else if (secToDo >= 2)
|
{
|
countDownTextNew.text = "2";
|
if (!bVibrate[2])
|
{
|
bVibrate[2] = true;
|
MMVibrationManager.Haptic(HapticTypes.MediumImpact);
|
}
|
}
|
else if (secToDo >= 1)
|
{
|
countDownTextNew.text = "1";
|
if (!bVibrate[1])
|
{
|
bVibrate[1] = true;
|
MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
|
}
|
}
|
else if (secToDo < 1)
|
{
|
countDownTextNew.text = "GO!";
|
if (!bVibrate[0])
|
{
|
bVibrate[0] = true;
|
MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
|
}
|
}
|
|
// 开启游戏,且隐藏中间的数字.
|
if (secToDo <= 0)
|
{
|
uiStartMssk.gameObject.SetActive(false);
|
countDownTextNew.text = "";
|
countDownTextNew.gameObject.SetActive(false);
|
bGameStart = true;
|
// 开始关卡
|
EndlessLevelManager.instance.StartLevel();
|
timeTextNew.gameObject.SetActive(true);
|
|
// 开始播放背景音乐.
|
if (bgMusic != null)
|
bgMusic.Play();
|
}
|
}
|
}
|
}
|