How do i search for a node that is present in the game scene?
in Unity we can use GameObject.find("object name"); there is one in cocos creator
find(nodePath)
BaseClass extend Component{
views:{[nodeName:string]:Node} = {}; //node map
ctor(){
this.views["xxxName"] = null!; // ts ! remark not null
}
onLoad () {
this.parseView(this.node, true);
this._hasParsedView = true;
//example
this.views["xxxName"].getComponet(xx).xxx
}
parseView(node:Node, forceParse:boolean = false){
if(forceParse || !this._hasParsedView){
this.onParseView(node);
}
}
protected onParseView(node:Node, name:string = ""){
let childrenCount = node.children.length;
for (let i = 0; i < childrenCount; i++){
let child = node.children[i];
let childName:string = child.name;
//if prop name duplicate ...,use the first node
if(this.views[childName] === null){
this.views[childName] = child;
}
if(child.children.length > 0){
let key = name === undefined || name === "" ? childName : [name, "/" , childName].join("");
this.onParseView(child, key)
}
}
}
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。