Beispiel #1
0
        /// <summary>
        /// Checks list of tabs for tab matching given content.
        /// </summary>
        /// <param name="menuContent"></param>
        /// <returns>Returns matching tab. Returns null if no tab found.</returns>
        private IMenuTab GetTabForContent(IMenuContent menuContent)
        {
            int      index = GetIndexOfTabForContent(menuContent);
            IMenuTab tab   = GetTabAtIndex(index);

            return(tab);
        }
Beispiel #2
0
        /// <summary>
        /// Updates tab draw order and views the given menu content.
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="content"></param>
        /// <param name="fadeTime"></param>
        private void TabAndContentToShow(IMenuTab tab, IMenuContent content, float fadeTime)
        {
            if (tab == null || content == null)
            {
                return;
            }

            CanvasGroup  previousCGroup  = currentContent?.CGroup;
            IMenuContent previousContent = currentContent;

            currentContent = content;
            UpdateTabDrawOrder();
            if (previousCGroup != null)
            {
                void finishAction()
                {
                    previousCGroup.gameObject.SetActive(false);
                    previousContent.OnClose();
                }

                StartCoroutine(TimedAction(fadeTime,
                                           (float delta) => previousCGroup.alpha = 1f - delta,
                                           finishAction));
            }
            CanvasGroup currentCGroup = currentContent.CGroup;

            currentCGroup.gameObject.SetActive(true);
            currentContent.OnOpen();
            StartCoroutine(TimedAction(fadeTime,
                                       (float delta) => currentCGroup.alpha = delta,
                                       null));
        }
Beispiel #3
0
        protected virtual void Open()
        {
            gameObject.SetActive(true);

            ClearTabsHolder();
            AddPreExistingMenuContentsToList();
            InstantiateTabContentPrefabs();
            CreateTabs();
            UpdateTabDrawOrder();
            SubscribeToTabClickEvents();

            KeyValuePair <int, IMenuContent> firstContent = menuContents.FirstOrDefault();

            currentContent = firstContent.Value;
            ContentToShow(currentContent, 0f);
        }
Beispiel #4
0
        /// <summary>
        /// Add any pre-existing menu contents to menu contents list, ignoring anything with a duplicate tab name.
        /// </summary>
        private void AddPreExistingMenuContentsToList()
        {
            menuContents.Clear();
            currentContent = null;

            foreach (Transform child in menuContentHolder)
            {
                IMenuContent menuContent = child.GetComponent <IMenuContent>();
                if (menuContent == null || ContainsTabWithName(menuContent.TabName))
                {
                    Destroy(child.gameObject);
                    continue;
                }
                menuContent.CGroup.alpha = 0f;
                menuContent.CGroup.gameObject.SetActive(false);
                menuContents.Add(menuContent.PreferredTabIndex, menuContent);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Checks list of tabs for index of the tab matching given content.
        /// </summary>
        /// <param name="menuContent"></param>
        /// <returns>Returns index for tab that matches the content. Returns -1 if match not found.</returns>
        private int GetIndexOfTabForContent(IMenuContent menuContent)
        {
            if (menuContent == null)
            {
                return(-1);
            }

            string tabName = menuContent.TabName;

            for (int i = 0; i < tabs.Count; i++)
            {
                if (tabs[i].TabText == tabName)
                {
                    return(i);
                }
            }
            return(-1);
        }
Beispiel #6
0
 /// <summary>
 /// Create all menu contents from prefab list, excluding anything with a duplicate tab name.
 /// </summary>
 private void InstantiateTabContentPrefabs()
 {
     for (int i = 0; i < menuContentPrefabs.Count; i++)
     {
         IMenuContent prefab = menuContentPrefabs[i] as IMenuContent;
         if (prefab == null)
         {
             Debug.Log($"Menu Content prefab is not of type: {typeof(IMenuContent)}", menuContentPrefabs[i]);
             continue;
         }
         if (ContainsTabWithName(prefab.TabName))
         {
             continue;
         }
         IMenuContent newContent = prefab.CreateCopy(menuContentHolder);
         newContent.CGroup.alpha = 0f;
         newContent.CGroup.gameObject.SetActive(false);
         menuContents.Add(newContent.PreferredTabIndex, newContent);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Checks list of tabs looking for a match with given content.
        /// </summary>
        /// <param name="menuContent"></param>
        /// <returns>Returns true if matching tab is found.</returns>
        private bool TabExistsForContent(IMenuContent menuContent)
        {
            IMenuTab tab = GetTabForContent(menuContent);

            return(tab != null);
        }
Beispiel #8
0
        /// <summary>
        /// Updates tab draw order and views the given menu content.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="fadeTime"></param>
        private void ContentToShow(IMenuContent content, float fadeTime)
        {
            IMenuTab tab = GetTabForContent(content);

            TabAndContentToShow(tab, content, fadeTime);
        }
Beispiel #9
0
        /// <summary>
        /// Updates tab draw order and views the appropriate menu content associated with the given tab.
        /// </summary>
        /// <param name="tab"></param>
        /// <param name="fadeTime"></param>
        private void TabToShow(IMenuTab tab, float fadeTime)
        {
            IMenuContent content = GetContentMatchingTab(tab);

            TabAndContentToShow(tab, content, fadeTime);
        }