@cc-component/cc-core 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,7 @@ export abstract class BaseLoading extends Component {
27
27
  progress_ratio: number = 1
28
28
  /**总进度 值范围 0-100*/
29
29
  pro_total: number;
30
+ is_init: boolean = false;
30
31
 
31
32
  sceneParam: ISceneParam = {
32
33
  param: null,
@@ -44,23 +45,26 @@ export abstract class BaseLoading extends Component {
44
45
  }
45
46
 
46
47
  async Init() {
47
- const count = this.path_list.length;
48
- const ratio = 1 / count * this.progress_ratio;
49
- this.pro_total = 0;
50
-
51
- for (let index = 0; index < this.path_list.length; index++) {
52
- const key_path = this.path_list[index];
53
- let temp_pro = 0;
54
- await MainModule.loadDir(BundleConfig[key_path.bundleName], key_path.path, GetAssetType(key_path.type), (pro: number) => {
55
- temp_pro = pro * ratio
56
- const progess = (this.pro_total + pro * ratio)
57
- MainModule.gui.progess.progess?.(progess)//进度在OpenScene方法中先打开才可以 设置进度
58
- })
59
- this.pro_total = (this.pro_total + temp_pro)
48
+ if (this.is_init) {
49
+ await this.loadProgress(1)
50
+ } else {
51
+ const count = this.path_list.length;
52
+ const ratio = 1 / count * this.progress_ratio;
53
+ this.pro_total = 0;
54
+ for (let index = 0; index < this.path_list.length; index++) {
55
+ const key_path = this.path_list[index];
56
+ let temp_pro = 0;
57
+ await MainModule.loadDir(BundleConfig[key_path.bundleName], key_path.path, GetAssetType(key_path.type), (pro: number) => {
58
+ temp_pro = pro * ratio
59
+ const progess = (this.pro_total + pro * ratio)
60
+ MainModule.gui.progess.progess?.(progess)//进度在OpenScene方法中先打开才可以 设置进度
61
+ })
62
+ this.pro_total = (this.pro_total + temp_pro)
63
+ }
64
+ console.log("完成", this.pro_total)
65
+ // ✅ 先调用子类的 Finish(允许子类做自定义操作)
66
+ await this.Finish(); // 支持异步
60
67
  }
61
- console.log("完成", this.pro_total)
62
- // ✅ 先调用子类的 Finish(允许子类做自定义操作)
63
- await this.Finish(); // 支持异步
64
68
  this.FinishLoad()
65
69
  }
66
70
 
@@ -88,6 +92,26 @@ export abstract class BaseLoading extends Component {
88
92
  }
89
93
  }
90
94
 
95
+ /** 模拟假加载进度(仅用于调试) */
96
+ loadProgress(durationSeconds: number = 2): Promise<void> {
97
+ return new Promise((resolve) => {
98
+ let progress = 0;
99
+ const step = 1; // 每次增加 1%
100
+ const intervalMs = (durationSeconds * 1000) / 100; // 总毫秒数 / 100 步
101
+ const timer = setInterval(() => {
102
+ progress += step;
103
+ if (progress >= 100) {
104
+ progress = 100;
105
+ clearInterval(timer);
106
+ MainModule.gui.progess.progess?.(progress);
107
+ resolve();
108
+ } else {
109
+ MainModule.gui.progess.progess?.(progress);
110
+ }
111
+ }, intervalMs);
112
+ });
113
+ }
114
+
91
115
 
92
116
  // 抽象方法:子类实现自己的逻辑
93
117
  abstract Finish(): Promise<void>; // 推荐加 async/await 支持
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-core",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",