TapTapChinaVerifyFinishPanelController.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections;
  3. using TapSDK.UI;
  4. using TapTap.AntiAddiction.Model;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. namespace TapTap.AntiAddiction.Internal {
  8. public class TapTapChinaVerifyFinishPanelController : BasePanelController
  9. {
  10. public Text titleText;
  11. public Text contentText;
  12. public Text closeTipText;
  13. public Button okButton;
  14. public Button closeButton;
  15. private float _closeTime = 5.0f;
  16. private float _elapse;
  17. private Action OnOk;
  18. /// <summary>
  19. /// bind ugui components for every panel
  20. /// </summary>
  21. protected override void BindComponents()
  22. {
  23. titleText = transform.Find("Root/TitleText").GetComponent<Text>();
  24. contentText = transform.Find("Root/ContentText").GetComponent<Text>();
  25. closeTipText = transform.Find("Root/CloseTipText").GetComponent<Text>();
  26. okButton = transform.Find("Root/OKButton").GetComponent<Button>();
  27. closeButton = transform.Find("Root/CloseButton").GetComponent<Button>();
  28. }
  29. protected override void OnLoadSuccess()
  30. {
  31. base.OnLoadSuccess();
  32. okButton.onClick.AddListener(OnOKButtonClicked);
  33. closeButton.onClick.AddListener(OnOKButtonClicked);
  34. _elapse = 0;
  35. StartCoroutine(Countdown());
  36. }
  37. internal void Show(PayableResult payable, Action onOk = null)
  38. {
  39. // if (payable != null)
  40. // {
  41. // titleText.text = payable.Title;
  42. // contentText.text = payable.Content
  43. // ?.Replace("<font color=", "<color=")
  44. // .Replace("</font>", "</color>")
  45. // .Replace("<br>", "\n");
  46. // }
  47. OnOk = onOk;
  48. }
  49. private void OnOKButtonClicked()
  50. {
  51. OnOk?.Invoke();
  52. Close();
  53. }
  54. IEnumerator Countdown()
  55. {
  56. int remainTime = 0;
  57. do
  58. {
  59. remainTime = Mathf.CeilToInt(_closeTime - _elapse);
  60. closeTipText.text = $"即将关闭当前页面({remainTime}s)";
  61. yield return new WaitForSeconds(1);
  62. _elapse++;
  63. } while (remainTime > 0);
  64. OnOk?.Invoke();
  65. Close();
  66. }
  67. }
  68. }