12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using UnityEngine;
- using UnityEngine.UI;
- using QFramework;
- using System;
- using System.Collections;
- namespace QFramework
- {
- public class TimeForCompletingLevelsPanelData : UIPanelData
- {
- /// <summary>
- /// 倒计时时间
- /// </summary>
- 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()
- {
- }
- /// <summary>
- /// 开启倒计时
- /// </summary>
- /// <returns></returns>
- IEnumerator StartCountDown(float targetTime)
- {
- int second = 0;
- while (second < targetTime * 60)
- {
- //等待时间
- yield return new WaitForSeconds(1);
-
- second++;
- SetExamTime((targetTime * 60) - second);
- }
- ChallengeManagerForPC.instance.EndChallenge();
- }
- /// <summary>
- /// 用时
- /// </summary>
- /// <param name="time"></param>
- 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;
- }
- }
- }
|