public resetInEditor(): void {
if (!EDITOR) {
return;
}
this.checkNode("MainLayer", "DialogLayer", "LoadingLayer", "TipLayer");
}
// 添加names数组的子节点,
private checkNode(...names: string[]) {
names.forEach((name) => {
let nd:Node;
nd=this.node.getChildByName(name);
if(!nd){
nd = new Node(name);
this.node.addChild(nd);
}
this.setupFullScreenWidget(nd);
});
};
// 通过Widget初始化尺寸
// 直接设置widget,contentSize默认还是(100,100),widget没有作用
private setupFullScreenWidget(nd: Node) {
const widget = nd.getComponent(Widget)||nd.addComponent(Widget);
// 设置对齐目标(通常是 Canvas)
widget.target = this.node;
widget.top = 0;
widget.isAlignTop = true;
widget.bottom = 0;
widget.isAlignBottom = true;
widget.left = 0;
widget.isAlignLeft = true;
widget.right = 0;
widget.isAlignRight = true;
// 强制更新
widget.alignMode = Widget.AlignMode.ON_WINDOW_RESIZE;
widget.updateAlignment();
}
请问什么原因
