如何只销毁父节点下面的预制体实例?有啥方法可以判断子节点的类型?
子节点有用预制体动态生成的,也有通过层级管理器直接拉上去生成的
这种用节点名区分就行了啊,动态添加的命名为dym_xxx等特殊意义的。
大佬,有具体例子么?cocos3.x的
写的思路 代码没测试
/** 动态创建节点的数组 */
protected dymNodes: cc.Node[] = [];
onLoad() {
/** 1:在instantiate后将返回的node添加到数组中,直接遍历数组销毁; */
let node = cc.instantiate(this.node);
/** 添加到数据 */
this.dymNodes.push(node);
/** 销毁 */
let length = this.dymNodes.length;
for (let i = 0; i < length; i++) {
this.dymNodes.pop().destroy();
}
/** 2:如"风草流"老哥所说修改节点名,instantiate后修改node.name,遍历节点.children判断name,条件达成则销毁; */
node = cc.instantiate(this.node);
node.name = "dym_xxx";
for (let i = 0; i < this.node.childrenCount; i++) {
/** 判断name */
if (this.node.children[i].name.indexOf("dym_xxx") < 0) {
continue;
}
this.node.children[i].destroy();
}
/** 3:在还没动态创建预制体之前,初始化将层级管理器中添加的节点标记一下,然后遍历销毁; */
for (let i = 0; i < this.node.childrenCount; i++) {
/** 设置个标记 */
this.node.children[i]["origin_flag"] = true;
}
for (let i = 0; i < this.node.childrenCount; i++) {
/** 判断标记,true则是层级管理器中的节点 */
if (this.node.children[i]["origin_flag"]) {
continue;
}
this.node.children[i].destroy();
}
}
谢谢大佬,我先试试
node.id或者node.uuid什么的,新创建的是node开头的id
求代码例子
已搞定,谢谢!
