@cc-component/cc-core 1.1.9 → 1.2.0

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.
@@ -1,5 +1,6 @@
1
1
 
2
2
  import { tween } from 'cc';
3
+ import { Label } from 'cc';
3
4
  import { ProgressBar } from 'cc';
4
5
  import { _decorator, Component, Node, game, find, director } from 'cc';
5
6
  const { ccclass, property, menu } = _decorator;
@@ -25,8 +26,17 @@ export class ProgessWindow extends Component {
25
26
  type: ProgressBar,
26
27
  displayName: "进度条"
27
28
  })
28
- pro_bar!: ProgressBar;
29
- stop = false
29
+ pro_bar: ProgressBar;
30
+
31
+ @property({
32
+ type: Label,
33
+ displayName: "进度条文本"
34
+ })
35
+ pro_lb: Label;
36
+ /**监听进度
37
+ * pro:0-100
38
+ */
39
+ public onProgress: (pro: number) => void
30
40
 
31
41
  protected onLoad(): void {
32
42
 
@@ -37,27 +47,18 @@ export class ProgessWindow extends Component {
37
47
  }
38
48
 
39
49
  /***更新进度--假的进度 */
40
- async ProgessValueAuto(isOk) {
41
- this.stop = isOk
42
- if (isOk) {
43
- for (var i = 90; i < 101; i++) {
44
- await MainModule.timeManager.AwaitMS(1);
45
- this.ProgessValue((i));
46
- }
47
- this.Hide()
48
- } else {
49
- for (var i = 0; i < 90; i++) {
50
- if (this.stop) { return }
51
- await MainModule.timeManager.AwaitMS(1);
52
- this.ProgessValue((i));
53
- }
54
- }
50
+ async ProgessValueAuto(param: { startTime: number, endTime: number }) {
51
+ await this.loadProgress(param.startTime, param.endTime, (pro: number) => { this.ProgessValue((pro)); })
55
52
  }
56
53
 
57
54
  /***更新进度 */
58
55
  public ProgessValue(value: number) {
59
56
  if (this.pro_bar) {
60
- this.pro(this.pro_bar, value, 100);
57
+ this.onProgress?.(value)
58
+ if (this.pro_lb) {
59
+ this.pro_lb.string = `${value}%`
60
+ }
61
+ this.pro(this.pro_bar, value, 100, 0);
61
62
  }
62
63
  }
63
64
 
@@ -84,5 +85,25 @@ export class ProgessWindow extends Component {
84
85
  proBar.progress = pro;
85
86
  }
86
87
  }
88
+
89
+ /** 模拟假加载进度(仅用于调试) */
90
+ loadProgress(startTime: number = 0, durationSeconds: number = 2, pro: (pro: number) => void): Promise<void> {
91
+ return new Promise((resolve) => {
92
+ let progress = startTime;
93
+ const step = 1; // 每次增加 1%
94
+ const intervalMs = (durationSeconds * 1000) / 100; // 总毫秒数 / 100 步
95
+ const timer = setInterval(() => {
96
+ progress += step;
97
+ if (progress >= 100) {
98
+ progress = 100;
99
+ clearInterval(timer);
100
+ pro?.(progress);
101
+ resolve();
102
+ } else {
103
+ pro?.(progress);
104
+ }
105
+ }, intervalMs);
106
+ });
107
+ }
87
108
  }
88
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-core",
3
- "version": "1.1.9",
3
+ "version": "1.2.0",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",