/* Работа с экранами несколько отличается от работы модальных окон * Модальное окно может быть в единсвенном колличестве и они в очереди открытия, одно за другим * Экрны же могут открываться сворачивая предыдущий экран, а когда экран закрывается, то разворачивается предыдущий * в этом и вся разница */ public void CreateMainScreen <TController, TView>(ControllerData paramsScreen) where TController : IControllerUI <TView> { titlePanelUIView.gameObject.SetActive(true); var id = ScreenId.GetMainScreen(); if (id == null) { Debug.LogError("ВНИМАНИЕ!!! НЕТ ГЛАВНОГО ЭКРАНА В КОНФИГЕ!!!"); return; } var controller = default(TController); controller = (TController)Activator.CreateInstance(typeof(TController)); controller.SetData(paramsScreen); var createdAction = new Action <object>((obj) => { controller.OnCreatedView(((TView)obj)); }); var prefab = GetPrefab(id, "[Screen]"); var screen = Instantiate(prefab, screenRect).GetComponent <AbstractView>(); closedActionMain = new Action(() => { controller.OnWantToCloseView((TView)(screen as object)); }); destroyActionMain = new Action(() => { controller.OnDestoyView((TView)(screen as object)); }); currentMainScreen = screen; screen.GetComponent <RectTransform>().SetSiblingIndex(-999999); createdAction?.Invoke(screen); titlePanelUIView.SetScreenConfig("Main Screen", id.Config.TitleConfig); }
/// <summary> /// Экран закрылся /// </summary> private void OnCloseCurrentScreen(object screenObj) { if (stackScreen != null && stackScreen.Count > 0) { var screen = (screenObj as AbstractView); screen.OnClose -= OnCloseCurrentScreen; if (OpenedScreens.ContainsKey(screenObj)) { OnCloseView?.Invoke(screenObj as IViewUI, OpenedScreens[screenObj].Id); OnCloseScreenView?.Invoke(screenObj as IViewUI, OpenedScreens[screenObj].Id); OpenedScreens[screenObj].OnDestroy?.Invoke(screenObj); OpenedScreens.Remove(screenObj); if (OpenedScreens.Count > 0) { var openedScreen = OpenedScreens.Last(); var config = openedScreen.Value.Id.Config.TitleConfig; titlePanelUIController.SetScreenConfig(openedScreen.Value.Id.Name, config); } else { if (currentMainScreen != null) { var config = ScreenId.GetMainScreen().Config.TitleConfig; titlePanelUIController.SetScreenConfig("", config); } else { titlePanelUIController.SetScreenConfig("", TitlePanelConfig.GetEmpty()); } } } stackScreen.Remove(screen); //.RemoveAt(stackScreen.Count - 1); if (currentScreen == screen) { currentScreen = null; } } NextScreen(); if (!IsAnyOpenScreen) { if (currentMainScreen != null) { var config = ScreenId.GetMainScreen().Config.TitleConfig; titlePanelUIController.SetScreenConfig("", config); } else { titlePanelUIController.SetScreenConfig("", TitlePanelConfig.GetEmpty()); } } }
public void CreateWindow <TController, TView>(ScreenId id, ControllerData paramsWindow, bool showOnTop = false) where TController : IControllerUI <TView> { titlePanelUIView.gameObject.SetActive(true); var prefab = GetPrefab(id, "[Window]"); var target = modalRect; var winGo = Instantiate(prefab, target); var window = winGo.GetComponent <AbstractWindow>(); window.SetTitle(id.Name); var controller = (TController)Activator.CreateInstance(typeof(TController)); controller.SetData(paramsWindow); var createdAction = new Action <object>((obj) => { controller.OnCreatedView((TView)obj); }); var closedAction = new Action <object>((obj) => { controller.OnWantToCloseView((TView)obj); }); var destroyAction = new Action <object>((obj) => { controller.OnDestoyView((TView)obj); }); window.OnWantClose += (z) => { if (OpenedWindows.ContainsKey(z)) { closedAction?.Invoke(z); } }; window.OnClose += (z) => { if (OpenedWindows.ContainsKey(z)) { OpenedWindows[z].OnDestroy?.Invoke(z); OnCloseView?.Invoke(z as IViewUI, OpenedWindows[z].Id); OnCloseWindowView?.Invoke(z as IViewUI, OpenedWindows[z].Id); OpenedWindows.Remove(z); if (OpenedWindows.Count > 0) { var last = OpenedWindows.Last(); var config = last.Value.Id.Config.TitleConfig; } else { if (IsAnyOpenScreen) { if (OpenedScreens.Count > 0) { var openedScreen = OpenedScreens.Last(); var config = openedScreen.Value.Id.Config.TitleConfig; } } else { if (currentMainScreen != null) { var config = ScreenId.GetMainScreen().Config.TitleConfig; titlePanelUIController.SetScreenConfig("", config); } else { titlePanelUIController.SetScreenConfig("", TitlePanelConfig.GetEmpty()); } } } } }; createdAction.Invoke(window); var windowElement = new ViewElementData { ViewElement = window, Id = id, OnClosed = closedAction, OnCreated = createdAction, OnDestroy = destroyAction }; OpenedWindows[window] = windowElement; }