protected void SetChildRect(int index, int axis, float pos, float size, bool sizeDrive) { ChildRect childRect = m_RectChildren.Array[index]; childRect.properties |= DrivenTransformProperties.Anchors; if (axis == 0) { childRect.rect.xMin = pos + rectTransform.rect.xMin; childRect.rect.width = size; childRect.properties |= DrivenTransformProperties.AnchoredPositionX; if (sizeDrive) { childRect.properties |= DrivenTransformProperties.SizeDeltaX; } } else { childRect.rect.yMin = rectTransform.rect.yMin + rectTransform.rect.height - pos - size; childRect.rect.height = size; childRect.properties |= DrivenTransformProperties.AnchoredPositionY; if (sizeDrive) { childRect.properties |= DrivenTransformProperties.SizeDeltaY; } } m_RectChildren.Array[index] = childRect; }
private void UpdateItems() { if (m_ChildArray == null || m_PerformingUpdateItems) { return; } m_PerformingUpdateItems = true; bool isDirty = false; Rect clipRect = GetViewRect(); if (clipRect != m_ViewportRect || m_IsLayoutDirty) { m_ViewportRect = clipRect; List <int> visibleIndexes = ListPool <int> .Get(); if (m_PreRectChildrenCount > m_RectChildren.Count) { for (int i = m_RectChildren.Count; i < m_PreRectChildrenCount; i++) { dataContent.Release(i); } m_PreRectChildrenCount = m_RectChildren.Count; } for (int i = m_RectChildren.Offset; i < m_RectChildren.Count; i++) { if (m_ViewportRect.Overlaps(m_RectChildren.Array[i].rect)) { visibleIndexes.Add(i); } else { dataContent.Release(i); } } foreach (var index in visibleIndexes) { ChildRect child = m_RectChildren.Array[index]; Rect rect = new Rect(child.rect.min - rectTransform.rect.min, child.rect.size); var childRect = dataContent.Show(index, rect, m_IsLayoutDirty); if (!childRect) { continue; } SetChildAlongAxis(childRect, 0, rect.xMin, rect.width, child.properties); SetChildAlongAxis(childRect, 1, rect.yMin, rect.height, child.properties); isDirty = true; } ListPool <int> .Release(visibleIndexes); m_IsLayoutDirty = false; } if (isDirty && !CanvasUpdateRegistry.IsRebuildingGraphics() && !CanvasUpdateRegistry.IsRebuildingLayout()) { Canvas.ForceUpdateCanvases(); } m_PerformingUpdateItems = false; }