@cc-component/cc-core 1.5.4 → 1.5.5
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.
|
@@ -10,17 +10,18 @@ import { Asset } from 'cc';
|
|
|
10
10
|
import { instantiate } from 'cc';
|
|
11
11
|
|
|
12
12
|
/** 特效参数 */
|
|
13
|
-
export interface
|
|
13
|
+
export interface IPoolParams {
|
|
14
14
|
/**路径 */
|
|
15
15
|
path: string;
|
|
16
16
|
/**资源包名 */
|
|
17
|
-
bundle
|
|
17
|
+
bundle?: string;
|
|
18
18
|
/**初始空间坐标 */
|
|
19
19
|
pos?: Vec3,
|
|
20
20
|
/**初始世界坐标 */
|
|
21
21
|
worldPos?: Vec3,
|
|
22
|
-
/** 是否播放完成后删除 */
|
|
23
|
-
isPlayFinishedRelease?: boolean,
|
|
22
|
+
// /** 是否播放完成后删除 */
|
|
23
|
+
// isPlayFinishedRelease?: boolean,
|
|
24
|
+
parent?: Node
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -78,7 +79,7 @@ export class EffectSingleCase {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/** 池中预加载显示对象 */
|
|
81
|
-
preload(count: number, params:
|
|
82
|
+
preload(count: number, params: IPoolParams): Promise<void> {
|
|
82
83
|
return new Promise(async (resolve, reject) => {
|
|
83
84
|
let np = this.effects.get(params.path);
|
|
84
85
|
if (np == null) {
|
|
@@ -103,7 +104,7 @@ export class EffectSingleCase {
|
|
|
103
104
|
* @param parent 父节点
|
|
104
105
|
* @param params 显示参数
|
|
105
106
|
*/
|
|
106
|
-
loadAndShow(params?:
|
|
107
|
+
loadAndShow(params?: IPoolParams, parent?: Node): Promise<Node> {
|
|
107
108
|
return new Promise(async (resolve, reject) => {
|
|
108
109
|
var np = this.effects.get(params.path);
|
|
109
110
|
if (np == undefined) {
|
|
@@ -132,7 +133,7 @@ export class EffectSingleCase {
|
|
|
132
133
|
* @param parent 父节点
|
|
133
134
|
* @param params 显示参数
|
|
134
135
|
*/
|
|
135
|
-
show(params:
|
|
136
|
+
show(params: IPoolParams, parent?: Node): Node {
|
|
136
137
|
var np = this.effects.get(params.path);
|
|
137
138
|
if (np == null) {
|
|
138
139
|
np = new NodePool();
|
|
@@ -264,4 +265,40 @@ export class EffectSingleCase {
|
|
|
264
265
|
}
|
|
265
266
|
}
|
|
266
267
|
}
|
|
268
|
+
|
|
269
|
+
/**获取节点 */
|
|
270
|
+
getNode(params: IPoolParams): Node {
|
|
271
|
+
var np = this.effects.get(params.path);
|
|
272
|
+
const node = np?.get() ?? null
|
|
273
|
+
this.updateNode(node, params)
|
|
274
|
+
return node
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** 加载节点对象 */
|
|
278
|
+
load(params: IPoolParams): Promise<Node> {
|
|
279
|
+
return new Promise(async (resolve, reject) => {
|
|
280
|
+
if (!params.bundle) {
|
|
281
|
+
Logger.error('请指定bundleName');
|
|
282
|
+
resolve(null)
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
var np = this.effects.get(params.path);
|
|
286
|
+
if (np == null || np === undefined) {
|
|
287
|
+
np = new NodePool();
|
|
288
|
+
this.effects.set(params.path, np);
|
|
289
|
+
}
|
|
290
|
+
this.res.set(params.path, params.bundle);
|
|
291
|
+
const prefab = await App.LoadAsset(params.bundle, params.path, Prefab);
|
|
292
|
+
const node = instantiate(prefab)
|
|
293
|
+
|
|
294
|
+
this.updateNode(node, params)
|
|
295
|
+
resolve(node);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
updateNode(node: Node, params: IPoolParams) {
|
|
300
|
+
if (node && node.isValid && params.pos) node.position = params.pos;
|
|
301
|
+
if (node && node.isValid && params.worldPos) node.worldPosition = params.worldPos;
|
|
302
|
+
if (node && node.isValid && params.parent) { params.parent.addChild(node); }
|
|
303
|
+
}
|
|
267
304
|
}
|