public void AnchorPanel(IPanelGroupElement source, IPanelGroupElement anchor, PanelDirection anchorDirection) { PanelGroup group = anchor.Group; if (group is UnanchoredPanelGroup) { Debug.LogError("Can not anchor to an unanchored panel!"); return; } Vector2 size; Panel panel = source as Panel; if (panel != null) { size = panel.IsDocked ? panel.FloatingSize : panel.Size; } else { ((PanelGroup)source).Internal.UpdateLayout(); size = source.Size; } // Fill the whole anchored area in order not to break other elements' sizes on layout update if (anchorDirection == PanelDirection.Left || anchorDirection == PanelDirection.Right) { if (anchor.Size.y > 0f) { size.y = anchor.Size.y; } } else { if (anchor.Size.x > 0f) { size.x = anchor.Size.x; } } if (panel != null) { panel.RectTransform.sizeDelta = size; } else { ((PanelGroup)source).Internal.UpdateBounds(source.Position, size); } bool addElementAfter = anchorDirection == PanelDirection.Right || anchorDirection == PanelDirection.Top; if (group.IsInSameDirection(anchorDirection)) { if (addElementAfter) { group.AddElementAfter(anchor, source); } else { group.AddElementBefore(anchor, source); } } else { IPanelGroupElement element1, element2; if (addElementAfter) { element1 = anchor; element2 = source; } else { element1 = source; element2 = anchor; } PanelGroup newGroup = new PanelGroup(anchor.Canvas, anchorDirection); newGroup.AddElement(element1); newGroup.AddElement(element2); group.Internal.ReplaceElement(anchor, newGroup); } if (panel != null) { if (draggedPanel == panel) { draggedPanel = null; } panel.RectTransform.SetAsFirstSibling(); if (panel.Internal.ContentScrollRect != null) { panel.Internal.ContentScrollRect.OnDrag(nullPointerEventData); } } }
private static ISerializedElement Serialize(IPanelGroupElement element) { if (element == null) { return(null); } if (element is Panel panel) { if (panel.Internal.IsDummy) { return(new SerializedDummyPanel() { size = panel.Size }); } tabsTemp.Clear(); for (int i = 0; i < panel.NumberOfTabs; i++) { PanelTab tab = panel[i]; tabsTemp.Add(new SerializedPanelTab() { id = tab.ID, //minSize = tab.MinSize, //label = tab.Label }); } if (tabsTemp.Count == 0) { return(null); } if (panel.IsDocked) { return(new SerializedPanel() { activeTab = panel.ActiveTab, tabs = tabsTemp.ToArray(), size = panel.Size, floatingSize = panel.FloatingSize }); } else { return(new SerializedUnanchoredPanel() { active = panel.gameObject.activeSelf, activeTab = panel.ActiveTab, tabs = tabsTemp.ToArray(), position = panel.Position, size = panel.Size, floatingSize = panel.Size }); } } PanelGroup panelGroup = (PanelGroup)element; ISerializedElement[] children = new ISerializedElement[panelGroup.Count]; for (int i = 0; i < panelGroup.Count; i++) { children[i] = Serialize(panelGroup[i]); } return(new SerializedPanelGroup() { horizontal = panelGroup.IsInSameDirection(PanelDirection.Right), children = children, size = panelGroup.Size }); }