[TWLFramework] UIManager

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class UIManager : Singleton<UIManager>
{

//UI gameobjects
public Dictionary<E_UIType, GameObject> _dictUIs = new Dictionary<E_UIType, GameObject>();
//UI panels
public Dictionary<E_PanelType, GameObject> _dictPanels = new Dictionary<E_PanelType, GameObject>();

void Awake()
{
_instance = this;
}

#region 打开UI 关闭UI

//打开UI
public void OpenUI(E_UIType uiType, bool closeOtherUI, object args)
{
if (closeOtherUI == true)
{
CloseUIAll();
}
if (_dictUIs.ContainsKey(uiType))
{
_dictUIs[uiType].SetActive(true);
}
else
{
GameObject go = MonoBehaviour.Instantiate(Resources.Load("UIPrefabs/" + uiType.ToString())) as GameObject;
_dictUIs.Add(uiType, go);
}
BaseUI bu = _dictUIs[uiType].GetComponent<BaseUI>();
if (bu != null)
{
bu.UIState = E_UIState.Open;
Debug.Log("do set ui state");
}
if (args != null)
{
bu.LoadData(args);
}

Debug.Log("UIManager存了:" + _dictUIs.Count + " 个UI");
}
//打开UI 重载
public void OpenUI(E_UIType uiType, bool closeOtherUI)
{
OpenUI(uiType, closeOtherUI, null);
}
//打开UI 重载
public void OpenUI(E_UIType uiType)
{
OpenUI(uiType, false);
}

//关闭UI
public void CloseUI(E_UIType uiType)
{
if (!_dictUIs.ContainsKey(uiType)) return;
BaseUI bu = _dictUIs[uiType].GetComponent<BaseUI>();
if (bu != null)
{
bu.UIState = E_UIState.Close;
}
_dictUIs[uiType].SetActive(false);
//_dictUIs.Remove(uiType);
//Destroy(go);
Debug.Log("SetActive false 一个UI : " + uiType);
}
//关闭所有UI
public void CloseUIAll()
{
if (_dictUIs == null) return;
List<E_UIType> UIkeys = new List<E_UIType>(_dictUIs.Keys);

for (int i = 0; i < UIkeys.Count; i++)
{
CloseUI(UIkeys[i]);
}
_dictUIs.Clear();
}
public void ClearAllUI()
{
_dictUIs.Clear();
}
//拿到指定的UI
public GameObject GetUIObj(E_UIType uiType)
{
if (_dictUIs.ContainsKey(uiType))
{
return _dictUIs[uiType];
}
else
{
return null;
}
}
#endregion

#region 打开Panel 关闭Panel
//init Save Panels
public void SavePanel(E_PanelType type, GameObject panel)
{
if (!_dictPanels.ContainsKey(type))
{
_dictPanels.Add(type, panel);
Debug.Log("save panel : " + type);
}
}
//打开Panel
public void OpenPanel(E_PanelType type, bool CloseOthers, bool closeOthersButMain, E_PanelType dontCloseType)
{
//关闭其他Panel
if (!CloseOthers)
{
if (closeOthersButMain)
{
if (dontCloseType == E_PanelType.None)
CloseAllButMainPanel();
else
CloseAllButMainPanel(dontCloseType);
}
else
{
CloseAllPanel();
}
}
//打开Panel
if (_dictPanels.ContainsKey(type))
{
if (!_dictPanels[type].activeSelf)
{
_dictPanels[type].SetActive(true);
BasePanel bp = _dictPanels[type].GetComponent<BasePanel>();
if (bp != null)
{
bp.PanelState = E_PanelState.Open;
}
Debug.Log("open panel type : " + type);
}
}
}
//重载打开panel
public void OpenPanel(E_PanelType type, bool dontCloseOthers, bool closeOthersButMain)
{
OpenPanel(type, dontCloseOthers, closeOthersButMain, E_PanelType.None);
}
//重载打开panel
public void OpenPanel(E_PanelType type, E_PanelType dontClose)
{
OpenPanel(type, false, false);
}
//重载打开panel
public void OpenPanel(E_PanelType type, bool closeAssignPanel)
{
OpenPanel(type, false, false);
}
public void OpenPanel(E_PanelType type)
{

OpenPanel(type, true, false, E_PanelType.None);
}

//关闭Panel
public void ClosePanel(E_PanelType type)
{
if (_dictPanels.ContainsKey(type))
{
if (_dictPanels[type].activeSelf)
{
BasePanel bp = _dictPanels[type].GetComponent<BasePanel>();
if (bp != null)
{
bp.PanelState = E_PanelState.Close;
}
_dictPanels[type].SetActive(false);
Debug.Log("close panel type : " + type);
}
}
}
//关闭所有panel
public void CloseAllPanel()
{
CloseAllPanel(E_PanelType.None);
}
//关闭所有 but assignpanel
public void CloseAllPanel(E_PanelType type)
{
List<E_PanelType> list = new List<E_PanelType>(_dictPanels.Keys);
for (int i = 0; i < list.Count; i++)
{
if (list[i] == type)
continue;
ClosePanel(list[i]);
}
}
//关闭UIpanel 但是不关闭mian Panel
public void CloseAllButMainPanel()
{
List<E_PanelType> list = new List<E_PanelType>(_dictPanels.Keys);
for (int i = 0; i < list.Count; i++)
{
if (list[i] == E_PanelType.E_BtnPanel || list[i] == E_PanelType.E_MianFacePanel)
continue;
ClosePanel(list[i]);
}
}
//不关闭mian pane And assigen panel
public void CloseAllButMainPanel(E_PanelType type)
{
List<E_PanelType> list = new List<E_PanelType>(_dictPanels.Keys);
for (int i = 0; i < list.Count; i++)
{
if (list[i] == E_PanelType.E_BtnPanel || list[i] == E_PanelType.E_MianFacePanel || list[i] == type)
continue;
ClosePanel(list[i]);
}
}
//关闭UIpanel 但是不关闭指定 Panel
public void CloseOthersButAssignPanel(E_PanelType type)
{
CloseAllPanel(type);
}
//重新载入场景 清空所有
public void ClearDictPanel()
{
//if (_dictPanels.Count > 0)
//{
// List<E_PanelType> list = new List<E_PanelType>(_dictPanels.Keys);
// for (int i = 0; i < list.Count; i++)
// {
// MonoBehaviour.Destroy(_dictPanels[list[i]]);
// }
//}
_dictPanels.Clear();
}

//拿到指定panel
public GameObject GetPanelObj(E_PanelType type)
{
if (_dictPanels.ContainsKey(type))
{
return _dictPanels[type];
}
return null;
}

#endregion

}

时间: 2024-10-15 23:23:46

[TWLFramework] UIManager的相关文章

UI(UGUI)框架(二)-------------UIManager单例模式与开发BasePanel面板基类/UIManage统一管理UI面板的实例化/开发字典扩展类

UIManage单实例: 1 /// 单例模式的核心 2 /// 1,定义一个静态的对象 在外界访问 在内部构造 3 /// 2,构造方法私有化 4 5 private static UIManager _instance; 6 7 public static UIManager Instance 8 { 9 get 10 { 11 if (_instance == null) 12 { 13 _instance = new UIManager(); 14 } 15 return _instan

[TWLFramework] BasePanel

using UnityEngine;using System.Collections; public abstract class BasePanel : MonoBehaviour{ //panel State protected E_PanelState _panelState; public E_PanelState PanelState { get { return _panelState; } set { E_PanelState old = this._panelState; thi

Swing中使用UIManager批量自定义单一JComponent组件默认属性

最近在研究Swing,被它的复杂性气的快吐血了,刚才本打算把JFrame的背景色换成白底,结果发现事情没想象中那么顺利,调用setBackground完全没有效果,猛然醒悟到JPanel本身是带不透明底色的,事情一下子变得复杂起来了,因为即便最简单的窗口布局,也是嵌套了若干层JPanel.JSplitPane等容器的,一层遮盖一层,而要想统一改成白底的话,那得一个个改代码,或者用复杂的遍历算法... 百度上寻觅了一下,发现一个老去已久的帖子有提及到使用UIManager来批量更改默认值的,例如:

[TWLFramework] Singleton

using UnityEngine;using System.Collections; //单例模式 public class Singleton<T> where T : class, new(){ protected static T _instance = null; public static T Instance { get { if (_instance == null) { _instance = new T(); } return _instance; } } protecte

[TWLFramework] Message

using UnityEngine;using System.Collections;using System.Collections.Generic;using System;/* 消息体 直接遍历 key访问 message[key] send() remove() add() 构造函数参数=>sender type(name) content*/ public class Message : IEnumerable<KeyValuePair<string, object>&g

[TWLFramework] MessageCenter

using UnityEngine;using System.Collections;using System.Collections.Generic; public class MessageCenter : Singleton<MessageCenter>{ private Dictionary<string, List<MessageEvent>> _dictMessageEvent = null; public override void Init() { _d

[TWLFramework] BaseUI

using UnityEngine;using System.Collections; public abstract class BaseUI : MonoBehaviour{ //缓存 gameobject 和 transform private GameObject _cacheGameObject; public GameObject CacheGameObject { get { if (_cacheGameObject == null) { _cacheGameObject = th

[TWLFramework] 全局委托 全局枚举

using UnityEngine;using System.Collections; #region 全局委托 public delegate void MessageEvent(Message message); #endregion #region 全局枚举//panel Typepublic enum E_UIType{ None, FaceUI_Login, FaceUI_SelectRole,}//UI Typepublic enum E_PanelType{ None, E_Mia

UIManager的字体颜色参数对照表

FileChooser.fileTypeHeaderTextTextArea.margincom.sun.java.swing.plaf.windows.WindowsSplitPaneUIcom.sun.java.swing.plaf.windows.WindowsToolBarUIcom.sun.java.swing.plaf.windows.WindowsRootPaneUIFileChooser.fileAttrHeaderTextcom.sun.java.swing.plaf.wind