TimeForCompletingLevelsPanel.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using QFramework;
  4. using System;
  5. using System.Collections;
  6. namespace QFramework
  7. {
  8. public class TimeForCompletingLevelsPanelData : UIPanelData
  9. {
  10. /// <summary>
  11. /// 倒计时时间
  12. /// </summary>
  13. public float m_time;
  14. }
  15. public partial class TimeForCompletingLevelsPanel : UIPanel
  16. {
  17. protected override void ProcessMsg(int eventId, QMsg msg)
  18. {
  19. throw new System.NotImplementedException();
  20. }
  21. protected override void OnInit(IUIData uiData = null)
  22. {
  23. mData = uiData as TimeForCompletingLevelsPanelData ?? new TimeForCompletingLevelsPanelData();
  24. // please add init code here
  25. }
  26. protected override void OnOpen(IUIData uiData = null)
  27. {
  28. mData = uiData as TimeForCompletingLevelsPanelData ?? new TimeForCompletingLevelsPanelData();
  29. StopAllCoroutines();
  30. StartCoroutine(StartCountDown(mData.m_time));
  31. }
  32. protected override void OnShow()
  33. {
  34. }
  35. protected override void OnHide()
  36. {
  37. }
  38. protected override void OnClose()
  39. {
  40. }
  41. /// <summary>
  42. /// 开启倒计时
  43. /// </summary>
  44. /// <returns></returns>
  45. IEnumerator StartCountDown(float targetTime)
  46. {
  47. int second = 0;
  48. while (second < targetTime * 60)
  49. {
  50. //等待时间
  51. yield return new WaitForSeconds(1);
  52. second++;
  53. SetExamTime((targetTime * 60) - second);
  54. }
  55. ChallengeManagerForPC.instance.EndChallenge();
  56. }
  57. /// <summary>
  58. /// 用时
  59. /// </summary>
  60. /// <param name="time"></param>
  61. public void SetExamTime(float time)
  62. {
  63. TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(time));
  64. string str = "";
  65. if (ts.Hours > 0)
  66. {
  67. str = String.Format("{0:00}", ts.Hours) + ":" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
  68. }
  69. if (ts.Hours == 0 && ts.Minutes > 0)
  70. {
  71. str = "00:" + String.Format("{0:00}", ts.Minutes) + ":" + String.Format("{0:00}", ts.Seconds);
  72. }
  73. if (ts.Hours == 0 && ts.Minutes == 0)
  74. {
  75. str = "00:00:" + String.Format("{0:00}", ts.Seconds);
  76. }
  77. ExamTime.text = str;
  78. }
  79. }
  80. }