public void UpdateLayout() { group.UpdateLayout(); }
protected virtual void UpdateLayout() { if (isDirty) { elements.RemoveAll((element) => element.IsNull() || element.Group != this); for (int i = elements.Count - 1; i >= 0; i--) { PanelGroup subGroup = elements[i] as PanelGroup; if (subGroup != null) { subGroup.UpdateLayout(); int count = subGroup.Count; if (count == 0) { elements.RemoveAt(i); } else if (count == 1) { elements[i] = subGroup.elements[0]; SetGroupFor(elements[i], this); i++; } else if (subGroup.IsInSameDirection(direction)) { elements.RemoveAt(i); elements.InsertRange(i, subGroup.elements); for (int j = 0; j < count; j++, i++) { SetGroupFor(elements[i], this); } } } } Vector2 size = Vector2.zero; Vector2 minSize = Vector2.zero; bool horizontal = IsInSameDirection(Direction.Right); int dummyPanelIndex = -1; for (int i = 0; i < elements.Count; i++) { Vector2 elementSize = elements[i].Size; Vector2 elementMinSize = elements[i].MinSize; // Rescue elements whose sizes are stuck at 0 bool rescueElement = false; if (elementSize.x == 0f && elementMinSize.x > 0f) { elementSize.x = Mathf.Min(1f, elementMinSize.x); rescueElement = true; } if (elementSize.y == 0f && elementMinSize.y > 0f) { elementSize.y = Mathf.Min(1f, elementMinSize.y); rescueElement = true; } if (rescueElement) { UpdateBoundsOf(elements[i], elements[i].Position, elementSize); } if (i == 0) { size = elementSize; minSize = elementMinSize; } else { if (horizontal) { size.x += elementSize.x; minSize.x += elementMinSize.x; if (elementSize.y < size.y) { size.y = elementSize.y; } if (elementMinSize.y > minSize.y) { minSize.y = elementMinSize.y; } } else { size.y += elementSize.y; minSize.y += elementMinSize.y; if (elementSize.x < size.x) { size.x = elementSize.x; } if (elementMinSize.x > minSize.x) { minSize.x = elementMinSize.x; } } } if (elements[i] is Panel && ((Panel)elements[i]).Internal.IsDummy) { dummyPanelIndex = i; } } if (dummyPanelIndex >= 0) { Vector2 flexibleSpace = Vector2.zero; if (size.x < Size.x) { flexibleSpace.x = Size.x - size.x; size.x = Size.x; } if (size.y < Size.y) { flexibleSpace.y = Size.y - size.y; size.y = Size.y; } ((Panel)elements[dummyPanelIndex]).RectTransform.sizeDelta += flexibleSpace; } Size = size; MinSize = minSize; isDirty = false; } }