Example #1
0
        private UiEventNavigation[] GenerateLanguageCheckboxes()
        {
            // Setup return variable
            UiEventNavigation[] returnToggles = new UiEventNavigation[supportedLanguages.Count];

            // Setup the first button
            StringBuilder nameBuilder = new StringBuilder();

            SetupToggle(languageCheckbox, supportedLanguages[0], nameBuilder);
            returnToggles[0] = languageCheckbox.Navigation;

            // Setup the rest of the buttons
            LanguageToggle clonedToggle;

            for (int index = 1; index < supportedLanguages.Count; ++index)
            {
                // Duplicate the toggle
                clonedToggle = DuplicateToggle(languageCheckbox);

                // Setup the toggle
                SetupToggle(clonedToggle, supportedLanguages[index], nameBuilder);
                returnToggles[index] = clonedToggle.Navigation;
            }

            return(returnToggles);
        }
Example #2
0
        public UiEventNavigation ScrollToLastSelectedElement(UiEventNavigation defaultElement, bool forceCenter)
        {
            // Make sure the last selected element is within the scrollable list
            if ((LastSelectedElement != null) && (UiElementsInScrollableSet.Contains(LastSelectedElement) == true))
            {
                // Change the default element to the last selected one
                defaultElement = LastSelectedElement;
            }

            // Scroll to this element
            ScrollToSelectable(defaultElement, forceCenter);
            return(defaultElement);
        }
Example #3
0
        public void ScrollToSelectable(UiEventNavigation selectable, bool forceCenter)
        {
            // Check if we have the scroll view open
            if ((scrollable != null) && (selectable != null))
            {
                // Scroll to this control
                ScrollingHelper.ScrollVerticallyTo(scrollable, selectable, boundsCache, forceCenter);

                // Highlight this element
                MenuManager manager = Singleton.Get <MenuManager>();
                if (manager != null)
                {
                    manager.SelectGui(selectable.Selectable);
                }
            }
        }
Example #4
0
        private void SetupUiElementsInScrollable(UiEventNavigation nextElement, ref UiEventNavigation lastElement, ref UiEventNavigation topMostElement)
        {
            // Check if this is the top-most element
            if (topMostElement == null)
            {
                // If so, set the variable
                topMostElement = nextElement;
            }

            // Check if there's an element above this
            ResetNavigation(nextElement.Selectable);
            SetNextNavigation(lastElement, nextElement.Selectable, (enableNavigatingToSlider ? VerticalScrollbar : null));
            if (lastElement != null)
            {
                SetPreviousNavigation(lastElement.Selectable, nextElement);
            }
            lastElement = nextElement;
        }
        public static void ScrollVerticallyTo(ScrollRect parentScrollRect, UiEventNavigation childControl, Dictionary <UiEventNavigation, SingleAxisBounds> cacheDict = null, bool centerTo = false)
        {
            if ((parentScrollRect != null) && (childControl != null) && (childControl.Selectable != null))
            {
                // Check the cache, and see if the bounds for this child control already exists
                SingleAxisBounds childBounds;
                if ((cacheDict == null) || (cacheDict.TryGetValue(childControl, out childBounds) == false))
                {
                    // Calculate the top and bottom position of the the control
                    float topPos, centerPos, bottomPos;
                    centerPos   = GetVerticalAnchoredPositionInContent(parentScrollRect.content, childControl, out topPos, out bottomPos);
                    childBounds = new SingleAxisBounds(topPos, centerPos, bottomPos);

                    // Cache these values
                    if (cacheDict != null)
                    {
                        cacheDict.Add(childControl, childBounds);
                    }
                }

                // Check whether we need to scroll or not, and if so, in which snapping direction
                ScrollVerticalSnap snapTo = ScrollVerticalSnap.CenterToChild;
                if (centerTo == false)
                {
                    snapTo = GetVerticalSnapping(parentScrollRect.content, parentScrollRect.viewport, ref childBounds);
                }

                // Check whether we want to scroll or not
                if (snapTo != ScrollVerticalSnap.None)
                {
                    // Grab the position to scroll to
                    float selectionPosition = GetScrollToPosition(parentScrollRect.viewport, snapTo, ref childBounds);

                    // Clamp the selection position value
                    float maxPosition = (parentScrollRect.content.rect.height - parentScrollRect.viewport.rect.height);
                    selectionPosition = Mathf.Clamp(selectionPosition, 0, maxPosition);

                    // Directly set the position of the ScrollRect's content
                    Vector3 scrollPosition = parentScrollRect.content.anchoredPosition;
                    scrollPosition.y = selectionPosition;
                    parentScrollRect.content.anchoredPosition = scrollPosition;
                }
            }
        }
Example #6
0
        private Scrollbar SetupHorizontalScrollBar(UiEventNavigation lastElement)
        {
            Scrollbar horizontalScrollbar = null;

            if ((lastElement != null) && (scrollable != null) && (scrollable.horizontal == true) && (scrollable.horizontalScrollbar != null) && (scrollable.viewport.rect.width < scrollable.content.rect.width))
            {
                horizontalScrollbar = scrollable.horizontalScrollbar;
                SetNextNavigation(lastElement, horizontalScrollbar);

                // Grab the current navigation values
                Navigation newNavigation = horizontalScrollbar.navigation;

                // Customize the navigation
                newNavigation.mode             = Navigation.Mode.Explicit;
                newNavigation.selectOnUp       = lastElement.Selectable;
                horizontalScrollbar.navigation = newNavigation;
            }
            return(horizontalScrollbar);
        }
Example #7
0
        private static void SetNextNavigation(UiEventNavigation lastElement, Selectable currentElement, Scrollbar verticalScrollbar = null)
        {
            // Check if the last and current element is available
            if (lastElement != null)
            {
                // Grab the last navigation values
                Navigation newNavigation = lastElement.Selectable.navigation;

                // Customize the navigation for vertical
                if ((lastElement.ToNextUi & UiEventNavigation.Direction.Up) != 0)
                {
                    newNavigation.selectOnUp = currentElement;
                }
                if ((lastElement.ToNextUi & UiEventNavigation.Direction.Down) != 0)
                {
                    newNavigation.selectOnDown = currentElement;
                }

                // Check if element is not a slider
                if ((lastElement.Selectable is Slider) == false)
                {
                    // Customize the navigation for horizontal
                    if ((lastElement.ToNextUi & UiEventNavigation.Direction.Left) != 0)
                    {
                        newNavigation.selectOnLeft = currentElement;
                    }
                    if ((lastElement.ToNextUi & UiEventNavigation.Direction.Right) != 0)
                    {
                        newNavigation.selectOnRight = currentElement;
                    }
                    else if (verticalScrollbar != null)
                    {
                        // If right-direction navigation isn't overridden, and a scrollbar is provided,
                        // navigate to the scroll on right
                        newNavigation.selectOnRight = verticalScrollbar;
                    }
                }
                lastElement.Selectable.navigation = newNavigation;
            }
        }
Example #8
0
        private static void SetupUiElementsBelowScrollable(UiEventNavigation nextElement, Scrollbar horizontalScrollbar, ref UiEventNavigation lastElement, ref UiEventNavigation topMostElement)
        {
            // Check if this is the top-most element
            if (topMostElement == null)
            {
                // If so, set the variable
                topMostElement = nextElement;
            }

            // Check if there's an element above this
            ResetNavigation(nextElement.Selectable);
            SetNextNavigation(lastElement, nextElement.Selectable);
            if (horizontalScrollbar != null)
            {
                // If the horizontal scroll bar is above these elements, setup navigation to that first
                SetPreviousNavigation(horizontalScrollbar, nextElement);
            }
            else if (lastElement != null)
            {
                // If last element is available, setup that element
                SetPreviousNavigation(lastElement.Selectable, nextElement);
            }
            lastElement = nextElement;
        }
        public static float GetVerticalAnchoredPositionInContent(RectTransform contentTransform, UiEventNavigation childControl, out float top, out float bottom)
        {
            top    = 0f;
            bottom = 0f;
            float returnCenter = 0f;

            if ((childControl != null) && (childControl.Selectable != null))
            {
                // Calculate as normal
                GetVerticalAnchoredPositionInContent(contentTransform, ((RectTransform)childControl.Selectable.transform), out top, out bottom);
                returnCenter = (top + bottom) / 2f;

                // Grab new top value
                if (childControl.UpperBoundToScrollTo != null)
                {
                    float dummyBottom;
                    GetVerticalAnchoredPositionInContent(contentTransform, childControl.UpperBoundToScrollTo, out top, out dummyBottom);
                }

                // Grab new bottom value
                if (childControl.LowerBoundToScrollTo != null)
                {
                    float dummyTop;
                    GetVerticalAnchoredPositionInContent(contentTransform, childControl.LowerBoundToScrollTo, out dummyTop, out bottom);
                }
            }
            return(returnCenter);
        }
        public static float GetVerticalAnchoredPositionInContent(RectTransform contentTransform, UiEventNavigation childControl)
        {
            float selectionPosition = 0f;

            if ((childControl != null) && (childControl.Selectable != null))
            {
                selectionPosition = GetVerticalAnchoredPositionInContent(contentTransform, ((RectTransform)childControl.Selectable.transform));
            }
            return(selectionPosition);
        }