LoadingViewComp.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * @Author: dgflash
  3. * @Date: 2021-07-03 16:13:17
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-03-06 15:16:53
  6. */
  7. import { _decorator } from "cc";
  8. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  9. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  10. import { CCVMParentComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCVMParentComp";
  11. import { ModuleUtil } from "../../../../../extensions/oops-plugin-framework/assets/module/common/ModuleUtil";
  12. import { DemoViewComp } from "../../account/view/DemoViewComp";
  13. import { smc } from "../../common/SingletonModuleComp";
  14. import { UIID } from "../../common/config/GameUIConfig";
  15. import { StartViewComp } from "../../start/StartViewComp";
  16. const { ccclass, property } = _decorator;
  17. /** 游戏资源加载 */
  18. @ccclass('LoadingViewComp')
  19. @ecs.register('LoadingView', false)
  20. export class LoadingViewComp extends CCVMParentComp {
  21. /** VM 组件绑定数据 */
  22. data: any = {
  23. /** 加载资源当前进度 */
  24. finished: 0,
  25. /** 加载资源最大进度 */
  26. total: 0,
  27. /** 加载资源进度比例值 */
  28. progress: "0",
  29. /** 加载流程中提示文本 */
  30. prompt: ""
  31. };
  32. private progress: number = 0;
  33. start() {
  34. this.enter();
  35. }
  36. enter() {
  37. this.loadRes();
  38. }
  39. /** 加载资源 */
  40. private async loadRes() {
  41. this.data.progress = 0;
  42. await this.loadCustom();
  43. this.loadGameRes();
  44. }
  45. /** 加载游戏本地JSON数据(自定义内容) */
  46. private loadCustom() {
  47. // 加载游戏本地JSON数据的多语言提示文本
  48. this.data.prompt = oops.language.getLangByID("loading_load_json");
  49. }
  50. /** 加载初始游戏内容资源 */
  51. private loadGameRes() {
  52. // 加载初始游戏内容资源的多语言提示文本
  53. this.data.prompt = oops.language.getLangByID("loading_load_game");
  54. oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
  55. }
  56. /** 加载进度事件 */
  57. private onProgressCallback(finished: number, total: number, item: any) {
  58. this.data.finished = finished;
  59. this.data.total = total;
  60. var progress = finished / total;
  61. if (progress > this.progress) {
  62. this.progress = progress;
  63. this.data.progress = (progress * 100).toFixed(2);
  64. }
  65. }
  66. /** 加载完成事件 */
  67. private async onCompleteCallback() {
  68. // 获取用户信息的多语言提示文本
  69. this.data.prompt = oops.language.getLangByID("loading_load_player");
  70. // await ModuleUtil.addViewUiAsync(smc.account, DemoViewComp, UIID.Demo);
  71. // await ModuleUtil.addViewUiAsync(smc.account, StartViewComp, UIID.Start);
  72. // ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
  73. // 初始化帐号模块
  74. // smc.account.connect();
  75. //初始化剩下的东西
  76. //这做正式逻辑
  77. }
  78. reset(): void { }
  79. }