优化特效管理模块代码

This commit is contained in:
dgflash
2022-08-21 10:20:13 +08:00
parent 2a5ead92c8
commit cdf6b51a63
3 changed files with 25 additions and 26 deletions

View File

@@ -2,7 +2,7 @@
* @Author: dgflash
* @Date: 2021-10-12 14:00:43
* @LastEditors: dgflash
* @LastEditTime: 2022-08-19 17:51:37
* @LastEditTime: 2022-08-20 14:57:42
*/
import { Component, Node, NodePool, Prefab, Vec3 } from 'cc';
@@ -36,7 +36,7 @@ export class EffectSingleCase {
private effects: Map<string, NodePool> = new Map();
/** 加载资源并现实特效 */
loadAndShow(name: string, parent: Node, params?: IEffectParams): Promise<Node> {
loadAndShow(name: string, parent?: Node, params?: IEffectParams): Promise<Node> {
return new Promise((resolve, reject) => {
var np = this.effects.get(name);
if (np == undefined) {
@@ -63,7 +63,7 @@ export class EffectSingleCase {
* @param parent 父节点
* @param pos 位置
*/
show(name: string, parent: Node, params?: IEffectParams): Node {
show(name: string, parent?: Node, params?: IEffectParams): Node {
var np = this.effects.get(name);
if (np == null) {
np = new NodePool();
@@ -81,10 +81,11 @@ export class EffectSingleCase {
else {
node = np.get()!;
}
node.parent = parent;
if (params && params.pos) node.position = params.pos;
if (parent) node.parent = parent;
return node;
}

View File

@@ -16,21 +16,21 @@ const { ccclass, property } = _decorator;
*/
@ccclass
export default class VMBase extends Component {
/**VM管理 */
VM = VM;
/** watch 单路径 */
public watchPath: string = '';
watchPath: string = '';
/** 是否启用模板多路径模式 */
templateMode: boolean = false;
/** watch 多路径 */
protected watchPathArr: string[] = [];
/** 是否启用模板多路径模式 */
public templateMode: boolean = false;
/** 储存模板多路径的值 */
protected templateValueArr: any[] = [];
/**VM管理 */
public VM = VM;
/**
* 如果需要重写onLoad 方法,请根据顺序调用 super.onLoad(),执行默认方法
*/

View File

@@ -25,38 +25,36 @@ export default class VMLabel extends VMBase {
@property({
tooltip: '是否启用模板代码,只能在运行时之前设置,\n将会动态解析模板语法 {{0}},并且自动设置监听的路径'
})
public templateMode: boolean = false;
templateMode: boolean = false;
@property({
visible() {
return this.templateMode === false;
}
})
watchPath: string = '';
@property({
readonly: true
})
private labelType: string = LABEL_TYPE.CC_LABEL;
@property({
visible: function () {
// @ts-ignore
return this.templateMode === false;
}
})
watchPath: string = "";
// 按照匹配参数顺序保存的 path 数组 (固定)
@property({
type: [CCString],
visible: function () {
// @ts-ignore
visible() {
return this.templateMode === true;
}
})
/** 按照匹配参数顺序保存的 path 数组 (固定) */
protected watchPathArr: string[] = [];
// 按照路径参数顺序保存的 值的数组(固定)
/** 按照路径参数顺序保存的 值的数组(固定)*/
protected templateValueArr: any[] = [];
// 保存着字符模板格式的数组 (只会影响显示参数)
/** 保存着字符模板格式的数组 (只会影响显示参数) */
private templateFormatArr: string[] = [];
// 源字符串
/** 源字符串 */
private originText: string | null = null;
onRestore() {