LaunchCtrl.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. require('Init');
  2. // 闪屏ctrl
  3. cc.Class({
  4. editor: {
  5. menu: 'Launch/LaunchCtrl'
  6. },
  7. extends: cc.Component,
  8. properties: {
  9. audioClip: {
  10. default: undefined,
  11. type: cc.AudioClip
  12. },
  13. splashBg: {
  14. default: undefined,
  15. type: cc.Node
  16. }
  17. },
  18. onLoad () {
  19. // 监听网络协议加载完成消息
  20. cc.game.on('e_nwk_socket_sproto_done', this.handleSocketSprotoDone, this);
  21. cc.game.on('e_nwk_http_sproto_done', this.handleHttpSprotoDone, this);
  22. cc.game.on('e_mgr_load_config_done', this.handleLoadConfigDone, this);
  23. this.initNetwork();
  24. this.initLogin();
  25. },
  26. /** 初始化流程 */
  27. initLogin (){
  28. this.loadLoginScene();
  29. this.loadAllConfig();
  30. this.getRemoteUpdateInfo();
  31. // 初始化完成检测
  32. this.schedule(() => {
  33. if (this.initNetworkDone &&
  34. this.loadLoginSceneDone &&
  35. this.loadAllConfigDone &&
  36. this.getRemoteUpdateInfoDone
  37. ) {
  38. // 全部初始化完成
  39. G.LogUtils.log('[LaunchCtrl] 全部初始化完成');
  40. if (cc.sys.isNative) {
  41. G.AppUtils.runScene('scene_update_remote_info');
  42. } else {
  43. G.AppUtils.runScene('scene_login');
  44. }
  45. }
  46. }, 0.1);
  47. },
  48. // 加载登录场景
  49. loadLoginScene () {
  50. if (cc.sys.isNative) {
  51. cc.director.preloadScene('scene_update_remote_info', () => {
  52. this.loadLoginSceneDone = true;
  53. G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
  54. });
  55. } else {
  56. cc.director.preloadScene('scene_login', () => {
  57. this.loadLoginSceneDone = true;
  58. G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
  59. });
  60. }
  61. },
  62. // 加载牌局场景
  63. preloadResources () {
  64. let preloadScene = [
  65. 'scene_home', // 大厅
  66. 'scene_table' // 牌桌
  67. ];
  68. // 新手引导 包含在大厅场景中
  69. let preloadPrefab = [
  70. 'edt_prefab/notice/prefab_notice_alert', // 公告
  71. 'edt_prefab/activity/004/prefab_activity_004001_alert', // 每周签到
  72. 'edt_prefab/activity/015/prefab_activity_015001_alert', // 欢乐转盘
  73. 'edt_prefab/package/package2102/prefab_package_ui_1', // 白赚礼包
  74. 'edt_prefab/activity/014/prefab_activity_014001_alert', // 复购活动
  75. 'edt_prefab/rankmatch/prefab_rankmatch_alert', // 赢话费
  76. 'edt_prefab/qjb/prefab_qjb_special_alert' // 趣金币专场
  77. ];
  78. // 预加载场景
  79. for (const sceneName of preloadScene) {
  80. cc.director.preloadScene(sceneName, (error, asset) => {
  81. if (error) {
  82. G.LogUtils.error('[LaunchCtrl] preload Scene error:' + error);
  83. } else {
  84. G.LogUtils.log('[LaunchCtrl] preload Scene ' + sceneName + ' done!');
  85. }
  86. });
  87. }
  88. // 预加载预制体
  89. for (const prefabName of preloadPrefab) {
  90. cc.loader.loadRes(prefabName, cc.Prefab, (error, asset) => {
  91. if (error) {
  92. G.LogUtils.error('[LaunchCtrl] preload Prefab error:' + error);
  93. } else {
  94. G.LogUtils.log('[LaunchCtrl] preload Prefab ' + prefabName + ' done!');
  95. }
  96. });
  97. }
  98. },
  99. // 初始化网络层
  100. initNetwork () {
  101. if (!G.DID_GAME_INIT) {
  102. G.DID_GAME_INIT = true;
  103. // 初始化连接配置
  104. G.NetworkMgr.initConn();
  105. }
  106. },
  107. // 加载全部的配置
  108. loadAllConfig () {
  109. G.MgrUtils.loadAllConfig();
  110. },
  111. // 更新检测,目前暂时跳过
  112. getRemoteUpdateInfo () {
  113. // 初始化更新模块
  114. if (cc.sys.isNative) {
  115. // 请求远程更新信息
  116. G.RemoteUpdateInfoMgr.requestRemoteUpdateInfo((ok, errorMsg) => {
  117. this.getRemoteUpdateInfoDone = true;
  118. });
  119. } else {
  120. // 非原生平台不需要热更新
  121. this.getRemoteUpdateInfoDone = true;
  122. G.RemoteUpdateInfoMgr.requestRemoteUpdateInfo();
  123. G.LogUtils.log('[LaunchCtrl] getRemoteUpdateInfoDone');
  124. }
  125. },
  126. onDestroy () {
  127. cc.game.targetOff(this);
  128. },
  129. handleSocketSprotoDone () {
  130. this.socketSprotoDone = true;
  131. if (this.httpSprotoDone) {
  132. this.initNetworkDone = true;
  133. G.LogUtils.log('[LaunchCtrl] initNetworkDone');
  134. }
  135. },
  136. handleHttpSprotoDone () {
  137. this.httpSprotoDone = true;
  138. if (this.socketSprotoDone) {
  139. this.initNetworkDone = true;
  140. G.LogUtils.log('[LaunchCtrl] initNetworkDone');
  141. }
  142. },
  143. handleLoadConfigDone () {
  144. this.loadAllConfigDone = true;
  145. G.LogUtils.log('[LaunchCtrl] loadAllConfigDone');
  146. }
  147. });