for (int i = 0; i < comps.Count; ++i) { var cur = comps[i]; if (cur != null && cur is Behaviour && ((Behaviour)cur).isActiveAndEnabled) { validLayoutGroup = true; layoutRoot = parent; break; } }
// 遍历 comps 列表,检查每个组件是否是 Behaviour 类型且处于启用状态(isActiveAndEnabled 为 true)。 layoutRoot.GetComponents(typeof(ILayoutController), comps); for (int i = 0; i < comps.Count; ++i) { var cur = comps[i]; if (cur != null && cur is Behaviour && ((Behaviour)cur).isActiveAndEnabled) { returntrue; } }
publicvoidRebuild(CanvasUpdate executing) { switch (executing) { case CanvasUpdate.Layout: // 不幸的是,我们将对树执行相同的GetComponents查询2次, // 但是每个树必须在进入下一个动作之前被完全迭代, // 所以重用结果需要将结果存储在Dictionary或类似的地方, // 这可能比多次执行GetComponents的开销更大。 PerformLayoutCalculation(m_ToRebuild, e => (e as ILayoutElement).CalculateLayoutInputHorizontal()); PerformLayoutControl(m_ToRebuild, e => (e as ILayoutController).SetLayoutHorizontal()); PerformLayoutCalculation(m_ToRebuild, e => (e as ILayoutElement).CalculateLayoutInputVertical()); PerformLayoutControl(m_ToRebuild, e => (e as ILayoutController).SetLayoutVertical()); break; } }
var components = ListPool<Component>.Get(); rect.GetComponents(typeof(ILayoutController), components); StripDisabledBehavioursFromList(components);
//如果这个rect上没有控制器,我们可以跳过这整个子树 //我们也不需要考虑子树更深处的子节点上的控制器, //因为它们将成为自己的根。 if (components.Count > 0) { //布局控件需要自顶向下执行,父控件在子控件之前完成; //因为孩子依赖于父母的大小。
//首先调用布局控制器,它们可以改变自己的RectTransform for (int i = 0; i < components.Count; i++) if (components[i] is ILayoutSelfController) action(components[i]);
//然后调用其余的,比如改变它们的子布局组,考虑它们自己的RectTransform大小。 for (int i = 0; i < components.Count; i++) if (!(components[i] is ILayoutSelfController)) action(components[i]);
for (int i = 0; i < rect.childCount; i++) PerformLayoutControl(rect.GetChild(i) as RectTransform, action); }
var components = ListPool<Component>.Get(); rect.GetComponents(typeof(ILayoutElement), components); StripDisabledBehavioursFromList(components);
//如果这个rect上没有控制器,我们可以跳过这整个子树 //我们也不需要考虑子树更深处的子节点上的控制器, //因为它们将成为自己的根。 if (components.Count > 0 || rect.GetComponent(typeof(ILayoutGroup))) { //布局计算需要自底向上执行,子节点在父节点之前完成; //因为父节点的计算大小依赖于子节点的大小。 for (int i = 0; i < rect.childCount; i++) PerformLayoutCalculation(rect.GetChild(i) as RectTransform, action);
for (int i = 0; i < components.Count; i++) action(components[i]); }