import { _decorator, game, Label, Prefab, Node, Slider, ProgressBar, director, Sprite, SpriteFrame } from 'cc'; import { ModuleDef } from '../Script/ModuleDef'; import { SceneDef } from '../Script/SceneDef'; import { ch_start_pack } from '../ch/start/ch_start_pack'; import { gui } from '../core/ui/ui'; import { ResUtil } from '../core/util/ResUtil' import { ch } from '../ch/ch'; const { ccclass, property } = _decorator; //预加载模块 const _preloadBundles = [ModuleDef.EXTRA,ModuleDef.BASIC,ModuleDef.GAME]; //预加载资源 const _preloadRes = [ // { bundle: ModuleDef.EXTRA, url: 'ui/loading' }, { bundle: ModuleDef.BASIC, url: 'ui_alert/UI_Alert' }, { bundle: ModuleDef.BASIC, url: 'ui_waiting/UI_Waiting' }, { bundle: ModuleDef.BASIC, url: 'ui_notify/UI_Notify' }, { bundle: ModuleDef.GAME, url: 'ui/main/main' }, { bundle: ModuleDef.GAME, url: 'ui/UI_Hall/Hall' }, ]; // const _loadingText = ['Loading.', 'Loading..', 'Loading...']; const _totalNum = _preloadBundles.length + _preloadRes.length + 1; @ccclass('Start') export class Start extends ch_start_pack { //skinManager = new SkinManager(); @property(ProgressBar) loadingBar: ProgressBar; private _percent: string = '1'; private _numCurrentLoaded = 0; public static packId: number; @property({ type: Prefab, displayName: 'ui初始预制体' }) private ui_prefab: Prefab; isGameScenePreloaded = false; protected onLoad(): void { Start.packId = this.pid } async start() { console.log('Start'); gui.init(this.ui_prefab); game.frameRate = 61; await this.try_init(3); this.preloadBundle(0); } onResLoaded() { this._numCurrentLoaded++; console.log(this._numCurrentLoaded); this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) + '%'; console.log(this._percent); } async preloadBundle(idx: number) { await ResUtil.loadBundle(_preloadBundles[idx]) ch.log.info('module:<' + _preloadBundles[idx] + '>loaded.'); idx++; this.onResLoaded(); if (idx < _preloadBundles.length) { this.preloadBundle(idx); } else { this.preloadRes(0); } } async preloadRes(idx: number) { let res = _preloadRes[idx]; await ResUtil.loadAsset(res.url, res.bundle); idx++; this.onResLoaded(); if (idx < _preloadRes.length) { this.preloadRes(idx); } else { this.onPreloadingComplete(); } } async onPreloadingComplete() { await ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true); console.log('jinru hall'); this.onResLoaded(); } update(deltaTime: number) { if (this._percent) { // this.txtLoading.string = 'Loading...' + this._percent; const sc = this._numCurrentLoaded / _totalNum; if (sc >= 1) { this.loadingBar.progress = sc; } else { this.loadingBar.progress = this._numCurrentLoaded / _totalNum; } } } }