/// <summary> /// adds the event to the close panel /// </summary> /// <param name="popup">the popup on wich the event is triggered</param> private IEnumerator SetCancelListener(PopupElement popup) { if (!popup.DimIsInteractable) { yield break; } yield return(new WaitForSecondsRealtime(AnimTime + DimInteractionDelay)); closePanelButton.onClick.RemoveAllListeners(); closePanelButton.onClick.AddListener(popup.ExecuteCancel); closePanelButton.interactable = true; }
/// <summary> /// shows the dimmer /// </summary> /// <param name="popup">The popup we are attaching the dimmer to</param> /// <param name="hideOnDimAction">Whether to hide the popup when the user clicks anywhere outside the popup</param> private void ShowDimmer(PopupElement popup, bool hideOnDimAction) { pn_closePanel.SetActive(true); LeanTween.cancel(img_closePanelImage.gameObject, false); LeanTween.value(img_closePanelImage.gameObject, img_closePanelImage.color.a, 0.7f, DimTime).setIgnoreTimeScale(true) .setOnUpdate(x => img_closePanelImage.color = new Color(img_closePanelImage.color.r, img_closePanelImage.color.g, img_closePanelImage.color.b, x)) .setOnComplete(() => { if (hideOnDimAction) { StartCoroutine(SetCancelListener(popup)); } }); }
/// <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); }
/// <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); } }