cocos creator监听节点添加子节点: 给目标节点添加|删除子节点时触发的事件
实例
//v3.6.1
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('DomController')
export class DomController extends Component {
start() {
this.node.on(Node.EventType.CHILD_ADDED,()=>{
console.log("子节点添加了")
});
this.node.on(Node.EventType.CHILD_REMOVED,()=>{
console.log("子节点移除了")
});
}
update(deltaTime: number) {
}
}
为节点添加子节点时,触发事件
/**
* @en
* The event type for adding a new child node to the target node.
*
* @zh
* 给目标节点添加子节点时触发的事件。
*/
CHILD_ADDED = "child-added",
为节点移除|删除子节点时,触发事件
/**
* @en
* The event type for removing a child node from the target node.
*
* @zh
* 给目标节点移除子节点时触发的事件。
*/
CHILD_REMOVED = "child-removed",