Login.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import HotUpdate, { HotOptions } from "../../../mk/sdk/HotUpdate";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import LoadingBar from "../../component/LoadingBar";
  4. const { ccclass, property } = cc._decorator;
  5. @ccclass
  6. export default class Login extends cc.Component {
  7. @property(LoadingBar)
  8. private bar: LoadingBar = null;
  9. @property({ displayName: '加载文字', type: cc.Label })
  10. private lbl_progress: cc.Label = null;
  11. @property({ displayName: '服务协议', type: cc.Label })
  12. private lbl_server: cc.Label = null;
  13. @property({ displayName: '隐私协议', type: cc.Label })
  14. private lbl_privacy: cc.Label = null;
  15. @property({ type: cc.Asset })
  16. private manifest: cc.Asset = null;
  17. /** 是否检查热更 */
  18. hasCheck = false
  19. private updateFinish = false;
  20. onLoad() {
  21. this.setProgress(0);
  22. let options = new HotOptions();
  23. options.OnUpdateProgress = (event: jsb.EventAssetsManager) => {
  24. let bytes = event.getDownloadedBytes() + '/' + event.getTotalBytes();
  25. let files = event.getDownloadedFiles() + '/' + event.getTotalFiles();
  26. let file = event.getPercentByFile().toFixed(2);
  27. let byte = event.getPercent().toFixed(2);
  28. let msg = event.getMessage();
  29. this.bar.setProgress(parseFloat(file) * 0.01);
  30. this.lbl_progress.string = '更新中 ' + parseFloat(file) + "%";
  31. console.log(msg);
  32. };
  33. options.OnNeedToUpdate = (data) => {
  34. setTimeout(() => {
  35. HotUpdate.hotUpdate();
  36. }, 500);
  37. };
  38. options.OnNoNeedToUpdate = () => {
  39. this.updateFinish = true;
  40. };
  41. options.OnUpdateFailed = () => {
  42. setTimeout(() => {
  43. HotUpdate.checkUpdate();
  44. }, 300);
  45. };
  46. options.OnUpdateSucceed = () => {
  47. cc.audioEngine.stopAll();
  48. cc.game.restart();
  49. };
  50. HotUpdate.init(this.manifest, options);
  51. }
  52. start() {
  53. if (JsbSystem.getWxAppId()) {
  54. //获取微信id
  55. gData.appData.appId = JsbSystem.getWxAppId();
  56. }
  57. //获取设备信息
  58. JsbSystem.getDeviceInfo();
  59. }
  60. private setProgress(current) {
  61. this.bar.setProgress(current);
  62. this.lbl_progress.string = "加载不消耗流量 " + current + "%";
  63. }
  64. private process: number = 0;
  65. update() {
  66. if (this.hasCheck && !this.updateFinish) {
  67. }
  68. else {
  69. if (this.process < 100) {
  70. this.process += 2;
  71. this.setProgress(this.process);
  72. }
  73. }
  74. //检查热更新
  75. if (!this.hasCheck) {
  76. HotUpdate.checkUpdate();
  77. this.hasCheck = true
  78. console.log('MMM updateFinish NO ')
  79. return
  80. }
  81. if (!this.updateFinish) {
  82. console.log('MMM updateFinish state false')
  83. return
  84. }
  85. if (gData.loginData.loadResCompelete) {
  86. if (gData.appData.getDeviceInfoCompelete) {
  87. this.login();
  88. gData.appData.getDeviceInfoCompelete = false;
  89. }
  90. else if (gData.gameData.dataFinish) {//登录流程完毕
  91. if (gData.gameData.isNewPlayer()) {
  92. mk.ui.openPanel("module/agreementTip/agreementTip");
  93. }
  94. else {
  95. mk.ui.openPanel("game/prefab/game");
  96. }
  97. gData.gameData.dataFinish = false;
  98. }
  99. }
  100. else {
  101. gData.loginData.loadLocalRes();
  102. }
  103. }
  104. public login() {
  105. //初始化相关数据
  106. mk.pool.init(gData.gameData.pools);
  107. //取消构造的时候自动初始化,手动初始化
  108. mk.ad.init();
  109. gData.appData.init();
  110. gData.adData.init();
  111. gData.loginData.init();
  112. console.log("[FC] gData.appData.appId", gData.appData.appId);
  113. //登录
  114. gData.loginData.login();
  115. }
  116. }