123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import { _decorator, game, Label, Prefab, Node, Slider, ProgressBar } from 'cc';
- import { ch } from '../ch/ch';
- import { gui } from '../core/ui/ui';
- import { ch_start_pack } from '../ch/start/ch_start_pack';
- import { ResUtil } from '../core/util/ResUtil';
- import { ModuleDef } from '../Scripts/ModuleDef';
- import { SceneDef } from '../Scripts/SceneDef';
- import TableLoadUtil from '../core/util/TableLoadUtil';
- import { TableUtil } from '../module_extra/table_ts/TableUtil';
- const { ccclass, property } = _decorator;
- //预加载模块
- const _preloadBundles = [ModuleDef.EXTRA,ModuleDef.BASIC,ModuleDef.GAME ];
- //预加载资源
- const _preloadRes = [
- // { bundle: ModuleDef.EXTRA, url: 'ui_loading/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.Link, url: 'ui/main/UI_Main' },
- ];
- //
- const _loadingText = ['Loading.', 'Loading..', 'Loading...'];
- const _totalNum = _preloadBundles.length + _preloadRes.length + 1;
- @ccclass('Start')
- export class Start extends ch_start_pack {
- // @property(Label)
- // txtLoading: Label;
- // @property(Slider)
- // loadingSlider: Slider;
- @property(ProgressBar)
- loadingBar: ProgressBar;
- private _percent: string = '1';
- private _numCurrentLoaded = 0;
- public static packId: number;
- @property({ type: Prefab, displayName: 'ui初始预制体' })
- private ui_prefab: Prefab;
- protected onLoad(): void {
- Start.packId = this.pid
- }
- async start() {
- gui.init(this.ui_prefab);
- game.frameRate = 61;
- if (this.pid == 1) {
- // seeg.onLoginRet(
- // async (ret: { openid: string; white: boolean }) => {
- // console.log(ret);
- // await this.try_init(3);
- // this.preloadBundle(0);
- // }
- // //(ret: { userId: number; openId: string; isTest: boolean; abTest: number }) => {
- // //console.log(ret);
- // //}
- // )
- // seeg.init({ gid: this.gid, loggerLevel: this.log, old: false });
- } else {
- await this.try_init(3);
- this.preloadBundle(0);
- }
- this.loadTable();
- }
- onResLoaded() {
- this._numCurrentLoaded++;
- console.log(this._numCurrentLoaded);
- // this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) + '%';
- }
- 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<Prefab>(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);
- 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;
- }
- }
- // else {
- // let idx = Math.floor(game.totalTime / 1000) % 3;
- // this.txtLoading.string = _loadingText[idx];
- // }
- }
- private loadTable(): void {
- // ch.log.log_start("加载配置初始化");
- TableLoadUtil.preloadAll(ModuleDef.EXTRA, "table_json", async () => {
- // this.onPreloadingComplete();
- console.log("加载配置初始化完成");
- }, TableUtil.set);
- }
- }
|