// pops corresponding popup and calls transition event public void Pop(GamePopup popup) { if (!initialized) { Debug.LogError(debugableInterface.debugLabel + "Not initialized"); return; } Type type = GetTypeFromPopup(popup); if (type == null) { Debug.LogError(debugableInterface.debugLabel + "Couln't find type for GamePopup " + popup.ToString()); return; } else { Popup selected = scenePopups.Find(item => { return(item.GetType() == type); }); if (selected == null) { Debug.LogError(debugableInterface.debugLabel + "Couldn't find Popup for GamePopup " + popup.ToString()); return; } else { selected.Activate(this); actualPopup = popup; // FadeMusicIn.Invoke(); } } }
PopupEventSubscription GetSubscriptionEvent(GamePopup popup) { PopupEventSubscription popupEvent = popupsSubscriptions.Find(item => { return(item.popup == popup); }); if (popupEvent == null) { Debug.LogWarning(debugableInterface.debugLabel + "Couldn't find PopupEventSubscription for popup " + popup.ToString()); return(null); } return(popupEvent); }
// call this when you get on a new scene (like an Init but every time you change scenes) public void GetAllScenePopups() { scenePopups = new List <Popup>(); scenePopups.AddRange(Resources.FindObjectsOfTypeAll <Popup>()); scenePopups.ForEach(item => { item.Init( fadeDuration, alphaComparisonThreshold, () => { actualPopup = item.popup; }, () => GetSubscriptionEvent(item.popup).CallEvent() ); }); }
public void SubscribeEvent(GamePopup popup, Action callback) { if (!initialized) { Debug.LogError(debugableInterface.debugLabel + "Not initialized"); return; } PopupEventSubscription eventSubscription = GetSubscriptionEvent(popup); if (callback != null) { eventSubscription.AddEvent(callback); } }
public void Init(Action fadeMusicOut) { actualPopup = GamePopup.EMPTY; FadeMusicOut = fadeMusicOut; popupsSubscriptions = new List <PopupEventSubscription>(); // init all event subscriptions (we can then subscribe events) foreach (GamePopup popup in Enum.GetValues(typeof(GamePopup))) { popupsSubscriptions.Add(new PopupEventSubscription(popup)); } initializableInterface.InitInternal(); }
Type GetTypeFromPopup(GamePopup popup) { switch (popup) { case GamePopup.EMPTY: return(null); case GamePopup.TITLE_SETTINGS: return(null); case GamePopup.SHOGUN_DEDUCTION: return(typeof(ShogunPopup)); } return(null); }
public PopupEventSubscription(GamePopup popup) { this.popup = popup; }