Exemplo n.º 1
0
        public PanelTab AddTab(PanelTab tab, int tabIndex = -1)
        {
            if (!tab)
            {
                return(null);
            }

            return(AddTab(tab.Content, tabIndex));
        }
Exemplo n.º 2
0
        public PanelTab AddTab(PanelTab tab, int tabIndex = -1)
        {
            if (tab == null || tab.Equals(null))
            {
                return(null);
            }

            return(AddTab(tab.Content, tabIndex));
        }
        public static bool TryGetTab(string tabID, out PanelTab tab)
        {
            if (string.IsNullOrEmpty(tabID))
            {
                tab = null;
                return(false);
            }

            return(idToTab.TryGetValue(tabID, out tab));
        }
Exemplo n.º 4
0
        public int GetTabIndex(PanelTab tab)
        {
            for (int i = 0; i < tabs.Count; i++)
            {
                if (tabs[i] == tab)
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        public override bool Execute(PanelTab panelTab, PointerEventData eventData)
        {
            Direction anchorDirection = GetAnchorDirection(eventData);

            if (anchorDirection == Direction.None)
            {
                return(false);
            }

            Panel detachedPanel = PanelManager.Instance.DetachPanelTab(panelTab.Panel, panelTab.Panel.Internal.GetTabIndex(panelTab));

            PanelManager.Instance.AnchorPanel(detachedPanel, m_panel, anchorDirection);

            return(true);
        }
            public static void TabIDChanged(PanelTab tab, string previousID, string newID)
            {
                if (!string.IsNullOrEmpty(previousID))
                {
                    PanelTab previousTab;
                    if (idToTab.TryGetValue(previousID, out previousTab) && previousTab == tab)
                    {
                        idToTab.Remove(previousID);
                    }
                }

                if (!string.IsNullOrEmpty(newID))
                {
                    idToTab[newID] = tab;
                }
            }
 public static void TabDragStateChanged(PanelTab tab, bool isDragging)
 {
     if (isDragging)
     {
         if (OnStartedDraggingTab != null)
         {
             OnStartedDraggingTab(tab);
         }
     }
     else
     {
         if (OnStoppedDraggingTab != null)
         {
             OnStoppedDraggingTab(tab);
         }
     }
 }
Exemplo n.º 8
0
 public void OnPanelTabTranslate(PanelTab panelTab, PointerEventData draggingPointer)
 {
     if (draggedPanel == panelTab.Panel)
     {
         Rect previewRect;
         if (hoveredAnchorZone != null && hoveredAnchorZone.GetAnchoredPreviewRectangleAt(draggingPointer, out previewRect))
         {
             previewPanel.anchoredPosition = previewRect.position;
             previewPanel.sizeDelta        = previewRect.size;
         }
         else
         {
             Vector2 position;
             RectTransformUtility.ScreenPointToLocalPointInRectangle(previewPanelCanvas.RectTransform, draggingPointer.position, previewPanelCanvas.Internal.worldCamera, out position);
             previewPanel.anchoredPosition = position;
             previewPanel.sizeDelta        = panelTab.Panel.FloatingSize;
         }
     }
 }
Exemplo n.º 9
0
        public bool OnBeginPanelTabTranslate(PanelTab panelTab, PointerEventData draggingPointer)
        {
            if (draggedPanel != null)
            {
                CancelDraggingPanel();
            }

            if (panelTab.Panel.NumberOfTabs == 1 && panelTab.Panel.Canvas.PreventDetachingLastDockedPanel && panelTab.Panel.Canvas.Internal.IsLastDockedPanel(panelTab.Panel))
            {
                return(false);
            }

            draggedPanel = panelTab.Panel;

            if (!draggedPanel.IsDocked)
            {
                draggedPanel.FloatingSize = draggedPanel.Size;
            }

            AnchorZonesSetActive(true);

            if (draggedPanel.NumberOfTabs <= 1)
            {
                draggedPanel.Internal.PanelAnchorZone.SetActive(false);
            }

            if (RectTransformUtility.RectangleContainsScreenPoint(draggedPanel.Internal.HeaderAnchorZone.RectTransform, draggingPointer.position, draggedPanel.Canvas.Internal.worldCamera))
            {
                draggedPanel.Internal.HeaderAnchorZone.OnPointerEnter(draggingPointer);
                draggingPointer.pointerEnter = draggedPanel.Internal.HeaderAnchorZone.gameObject;
            }

            previewPanelCanvas = draggedPanel.Canvas;
            if (previewPanel.parent != previewPanelCanvas.RectTransform)
            {
                previewPanel.SetParent(previewPanelCanvas.RectTransform, false);
            }

            previewPanel.gameObject.SetActive(true);
            previewPanel.SetAsLastSibling();

            return(true);
        }
Exemplo n.º 10
0
        public void OnPointerEnteredCanvas(DynamicPanelsCanvas canvas, PointerEventData pointer)
        {
            if (draggedPanel != null && pointer.pointerDrag != null)
            {
                PanelHeader header = pointer.pointerDrag.GetComponent <PanelHeader>();
                if (header != null)
                {
                    if (header.Panel == draggedPanel && header.Panel.RectTransform.parent != canvas.RectTransform)
                    {
                        previewPanelCanvas = canvas;

                        header.Panel.RectTransform.SetParent(canvas.RectTransform, false);
                        header.Panel.RectTransform.SetAsLastSibling();
                    }
                }
                else
                {
                    PanelTab tab = pointer.pointerDrag.GetComponent <PanelTab>();
                    if (tab != null)
                    {
                        if (tab.Panel == draggedPanel && previewPanel.parent != canvas.RectTransform)
                        {
                            previewPanelCanvas = canvas;

                            if (hoveredAnchorZone && hoveredAnchorZone.Panel.Canvas != canvas)
                            {
                                hoveredAnchorZone.OnPointerExit(pointer);
                            }

                            previewPanel.SetParent(canvas.RectTransform, false);
                            previewPanel.SetAsLastSibling();
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 public InternalSettings(PanelTab tab)
 {
     this.tab      = tab;
     RectTransform = (RectTransform)tab.transform;
 }
Exemplo n.º 12
0
        public int AddTab(RectTransform tabContent, int tabIndex = -1)
        {
            if (tabContent == null || tabContent.Equals(null))
            {
                return(-1);
            }

            RectTransform contentTR = tabContent.transform as RectTransform;

            if (contentTR == null)
            {
                Debug.LogError("Content must have a RectTransform!");
                return(-1);
            }

            // Reset active tab because otherwise, it acts buggy in rare cases
            if (m_activeTab >= 0 && m_activeTab < tabs.Count)
            {
                tabs[m_activeTab].SetActive(false);
            }

            m_activeTab = -1;

            if (tabIndex < 0)
            {
                tabIndex = tabs.Count;
            }
            else if (tabIndex > tabs.Count)
            {
                tabIndex = tabs.Count;
            }

            int thisTabIndex = GetTabIndex(tabContent);

            if (thisTabIndex == -1)
            {
                PanelTab tab;
                Panel    tabCurrentPanel      = tabContent.GetComponentInParent <Panel>();
                int      tabCurrentPanelIndex = -1;
                if (tabCurrentPanel == null || (tabCurrentPanelIndex = tabCurrentPanel.GetTabIndex(tabContent)) < 0)
                {
                    tab = Instantiate(Resources.Load <PanelTab>("DynamicPanelTab"), tabsParent, false);
                    tabs.Insert(tabIndex, tab);

                    contentTR.anchorMin        = Vector2.zero;
                    contentTR.anchorMax        = Vector2.one;
                    contentTR.sizeDelta        = Vector2.zero;
                    contentTR.anchoredPosition = Vector2.zero;
                    contentTR.localScale       = Vector3.one;
                }
                else
                {
                    tab = tabCurrentPanel.tabs[tabCurrentPanelIndex];
                    tabs.Insert(tabIndex, tab);

                    tab.RectTransform.SetParent(null, false);                       // workaround for a rare internal Unity crash
                    tab.RectTransform.SetParent(tabsParent, false);

                    tabCurrentPanel.Internal.RemoveTab(tabCurrentPanelIndex, false);
                    Internal.RecalculateMinSize();
                }

                tab.Initialize(this, contentTR);
                tab.RectTransform.SetSiblingIndex(tabIndex);

                contentTR.SetParent(null, false);                   // workaround for a rare internal Unity crash
                contentTR.SetParent(contentParent, false);
            }
            else if (thisTabIndex != tabIndex)
            {
                if (tabIndex == tabs.Count)
                {
                    tabIndex = tabs.Count - 1;
                }

                PanelTab tab = tabs[thisTabIndex];
                tab.RectTransform.SetSiblingIndex(tabIndex);

                tabs.RemoveAt(thisTabIndex);
                tabs.Insert(tabIndex, tab);
            }

            ActiveTab = tabIndex;
            return(tabIndex);
        }
Exemplo n.º 13
0
 public abstract bool Execute(PanelTab panelTab, PointerEventData eventData);
Exemplo n.º 14
0
        public PanelTab AddTab(RectTransform tabContent, int tabIndex = -1)
        {
            if (!tabContent)
            {
                return(null);
            }

            // Reset active tab because otherwise, it acts buggy in rare cases
            if (m_activeTab >= 0 && m_activeTab < tabs.Count)
            {
                tabs[m_activeTab].Internal.SetActive(false);
            }

            m_activeTab = -1;

            if (tabIndex < 0 || tabIndex > tabs.Count)
            {
                tabIndex = tabs.Count;
            }

            int thisTabIndex = GetTabIndex(tabContent);

            if (thisTabIndex == -1)
            {
                PanelTab tab = PanelUtils.GetAssociatedTab(tabContent);
                if (!tab)
                {
                    PanelTab panelTabPrefab = null;

#if UNITY_EDITOR
                    panelTabPrefab = Resources.Load <PanelTab>("DynamicPanelTab");
#else
                    panelTabPrefab = GameObject.Find("BTDebugInspector").GetComponent <DesignerData>().DynamicPanelTab.GetComponent <PanelTab>();
#endif

                    if (panelTabPrefab == null)
                    {
                        Debug.LogError("PanelTabPrefab is null");
                    }
                    tab = (PanelTab)Instantiate(panelTabPrefab, tabsParent, false);
                    tabs.Insert(tabIndex, tab);

                    tabContent.anchorMin        = Vector2.zero;
                    tabContent.anchorMax        = Vector2.one;
                    tabContent.sizeDelta        = Vector2.zero;
                    tabContent.anchoredPosition = Vector2.zero;
                    tabContent.localScale       = Vector3.one;
                }
                else
                {
                    tabs.Insert(tabIndex, tab);

                    tab.Internal.RectTransform.SetParent(null, false); // workaround for a rare internal Unity crash
                    tab.Internal.RectTransform.SetParent(tabsParent, false);

                    tab.Panel.Internal.RemoveTab(tab.Index, false);
                }

                tab.Internal.Initialize(this, tabContent);
                tab.Internal.RectTransform.SetSiblingIndex(tabIndex);

                tabContent.SetParent(null, false); // workaround for a rare internal Unity crash
                tabContent.SetParent(contentParent, false);

                Internal.RecalculateMinSize();
            }
            else if (thisTabIndex != tabIndex)
            {
                if (tabIndex == tabs.Count)
                {
                    tabIndex = tabs.Count - 1;
                }

                PanelTab tab = tabs[thisTabIndex];
                tab.Internal.RectTransform.SetSiblingIndex(tabIndex);

                tabs.RemoveAt(thisTabIndex);
                tabs.Insert(tabIndex, tab);
            }

            ActiveTab = tabIndex;
            return(tabs[tabIndex]);
        }
Exemplo n.º 15
0
        public PanelTab AddTab(RectTransform tabContent, int tabIndex = -1)
        {
            if (tabContent == null || tabContent.Equals(null))
            {
                return(null);
            }

            // Reset active tab because otherwise, it acts buggy in rare cases
            if (m_activeTab >= 0 && m_activeTab < tabs.Count)
            {
                tabs[m_activeTab].Internal.SetActive(false);
            }

            m_activeTab = -1;

            if (tabIndex < 0 || tabIndex > tabs.Count)
            {
                tabIndex = tabs.Count;
            }

            int thisTabIndex = GetTabIndex(tabContent);

            if (thisTabIndex == -1)
            {
                PanelTab tab = PanelUtils.GetAssociatedTab(tabContent);
                if (tab == null)
                {
                    tab = (PanelTab)Instantiate(Resources.Load <PanelTab>("DynamicPanelTab"), tabsParent, false);
                    tabs.Insert(tabIndex, tab);

                    tabContent.anchorMin        = Vector2.zero;
                    tabContent.anchorMax        = Vector2.one;
                    tabContent.sizeDelta        = Vector2.zero;
                    tabContent.anchoredPosition = Vector2.zero;
                    tabContent.localScale       = Vector3.one;
                }
                else
                {
                    tabs.Insert(tabIndex, tab);

                    tab.Internal.RectTransform.SetParent(null, false);                       // workaround for a rare internal Unity crash
                    tab.Internal.RectTransform.SetParent(tabsParent, false);

                    tab.Panel.Internal.RemoveTab(tab.Index, false);
                }

                tab.Internal.Initialize(this, tabContent);
                tab.Internal.RectTransform.SetSiblingIndex(tabIndex);

                tabContent.SetParent(null, false);                   // workaround for a rare internal Unity crash
                tabContent.SetParent(contentParent, false);

                Internal.RecalculateMinSize();
            }
            else if (thisTabIndex != tabIndex)
            {
                if (tabIndex == tabs.Count)
                {
                    tabIndex = tabs.Count - 1;
                }

                PanelTab tab = tabs[thisTabIndex];
                tab.Internal.RectTransform.SetSiblingIndex(tabIndex);

                tabs.RemoveAt(thisTabIndex);
                tabs.Insert(tabIndex, tab);
            }

            ActiveTab = tabIndex;
            return(tabs[tabIndex]);
        }
Exemplo n.º 16
0
 public void RemoveTab(PanelTab tab)
 {
     RemoveTab(GetTabIndex(tab));
 }
        private static ISerializedElement Serialize(IPanelGroupElement element)
        {
            if (element == null)
            {
                return(null);
            }

            if (element is Panel)
            {
                Panel panel = (Panel)element;
                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(Direction.Right),
                children = children,
                size = panelGroup.Size
            });
        }
Exemplo n.º 18
0
 public Panel DetachTab(PanelTab tab)
 {
     return(DetachTab(GetTabIndex(tab)));
 }
Exemplo n.º 19
0
            public static Panel CreatePanel(RectTransform content, DynamicPanelsCanvas canvas)
            {
                bool canvasWasNull = canvas == null;

                if (canvasWasNull)
                {
                    if (content != null)
                    {
                        canvas = content.GetComponentInParent <DynamicPanelsCanvas>();
                    }

                    if (canvas == null)
                    {
                        canvas = Object.FindObjectOfType <DynamicPanelsCanvas>();
                        if (!canvas)
                        {
                            Debug.LogError("Panels require a DynamicPanelsCanvas!");
                            return(null);
                        }
                    }
                }

                Panel result = null;

                if (content != null)
                {
                    PanelTab currentTab = GetAssociatedTab(content);
                    if (currentTab != null)
                    {
                        result = currentTab.Panel;
                    }
                }

                if (result == null)
                {
                    Panel panelPrefab = null;
#if UNITY_EDITOR
                    panelPrefab = Resources.Load <Panel>("DynamicPanel");
#else
                    panelPrefab = GameObject.Find("BTDebugInspector").GetComponent <DesignerData>().DynamicPanel.GetComponent <Panel>();
#endif
                    result = (Panel)Object.Instantiate(panelPrefab, canvas.RectTransform, false);
                    result.gameObject.name = "DynamicPanel";
                    result.RectTransform.SetAsLastSibling();

                    if (content != null)
                    {
                        Rect contentRect = content.rect;

                        result.RectTransform.anchoredPosition = (Vector2)canvas.RectTransform.InverseTransformPoint(content.TransformPoint(contentRect.position)) + canvas.Size * 0.5f;
                        result.FloatingSize = contentRect.size;
                    }
                }
                else if (result.Canvas != canvas && !canvasWasNull)
                {
                    canvas.UnanchoredPanelGroup.AddElement(result);
                }

                if (content != null)
                {
                    result.AddTab(content);
                }

                return(result);
            }