Beispiel #1
0
        /// <summary>
        /// Create a popup of given type that inherits <see cref="PopupElementV3"/>
        /// </summary>
        /// <param name="T">The Type of popup to create</param>
        /// <param name="canSpawn">Action that returns the <see cref="PopupElementV3"/> only if popup was succesfully spawned this action is invoked</param>
        /// <param name="hideOnDimAction">Whether to hide the popup when the user clicks anywhere outside the popup</param>
        public void CreatePopup(Type T, Action <PopupElement> canSpawn = null, bool hideOnDimAction = true)
        {
#if UNITY_EDITOR
            if (!Popups.ContainsKey(T))
            {
                Debug.LogError(string.Concat("You forgot to add the prefab for the ", T.Name, " to the popupmanager."));
                return;
            }
#endif

            Popups[T].SetActive(false);
            PopupElement popup = (PopupElement)Instantiate(Popups[T], transform).GetComponent(T);

            // Check whether we can spawn the popup using it's own given condition
            if (!popup.CanSpawn(canSpawn))
            {
                return;
            }

            // If the popup spawned setup popupmanagers side
            activePopups++;
            if (activePopups > 1)
            {
                PopupQueue.Enqueue(popup);
            }
            else
            {
                popupStatusChange?.Invoke(true);
                popup.gameObject.SetActive(true);
                CoroutineManager.Instance.WaitForEndOfFrame(() => popup.Show());
                ShowDimmer(popup, hideOnDimAction);
                CurrentPopup = popup;
            }

            // Add hide popup method for closing the dim
            popup.CancelEvent  += () => Closepopup(popup);
            popup.DismissEvent += () => Closepopup(popup);
            popup.SucceedEvent += () => Closepopup(popup);

            // sets up the popups side
            canSpawn?.Invoke(popup);
        }
Beispiel #2
0
        /// <summary>
        /// closes the currently active popup and shows the next one in line if there is one
        /// </summary>
        public void Closepopup(PopupElement previousPopup)
        {
            activePopups--;
            PreviousPopup = previousPopup;

            if (PopupQueue.Count != 0)
            {
                PopupElement popup = PopupQueue.Dequeue();
                popup.gameObject.SetActive(true);
                CoroutineManager.Instance.WaitForEndOfFrame(() => {
                    CoroutineManager.Instance.Wait(0.2f, () => popup.Show());
                });

                StartCoroutine(SetCancelListener(popup));
            }

            if (activePopups <= 0)
            {
                HideDimmer();
                activePopups = 0;
                popupStatusChange?.Invoke(false);
            }
        }