LoadingViewComp.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * @Author: dgflash
  3. * @Date: 2021-07-03 16:13:17
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-03-19 17:29:41
  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 { EventTouch } from "cc";
  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. this.setButton();
  36. }
  37. enter() {
  38. this.loadRes();
  39. }
  40. /** 加载资源 */
  41. private async loadRes() {
  42. this.data.progress = 0;
  43. await this.loadCustom();
  44. this.loadGameRes();
  45. }
  46. /** 加载游戏本地JSON数据(自定义内容) */
  47. private loadCustom() {
  48. // 加载游戏本地JSON数据的多语言提示文本
  49. this.data.prompt = oops.language.getLangByID("loading_load_json");
  50. }
  51. /** 加载初始游戏内容资源 */
  52. private loadGameRes() {
  53. // 加载初始游戏内容资源的多语言提示文本
  54. this.data.prompt = oops.language.getLangByID("loading_load_game");
  55. oops.res.loadDir("game", this.onProgressCallback.bind(this), this.onCompleteCallback.bind(this));
  56. }
  57. /** 加载进度事件 */
  58. private onProgressCallback(finished: number, total: number, item: any) {
  59. this.data.finished = finished;
  60. this.data.total = total;
  61. var progress = finished / total;
  62. if (progress > this.progress) {
  63. this.progress = progress;
  64. this.data.progress = (progress * 100).toFixed(2);
  65. }
  66. }
  67. /** 加载完成事件 */
  68. private async onCompleteCallback() {
  69. // 获取用户信息的多语言提示文本
  70. this.data.prompt = oops.language.getLangByID("loading_load_player");
  71. // await ModuleUtil.addViewUiAsync(smc.account, DemoViewComp, UIID.Demo);
  72. // ModuleUtil.removeViewUi(this.ent, LoadingViewComp, UIID.Loading);
  73. }
  74. /**
  75. * @description: 微信登录
  76. * @return {*}
  77. */
  78. private btn_wxlogin() {
  79. //
  80. }
  81. /**
  82. * @description: 用户协议
  83. * @return {*}
  84. */
  85. private btn_user() {
  86. console.log("用户协议");
  87. }
  88. /**
  89. * @description: 隐私协议
  90. * @return {*}
  91. */
  92. private btn_privacy() {
  93. console.log("隐私协议");
  94. }
  95. //打开温馨提示
  96. private open_kindTipsView() {
  97. //
  98. }
  99. reset(): void { }
  100. }