// todo 这个传参也很麻烦, public static void OpenView(ViewID key, UIEventArgs args = null) { ViewBase view = GetView(key); if (view != null) { view.SetOpenParam(args); if (BeforeOpen(view) == false) { return; } // 已加载过 if (view.isLoaded) { InitView(view); } else { view.Load(InitView); } } else { GameLog.LogError("[UIModule]界面实例化失败" + key.ToString()); } }
public static void CloseView(ViewID key) { ViewBase view = GetView(key); if (view != null) { if (view.isOpen) { view.Close(); UINavigation.RemoveLastItem(view); } else { GameLog.LogWarning("[UIModule]界面关闭失败,已经关闭!" + key.ToString()); } } else { GameLog.LogError("[UIModule]界面关闭失败,没有找到指定界面!" + key.ToString()); } }
public void OpenView(ViewID viewID, OpenViewTag openTag = OpenViewTag.Nune, bool needAnim = true, UnityAction onComplate = null, params object[] args) { BaseView view = null; this._viewDic.TryGetValue(viewID, out view); if (view != null) { Debug.Log("[UIManager] OpenView: " + viewID); ViewConfigData viewCfgData = view.ViewData; switch (openTag) { case OpenViewTag.HidePrevious: { if (this._navigationStack.Count > 0) { CloseView(this._navigationStack.Peek().viewID, false, false, null); } } break; } if (viewCfgData._isNavigation) { pushToNavigation(new ViewNavigationData() { viewID = viewCfgData._viewID, data = args }); } switch (viewCfgData._mountLayer) { case ViewMountLayer.Fixed: { refreshSibling(view, this.FixedLayer); } break; case ViewMountLayer.Popup: { refreshSibling(view, this.PopupLayer); } break; case ViewMountLayer.MessageBox: { refreshSibling(view, this.MessageBoxLayer); } break; } view.gameObject.SetActive(true); view.OnShowView(needAnim, onComplate, args); } else { Debug.Log("[UIManager] loadView: " + viewID); AssetManager.Instance.LoadAssetAsync <BaseView>(GameConfigs.GetUIPath(UIDefine.viewPaths[viewID]), (BaseView viewPrefab) => { view = GameObject.Instantiate(viewPrefab).GetComponent <BaseView>(); switch (view.ViewData._mountLayer) { case ViewMountLayer.Fixed: { view.transform.SetParent(this.FixedLayer); } break; case ViewMountLayer.Popup: { view.transform.SetParent(this.PopupLayer); } break; case ViewMountLayer.MessageBox: { view.transform.SetParent(this.MessageBoxLayer); } break; } RectTransform rt = view.GetComponent <RectTransform>(); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.one; view.transform.localScale = Vector3.one; view.transform.localPosition = Vector3.zero; view.gameObject.name = viewID.ToString(); GameUtils.SetLayer(view.gameObject, LayerMask.NameToLayer("UI")); view.Init(); this._viewDic.Add(viewID, view); OpenView(viewID, openTag, needAnim, onComplate, args); }); } }
/// <summary> /// Инициализировать атрибуты данных /// </summary> protected void InitDataAttrs() { DataAttrs = new SortedList <string, string>(); DataAttrs.Add("view", ViewID.ToString()); DataAttrs.Add("cnl", AlarmCnlNum.ToString()); }