private void Close(PopupViewBase popup) { popupsManager.Remove(popup); if (popup != null) { Destroy(popup.gameObject); } var queuedPopup = popupsManager.DequeuePopup(); if (queuedPopup != null) { Open(queuedPopup.PopupData, queuedPopup.OnOpened, queuedPopup.OnFail); } }
public OpenPopupResponse(PopupViewBase popup, Exception exception = null) { if (exception != null) { Exception = exception; } if (popup != null) { OpenedPopup = popup; } else if (exception != null) { Exception = new NullReferenceException(); } }
public async void Open(PopupEntityBase popupData, Action <PopupViewBase> onOpened = null, Action onFail = null) { var rulesToOpen = container.TryResolveId <List <PopupRuleBase> >(popupData.PopupOpenRule); var canBePopupOpened = popupsManager.CanPopupBeOpened(rulesToOpen); if (canBePopupOpened) { PopupViewBase view = null; if (popupData is PopupEntityWithId entityWithId) { var request = new LoadPopupAssetRequest() { AssetId = entityWithId.PopupId, }; var response = await eventBus.FireAsync <LoadPopupAssetRequest, LoadPopupAssetResponse>(request); var isError = response.Exception != null; if (isError) { OnPopupLoadedFailHandler(response.Exception); } else { view = response.Result; } } else if (popupData is PopupEntityWithAssetPrefab entityWithPrefab) { view = entityWithPrefab.PopupViewPrefab; } OnPopupLoadedSuccessHandler(view, popupData, onOpened); } else { popupsManager.EnqueuePopup(popupData, onOpened, onFail); } }
private void OnPopupLoadedSuccessHandler(PopupViewBase popupView, PopupEntityBase popupData, Action <PopupViewBase> onSuccess) { var instantiatePrefab = container.InstantiatePrefab(popupView); var eventWrapperComponent = instantiatePrefab.AddComponent <MonoBehaviourEventWrapperComponent>(); var instantiatedPopupView = instantiatePrefab.GetComponent <PopupViewBase>(); eventWrapperComponent.OnDestroyEvent += OnDestroyEventHandler; instantiatedPopupView.OnHided += OnHideEventHandler; void OnHideEventHandler(PopupViewBase p) { RemoveSubscriptions(); Close(instantiatedPopupView); } void OnDestroyEventHandler() { RemoveSubscriptions(); Close(instantiatedPopupView); } void RemoveSubscriptions() { eventWrapperComponent.OnDestroyEvent -= OnDestroyEventHandler; instantiatedPopupView.OnHided -= OnHideEventHandler; } instantiatedPopupView.Data = popupData; instantiatedPopupView.SetData(popupData); instantiatedPopupView.Show(); var canvas = GetCanvasTransform(popupData.CanvasType); instantiatePrefab.transform.SetParent(canvas, false); onSuccess?.Invoke(instantiatedPopupView); popupsManager.AddPopupAsVisible(instantiatedPopupView); }
public void AddVisiblePopup(PopupViewBase instantiatedPopupView) { visiblePopups.Add(instantiatedPopupView); }
public void RemoveVisiblePopup(PopupViewBase popupView) { var popup = visiblePopups.First(x => x == popupView); visiblePopups.Remove(popup); }
protected void OnSuccess(PopupViewBase openedPopup) { cachedPopup = openedPopup; Debug.Log($"Popup has been opened { openedPopup.gameObject.name }"); }
public void AddPopupAsVisible(PopupViewBase instantiatedPopupView) { popupsModuleStorage.AddVisiblePopup(instantiatedPopupView); }
public void Remove(PopupViewBase popup) { popupsModuleStorage.RemoveVisiblePopup(popup); }