コード例 #1
0
        /// <summary>
        /// Auto-focuses the first response. Useful for gamepads.
        /// </summary>
        public void AutoFocus(GameObject lastSelection = null, bool allowStealFocus = true)
        {
            if (UnityEngine.EventSystems.EventSystem.current == null)
            {
                return;
            }
            var currentSelection = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;

            if (currentSelection == null)
            {
                currentSelection = lastSelection;
                UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(lastSelection);
            }

            // If anything is selected and we're not allowed to steal focus, stop:
            if (currentSelection != null && !allowStealFocus)
            {
                return;
            }

            // If a button is already auto-focused, keep it focused and stop there:
            if (instantiatedButtons.Find(x => x.gameObject == currentSelection) != null)
            {
                return;
            }
            for (int i = 0; i < buttons.Length; i++)
            {
                if (buttons[i] != null && buttons[i].gameObject == currentSelection)
                {
                    return;
                }
            }

            if (instantiatedButtons.Count > 0)
            {
                // Otherwise try to focus an instantiated button:
                UITools.Select(instantiatedButtons[0].GetComponent <UnityEngine.UI.Button>(), allowStealFocus);
            }
            else
            {
                // Failing that, focus a designed button:
                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i] != null && buttons[i].clickable)
                    {
                        UITools.Select(buttons[i].button, allowStealFocus);
                        return;
                    }
                }
            }
        }
コード例 #2
0
        protected IEnumerator SelectElement(UnityEngine.UI.Selectable elementToSelect)
        {
            yield return(null);

            UITools.Select(elementToSelect);
        }
コード例 #3
0
        public override void OnQuestListUpdated()
        {
            if (!m_isAwake)
            {
                return;
            }
            UnityEngine.UI.Selectable elementToSelect = null;
            showingActiveQuestsHeading.SetActive(isShowingActiveQuests);
            showingCompletedQuestHeading.SetActive(!isShowingActiveQuests);
            selectionPanelContentManager.Clear();
            var questTitleTemplate = isShowingActiveQuests ? activeQuestHeadingTemplate : completedQuestHeadingTemplate;

            // Get group names, and draw selected quest in its panel while we're at it:
            var groupNames            = new List <string>();
            int numGroupless          = 0;
            var repaintedQuestDetails = false;

            if (quests.Length > 0)
            {
                foreach (var quest in quests)
                {
                    if (IsSelectedQuest(quest))
                    {
                        RepaintSelectedQuest(quest);
                        repaintedQuestDetails = true;
                    }
                    var groupName = quest.Group;
                    if (string.IsNullOrEmpty(groupName))
                    {
                        numGroupless++;
                    }
                    if (string.IsNullOrEmpty(groupName) || groupNames.Contains(groupName))
                    {
                        continue;
                    }
                    groupNames.Add(groupName);
                }
            }
            if (!repaintedQuestDetails)
            {
                RepaintSelectedQuest(null);
            }

            // Add quests by group:
            foreach (var groupName in groupNames)
            {
                var groupFoldout = selectionPanelContentManager.Instantiate <StandardUIFoldoutTemplate>(questGroupTemplate);
                selectionPanelContentManager.Add(groupFoldout, questSelectionContentContainer);
                groupFoldout.Assign(groupName, IsGroupExpanded(groupName));
                var targetGroupName    = groupName;
                var targetGroupFoldout = groupFoldout;
                if (!keepGroupsExpanded)
                {
                    groupFoldout.foldoutButton.onClick.AddListener(() => { OnClickGroup(targetGroupName, targetGroupFoldout); });
                }
                if (string.Equals(foldoutToSelect, groupName))
                {
                    elementToSelect = groupFoldout.foldoutButton;
                    foldoutToSelect = null;
                }
                foreach (var quest in quests)
                {
                    if (string.Equals(quest.Group, groupName))
                    {
                        var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(questTitleTemplate);
                        questTitle.Assign(quest.Title, quest.Heading.text, OnToggleTracking);
                        selectionPanelContentManager.Add(questTitle, groupFoldout.interiorPanel);
                        var target = quest.Title;
                        questTitle.button.onClick.AddListener(() => { OnClickQuest(target); });
                        if (showDetailsOnSelect)
                        {
                            AddShowDetailsOnSelect(questTitle.button, target);
                        }
                        if (string.Equals(quest.Title, questTitleToSelect))
                        {
                            elementToSelect    = questTitle.button;
                            questTitleToSelect = null;
                        }
                    }
                }
            }

            // Add groupless quests:
            foreach (var quest in quests)
            {
                if (!string.IsNullOrEmpty(quest.Group))
                {
                    continue;
                }
                var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(questTitleTemplate);
                questTitle.Assign(quest.Title, quest.Heading.text, OnToggleTracking);
                selectionPanelContentManager.Add(questTitle, questSelectionContentContainer);
                var target = quest.Title;
                questTitle.button.onClick.AddListener(() => { OnClickQuest(target); });
                if (showDetailsOnSelect)
                {
                    AddShowDetailsOnSelect(questTitle.button, target);
                }
                if (string.Equals(quest.Title, questTitleToSelect))
                {
                    elementToSelect    = questTitle.button;
                    questTitleToSelect = null;
                }
            }

            // If no quests, add no quests text:
            if (quests.Length == 0 && showNoQuestsText)
            {
                var questTitle = selectionPanelContentManager.Instantiate <StandardUIQuestTitleButtonTemplate>(completedQuestHeadingTemplate);
                var dummyText  = IsShowingActiveQuests ? noActiveQuestsText : noCompletedQuestsText;
                questTitle.Assign(dummyText, dummyText, null);
                selectionPanelContentManager.Add(questTitle, questSelectionContentContainer);
            }

            SetStateToggleButtons();
            mainPanel.RefreshSelectablesList();
            if (mainPanel != null)
            {
                UnityEngine.UI.LayoutRebuilder.MarkLayoutForRebuild(mainPanel.GetComponent <RectTransform>());
            }
            if (elementToSelect != null)
            {
                StartCoroutine(SelectElement(elementToSelect));
            }
            else if (UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject == null && mainPanel != null && mainPanel.firstSelected != null && InputDeviceManager.autoFocus)
            {
                UITools.Select(mainPanel.firstSelected.GetComponent <UnityEngine.UI.Selectable>());
            }
        }
コード例 #4
0
 /// <summary>
 /// Auto-focuses the continue button. Useful for gamepads.
 /// </summary>
 public void AutoFocus(bool allowStealFocus = true)
 {
     UITools.Select(continueButton, allowStealFocus);
 }
コード例 #5
0
 /// <summary>
 /// Selects the panel's continue button (i.e., navigates to it).
 /// </summary>
 /// <param name="allowStealFocus">Select continue button even if another element is already selected.</param>
 public virtual void Select(bool allowStealFocus = true)
 {
     UITools.Select(continueButton, allowStealFocus);
 }
コード例 #6
0
        public void AutoFocus()
        {
            GameObject go = completedQuestsButton.gameObject.activeSelf ? completedQuestsButton.gameObject : activeQuestsButton.gameObject;

            UITools.Select(go.GetComponent <UnityEngine.UI.Selectable>());
        }