using UnityEngine; using UnityEngine.UI; using QFramework; using System; using System.Collections; namespace QFramework { public class TimeForCompletingLevelsPanelData : UIPanelData { /// /// 倒计时时间 /// public float m_time; } public partial class TimeForCompletingLevelsPanel : UIPanel { protected override void ProcessMsg(int eventId, QMsg msg) { throw new System.NotImplementedException(); } protected override void OnInit(IUIData uiData = null) { mData = uiData as TimeForCompletingLevelsPanelData ?? new TimeForCompletingLevelsPanelData(); // please add init code here } protected override void OnOpen(IUIData uiData = null) { mData = uiData as TimeForCompletingLevelsPanelData ?? new TimeForCompletingLevelsPanelData(); StopAllCoroutines(); StartCoroutine(StartCountDown(mData.m_time)); } protected override void OnShow() { } protected override void OnHide() { } protected override void OnClose() { } /// /// 开启倒计时 /// /// IEnumerator StartCountDown(float targetTime) { int second = 0; while (second < targetTime * 60) { //等待时间 yield return new WaitForSeconds(1); second++; SetExamTime((targetTime * 60) - second); } ChallengeManagerForPC.instance.EndChallenge(); } /// /// 用时 /// /// public void SetExamTime(float time) { TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(time)); string str = ""; if (ts.Hours > 0) { str = String.Format("{0:00}", ts.Hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds); } if (ts.Hours == 0 && ts.Minutes > 0) { str = "00:" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds); } if (ts.Hours == 0 && ts.Minutes == 0) { str = "00:00:" + String.Format("{0:00}", ts.Seconds); } ExamTime.text = str; } } }