Exemple #1
0
 internal void SetScrollTarget(DebugUIHandlerWidget widget)
 {
     if (m_UIPanels != null && m_SelectedPanel < m_UIPanels.Count && m_UIPanels[m_SelectedPanel] != null)
     {
         m_UIPanels[m_SelectedPanel].SetScrollTarget(widget);
     }
 }
        void ActivatePanel(int index, bool tryAndKeepSelection = false)
        {
            if (m_UIPanels.Count == 0)
            {
                return;
            }

            if (index >= m_UIPanels.Count)
            {
                index = m_UIPanels.Count - 1;
            }

            m_UIPanels.ForEach(p => p.gameObject.SetActive(false));
            m_UIPanels[index].gameObject.SetActive(true);
            m_SelectedPanel = index;

            DebugUIHandlerWidget widget = null;

            if (tryAndKeepSelection && !string.IsNullOrEmpty(m_CurrentQueryPath))
            {
                widget = m_UIPanels[m_SelectedPanel]
                         .GetComponentsInChildren <DebugUIHandlerWidget>()
                         .FirstOrDefault(w => w.GetWidget().queryPath == m_CurrentQueryPath);
            }

            if (widget == null)
            {
                widget = m_UIPanels[index].GetFirstItem();
            }

            ChangeSelection(widget, true);
        }
Exemple #3
0
 /// <summary>
 /// OnSelection implementation.
 /// </summary>
 /// <param name="fromNext">True if the selection wrapped around.</param>
 /// <param name="previous">Previous widget.</param>
 /// <returns>State of the widget.</returns>
 public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
 {
     nextButtonText.color     = colorSelected;
     previousButtonText.color = colorSelected;
     nameLabel.color          = colorSelected;
     valueLabel.color         = colorSelected;
     return(true);
 }
Exemple #4
0
        internal bool IsDirectChild(DebugUIHandlerWidget widget)
        {
            if (contentHolder.childCount == 0)
            {
                return(false);
            }

            return(GetActiveChildren()
                   .Count(x => x == widget) > 0);
        }
        /// <summary>
        /// OnSelection implementation.
        /// </summary>
        /// <param name="fromNext">True if the selection wrapped around.</param>
        /// <param name="previous">Previous widget.</param>
        /// <returns>True if the selection is allowed.</returns>
        public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
        {
            if (!fromNext && !m_Container.IsDirectChild(previous))
            {
                var lastItem = m_Container.GetLastItem();
                DebugManager.instance.ChangeSelection(lastItem, false);
                return(true);
            }

            return(false);
        }
Exemple #6
0
        void Traverse(DebugUI.IContainer container, Transform parentTransform, DebugUIHandlerWidget parentUIHandler, ref DebugUIHandlerWidget selectedHandler)
        {
            DebugUIHandlerWidget previousUIHandler = null;

            for (int i = 0; i < container.children.Count; i++)
            {
                var child = container.children[i];

                if (child.isEditorOnly || child.isHidden)
                {
                    continue;
                }

                Transform prefab;

                if (!m_PrefabsMap.TryGetValue(child.GetType(), out prefab))
                {
                    Debug.LogWarning("DebugUI widget doesn't have a prefab: " + child.GetType());
                    continue;
                }

                var go = Instantiate(prefab, parentTransform, false).gameObject;
                go.name = child.displayName;
                var uiHandler = go.GetComponent <DebugUIHandlerWidget>();

                if (uiHandler == null)
                {
                    Debug.LogWarning("DebugUI prefab is missing a DebugUIHandler for: " + child.GetType());
                    continue;
                }

                if (!string.IsNullOrEmpty(m_CurrentQueryPath) && child.queryPath.Equals(m_CurrentQueryPath))
                {
                    selectedHandler = uiHandler;
                }

                if (previousUIHandler != null)
                {
                    previousUIHandler.nextUIHandler = uiHandler;
                }
                uiHandler.previousUIHandler = previousUIHandler;
                previousUIHandler           = uiHandler;
                uiHandler.parentUIHandler   = parentUIHandler;
                uiHandler.SetWidget(child);

                var childContainer = go.GetComponent <DebugUIHandlerContainer>();
                if (childContainer != null && child is DebugUI.IContainer childAsContainer)
                {
                    Traverse(childAsContainer, childContainer.contentHolder, uiHandler, ref selectedHandler);
                }
            }
        }
        // TODO: Jumps around with foldouts and the likes, fix me
        internal void ScrollTo(DebugUIHandlerWidget target)
        {
            if (target == null)
            {
                return;
            }

            var targetTransform = target.GetComponent <RectTransform>();

            float itemY           = GetYPosInScroll(targetTransform);
            float targetY         = GetYPosInScroll(m_MaskTransform);
            float normalizedDiffY = (targetY - itemY) / (m_ContentTransform.rect.size.y - m_ScrollTransform.rect.size.y);
            float normalizedPosY  = scrollRect.verticalNormalizedPosition - normalizedDiffY;

            normalizedPosY = Mathf.Clamp01(normalizedPosY);
            scrollRect.verticalNormalizedPosition = Mathf.Lerp(scrollRect.verticalNormalizedPosition, normalizedPosY, Time.deltaTime * 10f);
        }
        /// <summary>
        /// OnSelection implementation.
        /// </summary>
        /// <param name="fromNext">True if the selection wrapped around.</param>
        /// <param name="previous">Previous widget.</param>
        /// <returns>True if the selection is allowed.</returns>
        public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
        {
            if (fromNext || valueToggle.isOn == false)
            {
                nameLabel.color = colorSelected;
            }
            else if (valueToggle.isOn)
            {
                if (m_Container.IsDirectChild(previous))
                {
                    nameLabel.color = colorSelected;
                }
                else
                {
                    var lastItem = m_Container.GetLastItem();
                    DebugManager.instance.ChangeSelection(lastItem, false);
                }
            }

            return(true);
        }
Exemple #9
0
        internal void ChangeSelection(DebugUIHandlerWidget widget, bool fromNext)
        {
            if (widget == null)
            {
                return;
            }

            if (m_SelectedWidget != null)
            {
                m_SelectedWidget.OnDeselection();
            }

            var prev = m_SelectedWidget;

            m_SelectedWidget = widget;
            SetScrollTarget(widget);

            if (!m_SelectedWidget.OnSelection(fromNext, prev))
            {
                if (fromNext)
                {
                    SelectNextItem();
                }
                else
                {
                    SelectPreviousItem();
                }
            }
            else
            {
                if (m_SelectedWidget == null || m_SelectedWidget.GetWidget() == null)
                {
                    m_CurrentQueryPath = string.Empty;
                }
                else
                {
                    m_CurrentQueryPath = m_SelectedWidget.GetWidget().queryPath;
                }
            }
        }
Exemple #10
0
        void ActivatePanel(int index, DebugUIHandlerWidget selectedWidget = null)
        {
            if (m_UIPanels.Count == 0)
            {
                return;
            }

            if (index >= m_UIPanels.Count)
            {
                index = m_UIPanels.Count - 1;
            }

            m_UIPanels.ForEach(p => p.gameObject.SetActive(false));
            m_UIPanels[index].gameObject.SetActive(true);
            m_SelectedPanel = index;

            if (selectedWidget == null)
            {
                selectedWidget = m_UIPanels[index].GetFirstItem();
            }

            ChangeSelection(selectedWidget, true);
        }
 internal void SetScrollTarget(DebugUIHandlerWidget target)
 {
     m_ScrollTarget = target;
 }
 /// <summary>
 /// OnSelection implementation.
 /// </summary>
 /// <param name="fromNext">True if the selection wrapped around.</param>
 /// <param name="previous">Previous widget.</param>
 /// <returns>True if the selection is allowed.</returns>
 public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
 {
     nameLabel.color      = colorSelected;
     checkmarkImage.color = colorSelected;
     return(true);
 }
 // Returns `true` if selection is allowed, `false` to skip to the next/previous item
 public virtual bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
 {
     return(true);
 }
Exemple #14
0
        void Rebuild()
        {
            // Check prefab associations
            m_PrefabsMap.Clear();
            foreach (var bundle in prefabs)
            {
                var type = Type.GetType(bundle.type);

                if (type != null && bundle.prefab != null)
                {
                    m_PrefabsMap.Add(type, bundle.prefab);
                }
            }

            m_UIPanels.Clear();

            m_DebugTreeState = DebugManager.instance.GetState();
            var panels = DebugManager.instance.panels;

#if UNITY_ANDROID || UNITY_IPHONE
            // Mobile device safe area
            Rect  parentRect  = GetComponentInParent <RectTransform>().rect;
            float parentWidth = Math.Min(parentRect.width, parentRect.height);
            float scaleRatio  = parentWidth / Math.Min(Screen.height, Screen.width);

            Rect    safeAreaRect       = Screen.safeArea;
            Vector2 margin             = new Vector2(5, 5);
            var     safeAreaOffsetLeft = safeAreaRect.xMin * scaleRatio;
            var     safeAreaOffsetTop  = -safeAreaRect.yMin * scaleRatio;
            Vector2 safeAreaOffset     = new Vector2(safeAreaOffsetLeft, safeAreaOffsetTop) + margin;
#endif

            DebugUIHandlerWidget selectedWidget = null;
            foreach (var panel in panels)
            {
                if (panel.isEditorOnly || panel.children.Count(x => !x.isEditorOnly && !x.isHidden) == 0)
                {
                    continue;
                }

                var go = Instantiate(panelPrefab, transform, false).gameObject;
                go.name = panel.displayName;

#if UNITY_ANDROID || UNITY_IPHONE
                RectTransform rectTransform = go.GetComponent <RectTransform>();
                rectTransform.anchoredPosition = safeAreaOffset;
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, safeAreaRect.height * scaleRatio + 2 * safeAreaOffsetTop);
#endif

                var uiPanel = go.GetComponent <DebugUIHandlerPanel>();
                uiPanel.SetPanel(panel);
                uiPanel.Canvas = this;
                m_UIPanels.Add(uiPanel);
                var container = go.GetComponent <DebugUIHandlerContainer>();
                DebugUIHandlerWidget selected = null;
                Traverse(panel, container.contentHolder, null, ref selected);

                if (selected != null && selected.GetWidget().queryPath.Contains(panel.queryPath))
                {
                    selectedWidget = selected;
                }
            }

            ActivatePanel(m_SelectedPanel, selectedWidget);
        }
 /// <summary>
 /// Method called when the box is selected
 /// </summary>
 /// <param name="fromNext">If is from next</param>
 /// <param name="previous">The previous <see cref="DebugUIHandlerWidget"/></param>
 /// <returns></returns>
 public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
 {
     return(false);
 }
Exemple #16
0
        /// <summary>
        /// Update implementation.
        /// </summary>
        protected void Update()
        {
            var row   = CastWidget <DebugUI.Table.Row>();
            var table = row.parent as DebugUI.Table;

            float refreshRate = 0.1f;
            bool  refreshRow  = m_Timer >= refreshRate;

            if (refreshRow)
            {
                m_Timer -= refreshRate;
            }
            m_Timer += Time.deltaTime;

            for (int i = 0; i < row.children.Count; i++)
            {
                if (!TryGetChild(i, out var child))
                {
                    continue;
                }

                bool active = IsActive(table, i, child);
                if (child != null)
                {
                    child.SetActive(active);
                }
                if (active && refreshRow)
                {
                    if (child.TryGetComponent <DebugUIHandlerColor>(out var color))
                    {
                        color.UpdateColor();
                    }
                    if (child.TryGetComponent <DebugUIHandlerToggle>(out var toggle))
                    {
                        toggle.UpdateValueLabel();
                    }
                    if (child.TryGetComponent <DebugUIHandlerObjectList>(out var list))
                    {
                        list.UpdateValueLabel();
                    }
                }
            }

            // Update previous and next ui handlers to skip hidden volumes
            var itemWidget = GetChild(0).GetComponent <DebugUIHandlerWidget>();
            DebugUIHandlerWidget previous = null;

            for (int i = 0; i < row.children.Count; i++)
            {
                itemWidget.previousUIHandler = previous;
                if (!TryGetChild(i, out var child))
                {
                    continue;
                }

                if (IsActive(table, i, child))
                {
                    previous = itemWidget;
                }

                bool found = false;
                for (int j = i + 1; j < row.children.Count; j++)
                {
                    if (!TryGetChild(j, out var innerChild))
                    {
                        continue;
                    }

                    if (IsActive(table, j, innerChild))
                    {
                        var childWidget = child.GetComponent <DebugUIHandlerWidget>();
                        itemWidget.nextUIHandler = childWidget;
                        itemWidget = childWidget;
                        i          = j - 1;
                        found      = true;
                        break;
                    }
                }
                if (!found)
                {
                    itemWidget.nextUIHandler = null;
                    break;
                }
            }
        }
        /// <summary>
        /// Update implementation.
        /// </summary>
        protected void Update()
        {
            var row   = CastWidget <DebugUI.Table.Row>();
            var table = row.parent as DebugUI.Table;

            float refreshRate = 0.1f;
            bool  refreshRow  = m_Timer >= refreshRate;

            if (refreshRow)
            {
                m_Timer -= refreshRate;
            }
            m_Timer += Time.deltaTime;

            for (int i = 0; i < row.children.Count; i++)
            {
                var child  = gameObject.transform.GetChild(1).GetChild(i).gameObject;
                var active = table.GetColumnVisibility(i);
                child.SetActive(active);
                if (active && refreshRow)
                {
                    if (child.TryGetComponent <DebugUIHandlerColor>(out var color))
                    {
                        color.UpdateColor();
                    }
                    if (child.TryGetComponent <DebugUIHandlerToggle>(out var toggle))
                    {
                        toggle.UpdateValueLabel();
                    }
                }
            }

            // Update previous and next ui handlers to pass over hidden volumes
            var item       = gameObject.transform.GetChild(1).GetChild(0).gameObject;
            var itemWidget = item.GetComponent <DebugUIHandlerWidget>();
            DebugUIHandlerWidget previous = null;

            for (int i = 0; i < row.children.Count; i++)
            {
                itemWidget.previousUIHandler = previous;
                if (table.GetColumnVisibility(i))
                {
                    previous = itemWidget;
                }

                bool found = false;
                for (int j = i + 1; j < row.children.Count; j++)
                {
                    if (table.GetColumnVisibility(j))
                    {
                        var child       = gameObject.transform.GetChild(1).GetChild(j).gameObject;
                        var childWidget = child.GetComponent <DebugUIHandlerWidget>();
                        itemWidget.nextUIHandler = childWidget;
                        item       = child;
                        itemWidget = childWidget;
                        i          = j - 1;
                        found      = true;
                        break;
                    }
                }
                if (!found)
                {
                    itemWidget.nextUIHandler = null;
                    break;
                }
            }
        }