CheckSystem.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using SC;
  7. using LitJson;
  8. namespace SC.Tools.UpdateAPKSystem.CheckSystem
  9. {
  10. public class CheckSystem : SystemBase
  11. {
  12. private static CheckSystem Instant;
  13. public static CheckSystem getInstant {
  14. get {
  15. if (Instant == null) {
  16. Debug.Log("[CheckSystem=====================================]: " + "Instantiate Start");
  17. Instant = Instantiate((GameObject)Resources.Load("Prefabs/CheckSystem")).
  18. GetComponent<CheckSystem>();
  19. Debug.Log("[" + Instant.GetType().ToString() + "]: " + "Instantiate Finish");
  20. }
  21. return Instant;
  22. }
  23. }
  24. public CheckSystemData CheckSystemDataSubSystem { get; set; }
  25. public CheckSystemGetData CheckSystemGetDataSubSystem { get; set; }
  26. public CheckSystemProcessData CheckSystemProcessDataSubSystem { get; set; }
  27. public CanvasUI CanvasUI { get; set; }
  28. /// <summary>
  29. /// 手动升级模式还是自动
  30. /// 手动模式对于Ignor的版本也会去升级
  31. /// 自动模式会忽略Ingnor的版本
  32. /// </summary>
  33. public bool isManualMode { get; set; }
  34. public override void Awake() {
  35. base.Awake();
  36. WebRequestServerForCheckSystem.RegisterGetDataFromWebRequestFailedCallBack(FailCallBack);
  37. WebRequestServerForCheckSystem.RegisterGetDataFromWebRequestErrorCallBack(ErrorCallBack);
  38. WebRequestServerForCheckSystem.RegisterDataFromWebRequestErrorCallBack(DataErrorCallBack);
  39. isManualMode = false;
  40. AddSubSystem(CheckSystemDataSubSystem = CheckSystemData.getInstant);
  41. AddSubSystem(CheckSystemGetDataSubSystem = new CheckSystemGetData());
  42. AddSubSystem(CheckSystemProcessDataSubSystem = new CheckSystemProcessData());
  43. AddSubSystem(CanvasUI = CanvasUI.getInstant);
  44. }
  45. public override void SystemStart() {
  46. base.SystemStart();
  47. ///当手动打开版本检测时,需要显示Canvas面板,当后台打开版本检测时,不需要显示Canvas面板
  48. if (isManualMode == false) {
  49. CanvasUI.SystemStop();
  50. }
  51. }
  52. public override void OnDestroy() {
  53. base.OnDestroy();
  54. WebRequestServerForCheckSystem.UnRegisterGetDataFromWebRequestFailedCallBack(FailCallBack);
  55. WebRequestServerForCheckSystem.UnRegisterGetDataFromWebRequestErrorCallBack(ErrorCallBack);
  56. WebRequestServerForCheckSystem.UnRegisterDataFromWebRequestErrorCallBack(DataErrorCallBack);
  57. }
  58. public static void RegisterCheckFinishCallBack(Action<bool, bool, bool> CheckFinishCallBack) {
  59. Debug.Log("RegisterCheckFinishCallBack");
  60. CheckSystemProcessData.CheckFinishCallBack += CheckFinishCallBack;
  61. }
  62. public static void UnRegisterCheckFinishCallBack(Action<bool, bool, bool> CheckFinishCallBack) {
  63. Debug.Log("UnRegisterCheckFinishCallBack");
  64. CheckSystemProcessData.CheckFinishCallBack -= CheckFinishCallBack;
  65. }
  66. void FailCallBack(JsonData jsonData) {
  67. Debug.Log("[" + GetType().ToString() + "]: " + "FailCallBack");
  68. ///后台检测时 失败不显示Canvas
  69. if (isManualMode == true) {
  70. CanvasUI.SystemStart();
  71. } else {
  72. UpdateAPKSystem.getInstant.SystemStop();
  73. }
  74. }
  75. void ErrorCallBack(JsonData jsonData) {
  76. Debug.Log("[" + GetType().ToString() + "]: " + "ErrorCallBack");
  77. ///后台检测时 出错不显示Canvas
  78. if (isManualMode == true) {
  79. CanvasUI.SystemStart();
  80. } else {
  81. UpdateAPKSystem.getInstant.SystemStop();
  82. }
  83. }
  84. void DataErrorCallBack(JsonData jsonData) {
  85. Debug.Log("[" + GetType().ToString() + "]: " + "DataErrorCallBack");
  86. ///后台检测时 出错不显示Canvas
  87. if (isManualMode == true) {
  88. CanvasUI.SystemStart();
  89. } else {
  90. UpdateAPKSystem.getInstant.SystemStop();
  91. }
  92. }
  93. }
  94. }