@cc-component/cc-core 1.7.1 → 1.7.3
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.
|
@@ -4,7 +4,7 @@ import { EnvironmentConfig, IConfig } from './IConfig';
|
|
|
4
4
|
import { LayerType } from './LayerType';
|
|
5
5
|
import { Canvas, director } from 'cc';
|
|
6
6
|
import { ResourceManager } from '../home/ResourceManager';
|
|
7
|
-
import { IInitConfig } from './CommonEnum';
|
|
7
|
+
import { IBundleConfig, IInitConfig } from './CommonEnum';
|
|
8
8
|
import { ISceneParam } from '../interface/ISceneParam';
|
|
9
9
|
import { BlockInputEvents } from 'cc';
|
|
10
10
|
import { BaseLaunchComponent } from '../home/BaseLaunchComponent';
|
|
@@ -33,7 +33,7 @@ export class LayerUI {
|
|
|
33
33
|
|
|
34
34
|
loading_call: { open: (finish: () => void) => void, close: () => void }
|
|
35
35
|
progess: { open: (param: ISceneParam, finish: () => void) => void, close: (param: ISceneParam) => void, progess: (param: ISceneParam, progress: number, time?: number) => void }
|
|
36
|
-
|
|
36
|
+
window: { willOpen: (comp: IBundleConfig) => void, open: (comp: IBundleConfig) => void, willClose: (comp: IBundleConfig) => void, close: (comp: IBundleConfig) => void }
|
|
37
37
|
scene: ISceneParam
|
|
38
38
|
launch: BaseLaunchComponent;
|
|
39
39
|
|
|
@@ -85,6 +85,36 @@ export class AudioUtil {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// ==================== 背景音乐控制 ====================
|
|
88
|
+
/**
|
|
89
|
+
|
|
90
|
+
// 播放音频资源,根据传入的状态参数决定播放类型(背景音乐或音效)。
|
|
91
|
+
// @param params - 播放参数对象
|
|
92
|
+
// @param params.path - 音频资源的路径
|
|
93
|
+
// @param params.bundle - 资源包标识符
|
|
94
|
+
// @param params.status - 播放类型状态码:1.表示背景音乐,2.表示音效,3.表示可控音效
|
|
95
|
+
// @param params.loop - 是否循环播放(仅对背景音乐有效),可选
|
|
96
|
+
// @param params.volume - 播放音量(0.0 到 1.0 之间),可选
|
|
97
|
+
// @param params.complete - 播放完成后的回调函数,可选 */
|
|
98
|
+
// async play(params: {
|
|
99
|
+
// path: string;
|
|
100
|
+
// bundle: string;
|
|
101
|
+
// status: number;
|
|
102
|
+
// loop?: boolean;
|
|
103
|
+
// volume?: number;
|
|
104
|
+
// complete?: () => void;
|
|
105
|
+
// }) {
|
|
106
|
+
// switch (params.status) {
|
|
107
|
+
// case 1:
|
|
108
|
+
// this.playMusic(params);
|
|
109
|
+
// break;
|
|
110
|
+
// case 2:
|
|
111
|
+
// this.playShot(params);
|
|
112
|
+
// break;
|
|
113
|
+
// case 3:
|
|
114
|
+
// this.playShot(params);
|
|
115
|
+
// break;
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
88
118
|
/**
|
|
89
119
|
* 播放背景音乐(支持完成回调)
|
|
90
120
|
* @param params.path 音频路径
|
|
@@ -93,7 +123,7 @@ export class AudioUtil {
|
|
|
93
123
|
* @param params.volume 音量(默认使用 music_volume)
|
|
94
124
|
* @param params.callback 播放完成回调(仅在 loop=false 时有效)
|
|
95
125
|
*/
|
|
96
|
-
async
|
|
126
|
+
async playMusic(params: {
|
|
97
127
|
path: string;
|
|
98
128
|
bundle?: string;
|
|
99
129
|
loop?: boolean;
|
|
@@ -110,7 +140,6 @@ export class AudioUtil {
|
|
|
110
140
|
|
|
111
141
|
// 设置完成回调(仅非循环时有意义)
|
|
112
142
|
this._musicCompleteCallback = (!params.loop && params.complete) ? params.complete : undefined;
|
|
113
|
-
|
|
114
143
|
this._audioSource.play();
|
|
115
144
|
} catch (e) {
|
|
116
145
|
console.error(`[AudioUtil] Failed to load or play music: ${params.path}`, e);
|
|
@@ -131,31 +160,33 @@ export class AudioUtil {
|
|
|
131
160
|
}
|
|
132
161
|
|
|
133
162
|
// ==================== 音效播放 ====================
|
|
134
|
-
/**
|
|
135
|
-
async
|
|
163
|
+
/** 播放一次性音效 */
|
|
164
|
+
async playEffects(params: {
|
|
136
165
|
path: string;
|
|
137
|
-
bundle
|
|
166
|
+
bundle: string;
|
|
138
167
|
volume?: number;
|
|
139
|
-
isMusic?: boolean;
|
|
140
168
|
complete?: () => void;
|
|
141
169
|
}) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
const clip = await this.loadAudioClip(params.bundle, params.path);
|
|
171
|
+
const volume = params.volume ?? this.sound_volume;
|
|
172
|
+
this._audioSource.playOneShot(clip, volume);
|
|
173
|
+
}
|
|
174
|
+
/**播放一次性音效--可控制 */
|
|
175
|
+
async playEffectsAudio(params: {
|
|
176
|
+
path: string;
|
|
177
|
+
bundle: string;
|
|
178
|
+
volume?: number;
|
|
179
|
+
complete?: () => void;
|
|
180
|
+
}) {
|
|
181
|
+
const clip = await this.loadAudioClip(params.bundle, params.path);
|
|
182
|
+
const volume = params.volume ?? this.sound_volume;
|
|
183
|
+
this.audioSourceShot.stop(); // 停止当前播放
|
|
184
|
+
this.audioSourceShot.clip = clip;
|
|
185
|
+
this.audioSourceShot.loop = false;
|
|
186
|
+
this.audioSourceShot.volume = volume
|
|
187
|
+
// 设置完成回调(仅非循环时有意义)
|
|
188
|
+
this._musicCompleteCallbackShot = (params.complete) ? params.complete : undefined;
|
|
189
|
+
this.audioSourceShot.play();
|
|
159
190
|
}
|
|
160
191
|
|
|
161
192
|
|
|
@@ -137,7 +137,7 @@ export class App {
|
|
|
137
137
|
static OnRequstNet(param: { open: (finish: (isOk: boolean) => void) => void }) { App.http.param = param; }
|
|
138
138
|
static OnLoading(param: { open: (finish: () => void) => void, close: () => void }) { App.gui.loading_call = param; }
|
|
139
139
|
static OnProgess(param: { open: (param: ISceneParam, finish: () => void) => void, close: (param: ISceneParam) => void, progess: (param: ISceneParam, progress: number, time?: number) => void }) { App.gui.progess = param; }
|
|
140
|
-
|
|
140
|
+
static OnWindow(param: { willOpen: (comp: IBundleConfig) => void, open: (comp: IBundleConfig) => void, willClose: (comp: IBundleConfig) => void, close: (comp: IBundleConfig) => void }) { App.gui.window = param; }
|
|
141
141
|
static async Requst<T>(config: IHttpConfig, params?: any, ext?: IExtData): Promise<{ code: number, data: T, msg: string }> {
|
|
142
142
|
return new Promise<{ code: number, data: T, msg: string }>(async (originalResolve, originalReject) => {
|
|
143
143
|
let retries = 0; // 当前重试次数
|
|
@@ -205,6 +205,7 @@ export class App {
|
|
|
205
205
|
return new Promise<T>(async (resolve, reject) => {
|
|
206
206
|
try {
|
|
207
207
|
const className = config.name ?? config.path.split('/').pop();
|
|
208
|
+
config.name = className;
|
|
208
209
|
if (App.IsWindowOpen(className)) {
|
|
209
210
|
const view = App.GetOpenWindow<Component>(config);
|
|
210
211
|
resolve(view as T);
|
|
@@ -216,6 +217,7 @@ export class App {
|
|
|
216
217
|
Logger.warn("重复打开窗口-请检查", config.path)
|
|
217
218
|
return;
|
|
218
219
|
}
|
|
220
|
+
App.gui.window?.willOpen?.(config)
|
|
219
221
|
//console.error('打开:', Array.from(App.Instance.openedWindows.keys()), config.path);
|
|
220
222
|
App.OpenBlockEvents(LayerType.LayerBlockEventsUI, true)
|
|
221
223
|
if (!param) {
|
|
@@ -256,6 +258,7 @@ export class App {
|
|
|
256
258
|
if (layerUI_list && layerUI_list.length > 0) App.gui.GetLayer(LayerType.LayerGame).active = false;
|
|
257
259
|
Logger.debug('LayerType.LayerUI 打开窗口记录:', className, list);
|
|
258
260
|
App.Emit(SystemMessage.OpenWindow, className)
|
|
261
|
+
App.gui.window?.open?.(config)
|
|
259
262
|
|
|
260
263
|
resolve(view);
|
|
261
264
|
//延迟100毫秒防止连点
|
|
@@ -272,6 +275,8 @@ export class App {
|
|
|
272
275
|
return new Promise<T>(async (resolve, reject) => {
|
|
273
276
|
try {
|
|
274
277
|
const className = config.name ?? config.path.split('/').pop();
|
|
278
|
+
//@ts-ignore
|
|
279
|
+
config.name = className;
|
|
275
280
|
// 记录打开的窗口--先占位
|
|
276
281
|
if (config.is_record === undefined || config.is_record) {//默认记录
|
|
277
282
|
App.Ins.openedWindows.set(className, null);
|
|
@@ -287,8 +292,6 @@ export class App {
|
|
|
287
292
|
App.Ins.openedWindowsConfig.set(className, config);
|
|
288
293
|
}
|
|
289
294
|
//@ts-ignore
|
|
290
|
-
config.name = className;
|
|
291
|
-
//@ts-ignore
|
|
292
295
|
view.config = config;
|
|
293
296
|
//@ts-ignore
|
|
294
297
|
if (param) view.param = param;
|
|
@@ -396,10 +399,11 @@ export class App {
|
|
|
396
399
|
|
|
397
400
|
// 设置窗口关闭监听
|
|
398
401
|
private setupCloseListener(view: Component, className: string) {
|
|
399
|
-
|
|
402
|
+
const config = App.Ins.openedWindowsConfig.get(className);
|
|
403
|
+
const old_destroy = view.node.destroy
|
|
400
404
|
view.node.destroy = () => {
|
|
401
405
|
this.removeWindowRecord(className);
|
|
402
|
-
return view.node
|
|
406
|
+
return old_destroy.call(view.node)
|
|
403
407
|
}
|
|
404
408
|
// 监听节点销毁事件
|
|
405
409
|
// view.node.once(Node.EventType.NODE_DESTROYED, () => {
|
|
@@ -433,6 +437,7 @@ export class App {
|
|
|
433
437
|
this.openedWindows.delete(className);
|
|
434
438
|
this.openedWindowsConfig.delete(className);
|
|
435
439
|
App.Emit(SystemMessage.CloseWindow, className)
|
|
440
|
+
App.gui.window?.close?.(config)
|
|
436
441
|
}
|
|
437
442
|
|
|
438
443
|
// 通过配置关闭窗口
|
|
@@ -56,6 +56,8 @@ declare global {
|
|
|
56
56
|
function OnLoading(param: { open: (finish: () => void) => void, close: () => void })
|
|
57
57
|
/**监听:是否打开网络接口重连窗口 -open 回调方法需要执行 finish() 方法 */
|
|
58
58
|
function OnRequstNet(param: { open: (finish: (isOk: boolean) => void) => void })
|
|
59
|
+
/**监听窗口打开关闭 */
|
|
60
|
+
function OnWindow(param: { willOpen: (comp: IBundleConfig) => void, open: (comp: IBundleConfig) => void, willClose: (comp: IBundleConfig) => void, close: (comp: IBundleConfig) => void });
|
|
59
61
|
/**=====================================✅✅Http请求======================= */
|
|
60
62
|
/**网络接口 */
|
|
61
63
|
function Requst<T>(config: IHttpConfig, params?: any, ext?: { is_show_alert?: boolean }): Promise<{ code: number, data: T, msg: string }>;
|