- Creator 版本: 3.7.3
- 源码中使用 child.active 判断是否处理 Widget,如果屏幕尺寸发生变化前,带有 Widget 的父节点隐藏了,那其子节点的 Widget 会先按错误的宽高进行计算,等父节点显示时会处理父节点的 Widget,但子节点不会再处理导致异常。(AlignMode 设置成 ON_WINDOW_RESIZE)
// TODO: type is hack, Change to the type actually used (Node or BaseNode) when BaseNode complete
function visitNode (node: any) {
const widget = node.getComponent(Widget);
if (widget && widget.enabled) {
if (DEV) {
widget._validateTargetInDEV();
}
// Notice: remove align to after visitNode, AlignMode.ONCE will use widget._hadAlignOnce flag
// align(node, widget);
// if ((!EDITOR || widgetManager.animationState!.animatedSinceLastFrame) && widget.alignMode === AlignMode.ONCE) {
// widget.enabled = false;
// } else {
if (!cclegacy.isValid(node, true)) {
return;
}
activeWidgets.push(widget);
}
const children = node.children;
for (const child of children) {
if (child.active) {
visitNode(child);
}
}
}