LaunchCtrl.js 5.0 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. ) {
  37. // 全部初始化完成
  38. G.LogUtils.log('[LaunchCtrl] 全部初始化完成');
  39. if (cc.sys.isNative) {
  40. G.AppUtils.runScene('scene_update_remote_info');
  41. } else {
  42. G.AppUtils.runScene('scene_login');
  43. }
  44. }
  45. }, 0.1);
  46. },
  47. // 加载登录场景
  48. loadLoginScene () {
  49. if (cc.sys.isNative) {
  50. cc.director.preloadScene('scene_update_remote_info', () => {
  51. this.loadLoginSceneDone = true;
  52. G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
  53. });
  54. } else {
  55. cc.director.preloadScene('scene_login', () => {
  56. this.loadLoginSceneDone = true;
  57. G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
  58. });
  59. }
  60. },
  61. // 加载牌局场景
  62. preloadResources () {
  63. let preloadScene = [
  64. 'scene_home', // 大厅
  65. 'scene_table' // 牌桌
  66. ];
  67. // 新手引导 包含在大厅场景中
  68. let preloadPrefab = [
  69. 'edt_prefab/notice/prefab_notice_alert', // 公告
  70. 'edt_prefab/activity/004/prefab_activity_004001_alert', // 每周签到
  71. 'edt_prefab/activity/015/prefab_activity_015001_alert', // 欢乐转盘
  72. 'edt_prefab/package/package2102/prefab_package_ui_1', // 白赚礼包
  73. 'edt_prefab/activity/014/prefab_activity_014001_alert', // 复购活动
  74. 'edt_prefab/rankmatch/prefab_rankmatch_alert', // 赢话费
  75. 'edt_prefab/qjb/prefab_qjb_special_alert' // 趣金币专场
  76. ];
  77. // 预加载场景
  78. for (const sceneName of preloadScene) {
  79. cc.director.preloadScene(sceneName, (error, asset) => {
  80. if (error) {
  81. G.LogUtils.error('[LaunchCtrl] preload Scene error:' + error);
  82. } else {
  83. G.LogUtils.log('[LaunchCtrl] preload Scene ' + sceneName + ' done!');
  84. }
  85. });
  86. }
  87. // 预加载预制体
  88. for (const prefabName of preloadPrefab) {
  89. cc.loader.loadRes(prefabName, cc.Prefab, (error, asset) => {
  90. if (error) {
  91. G.LogUtils.error('[LaunchCtrl] preload Prefab error:' + error);
  92. } else {
  93. G.LogUtils.log('[LaunchCtrl] preload Prefab ' + prefabName + ' done!');
  94. }
  95. });
  96. }
  97. },
  98. // 初始化网络层
  99. initNetwork () {
  100. if (!G.DID_GAME_INIT) {
  101. G.DID_GAME_INIT = true;
  102. // 初始化连接配置
  103. G.NetworkMgr.initConn();
  104. }
  105. },
  106. // 加载全部的配置
  107. loadAllConfig () {
  108. // G.MgrUtils.loadAllConfig();
  109. G.CfgMgr.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. });