using Core.Utilities; using System; using System.Collections; using System.Collections.Generic; using TMPro; using TowerDefense.UI.HUD; using UnityEngine; using UnityEngine.UI; using MoreMountains.NiceVibrations; using TowerDefense.Level; using DG.Tweening; public class UIStart : Singleton { public BuildSidebar buildSideBar = null; public TextMeshProUGUI countDownTextNew = null; public TextMeshProUGUI timeTextNew = null; public TextMeshProUGUI timeStatic = null; public Image bossPic = null; // 对应的Boss图片 public Image uiStartMssk = null;// 倒计时整体的背景图片Mask /// /// 怪物刷新加速。 /// public Image firstSpeedBg; public Image firstSpeedCent; public Image secondSpeedBg; public Image secondSpeedCent; public AudioSource bgMusic; public static float Max_GameTime = 50f;// 每一局的最长时间,用于界面显示倒计时. 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; // 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); //timeTextNew.gameObject.SetActive(false); bossPic.gameObject.SetActive(false); } if( firstSpeedBg) { firstSpeedBg.gameObject.SetActive(false); secondSpeedBg.gameObject.SetActive(false); } } /// /// 当前游戏局的开始时间. /// public float gameStartTime { get { return this.startTime; } } protected string convertSec( float sec) { if (sec < 10) return "0" + Math.Floor( sec ).ToString(); else return Math.Floor(sec).ToString(); } /// /// 把当前的秒数变成字符串. /// /// /// protected string convertTime( float sec) { if( sec < 60) { return "00:" + this.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 SetFirstSpeedUp() { firstSpeedBg.gameObject.SetActive(true); firstSpeedBg.color = new Color(1, 1, 1, 0); firstSpeedCent.color = new Color(1, 1, 1, 0); //设置一个DOTween队列 Sequence seq = DOTween.Sequence(); seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1), 0.3f)); seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1), 0.3f)); seq.AppendInterval(0.2f); seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.AppendInterval(0.2f); seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Append(firstSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.Join(firstSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.AppendInterval(0.2f); seq.Append(firstSpeedCent.DOColor(new Color(1, 1, 1, 0), 0.5f)); } /// /// 设置第二次加速 /// public void SetSecondSpeedUp() { firstSpeedBg.gameObject.SetActive(false); secondSpeedBg.gameObject.SetActive(true); secondSpeedBg.gameObject.SetActive(true); secondSpeedBg.color = new Color(1, 1, 1, 0); secondSpeedCent.color = new Color(1, 1, 1, 0); //设置一个DOTween队列 Sequence seq = DOTween.Sequence(); seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1), 0.3f)); seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1), 0.3f)); seq.AppendInterval(0.2f); seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.AppendInterval(0.2f); seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 0.2f), 0.25f)); seq.Append(secondSpeedBg.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.Join(secondSpeedCent.DOColor(new Color(1, 1, 1, 1.0f), 0.25f)); seq.AppendInterval(0.2f); seq.Append(secondSpeedCent.DOColor(new Color(1, 1, 1, 0), 0.5f)); } // Update is called once per frame void Update() { if( bGameStart) { startTime += Time.deltaTime; float finalTime = startTime; // Max_GameTime - startTime; /*if (finalTime <= 0) { if( !bossCreate) { bossCreate = true; AgentInsManager.instance.moveAllAgentToCenter(); } finalTime = 0; }*/ this.timeTextNew.text = this.convertTime( (float)Math.Ceiling( finalTime ) ); } if ((!bFirstLoaded)&&(!bGameStart)) { bFirstLoaded = true; secToDo = 4; } if(bFirstLoaded && (!bGameStart)) { secToDo -= (Time.deltaTime * 1.0f); // 放慢时间用于调试 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); } uiStartMssk.gameObject.SetActive(false); } // 开启游戏,且隐藏中间的数字. if( secToDo <= 0) { if (this.buildSideBar) { buildSideBar.StartWaveButtonPressed(); } countDownTextNew.text = ""; // 双方兵线都开始出兵. LevelManager.instance.BuildingCompleted(); OpponentMgr.instance.StartWaves(); timeTextNew.gameObject.SetActive(true); //timeStatic.gameObject.SetActive(true); //bossPic.gameObject.SetActive(true); bGameStart = true; // 开始播放背景音乐. if (bgMusic != null) bgMusic.Play(); } } } }