| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { _decorator, assetManager, Component, director, game, Label, Prefab, Node } from 'cc';
- import { tgxModuleContext, tgxUIMgr } from '../core_tgx/tgx';
- import { GameUILayers, GameUILayerNames } from '../scripts/GameUILayers';
- import { ModuleDef } from '../scripts/ModuleDef';
- import { SceneDef } from '../scripts/SceneDef';
- import { ProcessBar } from '../scripts/Component/ProcessBar';
- import { aa } from '../scripts/aa';
- import { ch_start } from '../ch/start/ch_start';
- const { ccclass, property } = _decorator;
- const _preloadBundles = [ModuleDef.EXTRA, ModuleDef.BASIC ];
- const _preloadRes = [
-
-
- { bundle: ModuleDef.BASIC, url: 'ui_game/UI_Game', type: 'prefab' },
- { bundle: ModuleDef.BASIC, url: 'ui_dialog/win_dialog/ui_win', type: 'prefab' },
- { bundle: ModuleDef.BASIC, url: 'ui_dialog/guide/Guide', type: 'prefab' },
- { bundle: ModuleDef.BASIC, url: 'ui_dialog/die_dialog/ui_die', type: 'prefab' },
- { bundle: ModuleDef.BASIC, url: 'scene/res', type: 'prefab' },
-
-
- ];
- const _loadingText = ['Loading.', 'Loading..', 'Loading...'];
- const _totalNum = _preloadBundles.length + _preloadRes.length + 1;
- const gid = 'xchst'
- const tdKey = "5F358EE0E2E94D078FD9E32DDA457229"
- @ccclass('Start')
- export class Start extends ch_start {
- @property(Label)
- txtLoading: Label;
- @property(Prefab)
- uiCanvasPrefab: Prefab;
- @property(ProcessBar)
- loadingBar: ProcessBar;
- @property(Label)
- titlen: Label;
- private _percent: string = '';
- private _numCurrentLoaded = 0;
- isinit
- async start() {
-
- this.isinit = 1
- game.frameRate = 61;
- tgxModuleContext.setDefaultModule(ModuleDef.BASIC);
- this.loadingBar.init();
-
- tgxUIMgr.inst.setup(this.uiCanvasPrefab, GameUILayers.NUM, GameUILayerNames);
-
- await this.try_init()
- this.preloadBundle(0);
-
- this.isinit += 1
- aa.data.download(() => {
- this.isinit -= 1
- this.onPreloadingComplete();
- })
-
- aa.info.g_name = this.conf.gname
- if(this.titlen){
- this.titlen.string = aa.info.g_name
- }
-
- }
- onResLoaded() {
- this._numCurrentLoaded++;
- this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) +"";
- }
- preloadBundle(idx: number) {
- assetManager.loadBundle(_preloadBundles[idx], null, (err, bundle) => {
- console.log('module:<' + _preloadBundles[idx] + '>loaded.');
- idx++;
- this.onResLoaded();
- if (idx < _preloadBundles.length) {
- this.preloadBundle(idx);
- }
- else {
- this.preloadRes(0);
- }
- });
- }
- preloadRes(idx: number) {
- let res = _preloadRes[idx];
- let bundle = assetManager.getBundle(res.bundle);
- let onComplete = () => {
- idx++;
- this.onResLoaded();
- if (idx < _preloadRes.length) {
- this.preloadRes(idx);
- }
- else {
- this.isinit -= 1
- this.onPreloadingComplete();
- }
- }
- if (bundle) {
- if (res.type == 'prefab') {
- bundle.load(res.url, Prefab, onComplete);
- }
- }
- }
- onPreloadingComplete() {
- if (this.isinit > 0) {
- return
- }
-
- let bundle = assetManager.getBundle(ModuleDef.BASIC);
- bundle.preloadScene(SceneDef.MAIN_MENU, () => {
- this.onResLoaded();
- director.loadScene(SceneDef.MAIN_MENU);
- });
-
- }
- update(deltaTime: number) {
- if (this._percent) {
- this.txtLoading.string = this._percent;
- }
- else {
- let idx = Math.floor(game.totalTime / 1000) % 3;
- this.txtLoading.string = _loadingText[idx];
- this.txtLoading.string = '0';
- }
-
- this.loadingBar.set(this._numCurrentLoaded / _totalNum );
- }
- }
|