123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- require('Init');
- // 闪屏ctrl
- cc.Class({
- editor: {
- menu: 'Launch/LaunchCtrl'
- },
- extends: cc.Component,
- properties: {
- audioClip: {
- default: undefined,
- type: cc.AudioClip
- },
- splashBg: {
- default: undefined,
- type: cc.Node
- }
- },
- onLoad () {
- // 监听网络协议加载完成消息
- cc.game.on('e_nwk_socket_sproto_done', this.handleSocketSprotoDone, this);
- cc.game.on('e_nwk_http_sproto_done', this.handleHttpSprotoDone, this);
- cc.game.on('e_mgr_load_config_done', this.handleLoadConfigDone, this);
- this.initNetwork();
- this.initLogin();
- },
- /** 初始化流程 */
- initLogin (){
- this.loadLoginScene();
- this.loadAllConfig();
- // this.getRemoteUpdateInfo();
- // 初始化完成检测
- this.schedule(() => {
- if (this.initNetworkDone &&
- this.loadLoginSceneDone &&
- this.loadAllConfigDone
- ) {
- // 全部初始化完成
- G.LogUtils.log('[LaunchCtrl] 全部初始化完成');
- if (cc.sys.isNative) {
- G.AppUtils.runScene('scene_update_remote_info');
- } else {
- G.AppUtils.runScene('scene_login');
- }
- }
- }, 0.1);
- },
- // 加载登录场景
- loadLoginScene () {
- if (cc.sys.isNative) {
- cc.director.preloadScene('scene_update_remote_info', () => {
- this.loadLoginSceneDone = true;
- G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
- });
- } else {
- cc.director.preloadScene('scene_login', () => {
- this.loadLoginSceneDone = true;
- G.LogUtils.log('[LaunchCtrl] loadLoginSceneDone');
- });
- }
- },
- // 加载牌局场景
- preloadResources () {
- let preloadScene = [
- 'scene_home', // 大厅
- 'scene_table' // 牌桌
- ];
- // 新手引导 包含在大厅场景中
- let preloadPrefab = [
- 'edt_prefab/notice/prefab_notice_alert', // 公告
- 'edt_prefab/activity/004/prefab_activity_004001_alert', // 每周签到
- 'edt_prefab/activity/015/prefab_activity_015001_alert', // 欢乐转盘
- 'edt_prefab/package/package2102/prefab_package_ui_1', // 白赚礼包
- 'edt_prefab/activity/014/prefab_activity_014001_alert', // 复购活动
- 'edt_prefab/rankmatch/prefab_rankmatch_alert', // 赢话费
- 'edt_prefab/qjb/prefab_qjb_special_alert' // 趣金币专场
- ];
- // 预加载场景
- for (const sceneName of preloadScene) {
- cc.director.preloadScene(sceneName, (error, asset) => {
- if (error) {
- G.LogUtils.error('[LaunchCtrl] preload Scene error:' + error);
- } else {
- G.LogUtils.log('[LaunchCtrl] preload Scene ' + sceneName + ' done!');
- }
- });
- }
- // 预加载预制体
- for (const prefabName of preloadPrefab) {
- cc.loader.loadRes(prefabName, cc.Prefab, (error, asset) => {
- if (error) {
- G.LogUtils.error('[LaunchCtrl] preload Prefab error:' + error);
- } else {
- G.LogUtils.log('[LaunchCtrl] preload Prefab ' + prefabName + ' done!');
- }
- });
- }
- },
- // 初始化网络层
- initNetwork () {
- if (!G.DID_GAME_INIT) {
- G.DID_GAME_INIT = true;
- // 初始化连接配置
- G.NetworkMgr.initConn();
- }
- },
- // 加载全部的配置
- loadAllConfig () {
- // G.MgrUtils.loadAllConfig();
- G.CfgMgr.loadAllConfig()
- },
- // 更新检测,目前暂时跳过
- getRemoteUpdateInfo () {
- // 初始化更新模块
- if (cc.sys.isNative) {
- // 请求远程更新信息
- G.RemoteUpdateInfoMgr.requestRemoteUpdateInfo((ok, errorMsg) => {
- this.getRemoteUpdateInfoDone = true;
- });
- } else {
- // 非原生平台不需要热更新
- this.getRemoteUpdateInfoDone = true;
- G.RemoteUpdateInfoMgr.requestRemoteUpdateInfo();
- G.LogUtils.log('[LaunchCtrl] getRemoteUpdateInfoDone');
- }
- },
- onDestroy () {
- cc.game.targetOff(this);
- },
- handleSocketSprotoDone () {
- this.socketSprotoDone = true;
- if (this.httpSprotoDone) {
- this.initNetworkDone = true;
- G.LogUtils.log('[LaunchCtrl] initNetworkDone');
- }
- },
- handleHttpSprotoDone () {
- this.httpSprotoDone = true;
- if (this.socketSprotoDone) {
- this.initNetworkDone = true;
- G.LogUtils.log('[LaunchCtrl] initNetworkDone');
- }
- },
- handleLoadConfigDone () {
- this.loadAllConfigDone = true;
- G.LogUtils.log('[LaunchCtrl] loadAllConfigDone');
- }
- });
|