Start.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.EXTRA,ModuleDef.BASIC,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. gui.init(this.ui_prefab);
  42. game.frameRate = 61;
  43. if (this.pid == 1) {
  44. // seeg.onLoginRet(
  45. // async (ret: { openid: string; white: boolean }) => {
  46. // console.log(ret);
  47. // await this.try_init(3);
  48. // this.preloadBundle(0);
  49. // }
  50. // //(ret: { userId: number; openId: string; isTest: boolean; abTest: number }) => {
  51. // //console.log(ret);
  52. // //}
  53. // )
  54. // seeg.init({ gid: this.gid, loggerLevel: this.log, old: false });
  55. } else {
  56. await this.try_init(3);
  57. this.preloadBundle(0);
  58. }
  59. this.loadTable();
  60. }
  61. onResLoaded() {
  62. this._numCurrentLoaded++;
  63. console.log(this._numCurrentLoaded);
  64. // this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) + '%';
  65. }
  66. async preloadBundle(idx: number) {
  67. await ResUtil.loadBundle(_preloadBundles[idx])
  68. ch.log.info('module:<' + _preloadBundles[idx] + '>loaded.');
  69. idx++;
  70. this.onResLoaded();
  71. if (idx < _preloadBundles.length) {
  72. this.preloadBundle(idx);
  73. }
  74. else {
  75. this.preloadRes(0);
  76. }
  77. }
  78. async preloadRes(idx: number) {
  79. let res = _preloadRes[idx];
  80. await ResUtil.loadAsset<Prefab>(res.url, res.bundle);
  81. idx++;
  82. this.onResLoaded();
  83. if (idx < _preloadRes.length) {
  84. this.preloadRes(idx);
  85. } else {
  86. this.onPreloadingComplete();
  87. }
  88. }
  89. async onPreloadingComplete() {
  90. await ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
  91. this.onResLoaded();
  92. }
  93. update(deltaTime: number) {
  94. if (this._percent) {
  95. // this.txtLoading.string = 'Loading...' + this._percent;
  96. const sc = this._numCurrentLoaded / _totalNum;
  97. if (sc >= 1) {
  98. this.loadingBar.progress = sc;
  99. } else{
  100. this.loadingBar.progress = this._numCurrentLoaded / _totalNum;
  101. }
  102. }
  103. // else {
  104. // let idx = Math.floor(game.totalTime / 1000) % 3;
  105. // this.txtLoading.string = _loadingText[idx];
  106. // }
  107. }
  108. private loadTable(): void {
  109. // ch.log.log_start("加载配置初始化");
  110. TableLoadUtil.preloadAll(ModuleDef.EXTRA, "table_json", async () => {
  111. // this.onPreloadingComplete();
  112. console.log("加载配置初始化完成");
  113. }, TableUtil.set);
  114. }
  115. }