123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /****************************************************************************
- * Copyright (c) 2021.8 liangxie
- *
- * http://qframework.io
- * https://github.com/liangxiegame/QFramework
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- ****************************************************************************/
- using UnityEngine;
- namespace QFramework
- {
- public class UIKit
- {
- public static UIKitConfig Config = new UIKitConfig();
- public static UIRoot Root
- {
- get { return Config.Root; }
- }
- /// <summary>
- /// UI 堆栈
- /// </summary>
- public static readonly UIPanelStack Stack = new UIPanelStack();
- /// <summary>
- /// UIPanel 管理(数据结构)
- /// </summary>
- public static readonly UIPanelTable Table = new UIPanelTable();
- public static T OpenPanel<T>(PanelOpenType panelOpenType, UILevel canvasLevel = UILevel.Common,
- IUIData uiData = null,
- string assetBundleName = null,
- string prefabName = null) where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.OpenType = panelOpenType;
- panelSearchKeys.Level = canvasLevel;
- panelSearchKeys.PanelType = typeof(T);
- panelSearchKeys.AssetBundleName = assetBundleName;
- panelSearchKeys.GameObjName = prefabName;
- panelSearchKeys.UIData = uiData;
- T retPanel = UIManager.Instance.OpenUI(panelSearchKeys) as T;
- panelSearchKeys.Recycle2Cache();
- return retPanel;
- }
- public static T OpenPanel<T>(UILevel canvasLevel = UILevel.Common, IUIData uiData = null,
- string assetBundleName = null,
- string prefabName = null) where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.OpenType = PanelOpenType.Single;
- panelSearchKeys.Level = canvasLevel;
- panelSearchKeys.PanelType = typeof(T);
- panelSearchKeys.AssetBundleName = assetBundleName;
- panelSearchKeys.GameObjName = prefabName;
- panelSearchKeys.UIData = uiData;
- T retPanel = UIManager.Instance.OpenUI(panelSearchKeys) as T;
- panelSearchKeys.Recycle2Cache();
- return retPanel;
- }
- public static T OpenPanel<T>(IUIData uiData, PanelOpenType panelOpenType = PanelOpenType.Single,
- string assetBundleName = null,
- string prefabName = null) where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.OpenType = panelOpenType;
- panelSearchKeys.Level = UILevel.Common;
- panelSearchKeys.PanelType = typeof(T);
- panelSearchKeys.AssetBundleName = assetBundleName;
- panelSearchKeys.GameObjName = prefabName;
- panelSearchKeys.UIData = uiData;
- T retPanel = UIManager.Instance.OpenUI(panelSearchKeys) as T;
- panelSearchKeys.Recycle2Cache();
- return retPanel;
- }
- public static void ClosePanel<T>() where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.PanelType = typeof(T);
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- public static void ShowPanel<T>() where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.PanelType = typeof(T);
- UIManager.Instance.ShowUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- public static void HidePanel<T>() where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.PanelType = typeof(T);
- UIManager.Instance.HideUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- public static void CloseAllPanel()
- {
- UIManager.Instance.CloseAllUI();
- }
- public static void HideAllPanel()
- {
- UIManager.Instance.HideAllUI();
- }
- public static T GetPanel<T>() where T : UIPanel
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.PanelType = typeof(T);
- var retPanel = UIManager.Instance.GetUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- return retPanel as T;
- }
- #region 给脚本层用的 api
- public static UIPanel GetPanel(string panelName)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = panelName;
- var retPanel = UIManager.Instance.GetUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- return retPanel;
- }
- public static UIPanel OpenPanel(string panelName, UILevel level = UILevel.Common, string assetBundleName = null)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.Level = level;
- panelSearchKeys.AssetBundleName = assetBundleName;
- panelSearchKeys.GameObjName = panelName;
- var retPanel = UIManager.Instance.OpenUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- return retPanel as UIPanel;
- }
- public static void ClosePanel(string panelName)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = panelName;
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
-
- public static void ClosePanel(UIPanel panel)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
-
- panelSearchKeys.Panel = panel;
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- public static void ShowPanel(string panelName)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = panelName;
- UIManager.Instance.ShowUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- public static void HidePanel(string panelName)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = panelName;
- UIManager.Instance.HideUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- #endregion
- public static void Back(string currentPanelName)
- {
- if (!string.IsNullOrEmpty(currentPanelName))
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = currentPanelName;
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- Stack.Pop();
- }
- public static void Back(UIPanel currentPanel)
- {
- if (currentPanel != null)
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.GameObjName = currentPanel.name;
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- }
- Stack.Pop();
- }
- public static void Back<T>()
- {
- var panelSearchKeys = PanelSearchKeys.Allocate();
- panelSearchKeys.PanelType = typeof(T);
- UIManager.Instance.CloseUI(panelSearchKeys);
- panelSearchKeys.Recycle2Cache();
- Stack.Pop();
- }
-
- }
- }
|