Start.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { _decorator, game, Label, Prefab, Node, Slider, ProgressBar } from 'cc';
  2. import { ch } from '../ch/ch';
  3. import { gui } from '../core/ui/ui';
  4. import { ch_start_pack } from '../ch/start/ch_start_pack';
  5. import { ResUtil } from '../core/util/ResUtil';
  6. import { ModuleDef } from '../Scripts/ModuleDef';
  7. import { SceneDef } from '../Scripts/SceneDef';
  8. // import TableLoadUtil from '../core/util/TableLoadUtil';
  9. // import { TableUtil } from '../module_extra/table_ts/TableUtil';
  10. const { ccclass, property } = _decorator;
  11. //预加载模块
  12. const _preloadBundles = [ModuleDef.BASIC,ModuleDef.EXTRA,ModuleDef.GAME ];
  13. //预加载资源
  14. const _preloadRes = [
  15. // { bundle: ModuleDef.EXTRA, url: 'ui_loading/UI_Loading' },
  16. { bundle: ModuleDef.BASIC, url: 'ui_alert/UI_Alert' },
  17. { bundle: ModuleDef.BASIC, url: 'ui_waiting/UI_Waiting' },
  18. { bundle: ModuleDef.BASIC, url: 'ui_notify/UI_Notify' },
  19. // { bundle: ModuleDef.Link, url: 'ui/main/UI_Main' },
  20. ];
  21. //
  22. const _loadingText = ['Loading.', 'Loading..', 'Loading...'];
  23. const _totalNum = _preloadBundles.length + _preloadRes.length + 1;
  24. @ccclass('Start')
  25. export class Start extends ch_start_pack {
  26. // @property(Label)
  27. // txtLoading: Label;
  28. // @property(Slider)
  29. // loadingSlider: Slider;
  30. @property(ProgressBar)
  31. loadingBar: ProgressBar;
  32. private _percent: string = '1';
  33. private _numCurrentLoaded = 0;
  34. public static packId: number;
  35. @property({ type: Prefab, displayName: 'ui初始预制体' })
  36. private ui_prefab: Prefab;
  37. protected onLoad(): void {
  38. Start.packId = this.pid
  39. }
  40. async start() {
  41. console.log('Start');
  42. gui.init(this.ui_prefab);
  43. game.frameRate = 61;
  44. // if (this.pid == 1) {
  45. // // seeg.onLoginRet(
  46. // // async (ret: { openid: string; white: boolean }) => {
  47. // // console.log(ret);
  48. // // await this.try_init(3);
  49. // // this.preloadBundle(0);
  50. // // }
  51. // // //(ret: { userId: number; openId: string; isTest: boolean; abTest: number }) => {
  52. // // //console.log(ret);
  53. // // //}
  54. // // )
  55. // // seeg.init({ gid: this.gid, loggerLevel: this.log, old: false });
  56. // } else {
  57. // await this.try_init(3);
  58. // this.preloadBundle(0);
  59. // }
  60. await this.try_init(3);
  61. this.preloadBundle(0);
  62. }
  63. onResLoaded() {
  64. this._numCurrentLoaded++;
  65. console.log(this._numCurrentLoaded);
  66. // this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) + '%';
  67. }
  68. async preloadBundle(idx: number) {
  69. await ResUtil.loadBundle(_preloadBundles[idx])
  70. ch.log.info('module:<' + _preloadBundles[idx] + '>loaded.');
  71. idx++;
  72. this.onResLoaded();
  73. if (idx < _preloadBundles.length) {
  74. this.preloadBundle(idx);
  75. }
  76. else {
  77. this.preloadRes(0);
  78. }
  79. }
  80. async preloadRes(idx: number) {
  81. let res = _preloadRes[idx];
  82. await ResUtil.loadAsset<Prefab>(res.url, res.bundle);
  83. idx++;
  84. this.onResLoaded();
  85. if (idx < _preloadRes.length) {
  86. this.preloadRes(idx);
  87. } else {
  88. this.onPreloadingComplete();
  89. }
  90. }
  91. async onPreloadingComplete() {
  92. await ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
  93. this.onResLoaded();
  94. }
  95. update(deltaTime: number) {
  96. if (this._percent) {
  97. // this.txtLoading.string = 'Loading...' + this._percent;
  98. const sc = this._numCurrentLoaded / _totalNum;
  99. if (sc >= 1) {
  100. this.loadingBar.progress = sc;
  101. } else{
  102. this.loadingBar.progress = this._numCurrentLoaded / _totalNum;
  103. }
  104. }
  105. // else {
  106. // let idx = Math.floor(game.totalTime / 1000) % 3;
  107. // this.txtLoading.string = _loadingText[idx];
  108. // }
  109. }
  110. }