UpdateAPKSystem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using SC;
  7. using SC.Tools.UpdateAPKSystem.CheckSystem;
  8. using SC.Tools.UpdateAPKSystem.UpdateSystem;
  9. namespace SC.Tools.UpdateAPKSystem
  10. {
  11. public class UpdateAPKSystem : SystemBase
  12. {
  13. public CheckSystem.CheckSystem checkSystem;
  14. public UpdateSystem.UpdateSystem updateSystem;
  15. public AndroidPluginManifest androidPluginManifest;
  16. public AndroidPluginUpdateAPK androidPluginUpdateAPK;
  17. private static UpdateAPKSystem mInstant;
  18. public static UpdateAPKSystem getInstant {
  19. get {
  20. if (mInstant == null) {
  21. Debug.Log("[UpdateAPKSystem=====================================]: " + "Instantiate Start");
  22. mInstant = Instantiate((GameObject)Resources.Load("Prefabs/UpdataAPKSystem")).
  23. GetComponent<UpdateAPKSystem>();
  24. Debug.Log("[" + mInstant.GetType().ToString() + "]: " + "Instantiate Finish");
  25. }
  26. return mInstant;
  27. }
  28. }
  29. public override void Awake() {
  30. if (mInstant) {
  31. DestroyImmediate(gameObject);
  32. return;
  33. }
  34. base.Awake();
  35. mInstant = this;
  36. DontDestroyOnLoad(gameObject);
  37. CheckSystem.CheckSystem.RegisterCheckFinishCallBack(CheckFinishCallBack);
  38. AddSubSystem(androidPluginUpdateAPK = AndroidPluginUpdateAPK.getInstant);
  39. AddSubSystem(androidPluginManifest = AndroidPluginManifest.getInstant);
  40. AddSubSystem(checkSystem = CheckSystem.CheckSystem.getInstant);
  41. AddSubSystem(updateSystem = UpdateSystem.UpdateSystem.getInstant);
  42. }
  43. public override void OnDestroy() {
  44. base.OnDestroy();
  45. CheckSystem.CheckSystem.UnRegisterCheckFinishCallBack(CheckFinishCallBack);
  46. }
  47. void CheckFinishCallBack(bool hasNewVersion, bool isForceUpdate,bool isIgnorUpdate) {
  48. Debug.Log("[" + GetType().ToString() + "]: " + "CheckFinishCallBack:hasNewVersion:"+ hasNewVersion+" isForceUpdate:"+ isForceUpdate
  49. + " isIgnorUpdate:" + isIgnorUpdate+" isManualMode:"+ checkSystem.isManualMode);
  50. if (hasNewVersion == false) {
  51. Debug.Log("[" + GetType().ToString() + "]: " + "hasNewVersion == false ,CloseUpdateAPKSystem");
  52. SystemStop();
  53. return;
  54. }
  55. if (isIgnorUpdate && checkSystem.isManualMode==false) {
  56. Debug.Log("[" + GetType().ToString() + "]: " + "isIgnorUpdate == true ,CloseUpdateAPKSystem");
  57. SystemStop();
  58. return;
  59. }
  60. Debug.Log("[" + GetType().ToString() + "]: " + "Go To UpdateSystem !");
  61. checkSystem.SystemStop();
  62. updateSystem.SystemStart();
  63. return;
  64. }
  65. ///后台打开版本检测API,不需要显示Canvas面板
  66. public override void SystemStart() {
  67. base.SystemStart();
  68. updateSystem.SystemStop();
  69. }
  70. public override void SystemStop() {
  71. base.SystemStop();
  72. checkSystem.isManualMode = false;
  73. }
  74. /// <summary>
  75. /// 当手动打开版本检测API,需要显示Canvas面板
  76. /// </summary>
  77. public void Run() {
  78. checkSystem.isManualMode = true;
  79. SystemStart();
  80. }
  81. /// <summary>
  82. /// 后台自动运行时API,检测有问题不显示Canvas面板,除有更新出现才会显示Canvas面板
  83. /// </summary>
  84. public void RunSilent() {
  85. checkSystem.isManualMode = false;
  86. SystemStart();
  87. }
  88. /// <summary>
  89. /// 停用检测API
  90. /// </summary>
  91. public void Stop() {
  92. SystemStop();
  93. }
  94. }
  95. }