窗口UI管理器-Dictionary
来源:互联网 发布:数据库与网站 编辑:程序博客网 时间:2024/05/21 10:24
CJUIWindowMgr类
<span style="font-size:18px;">using UnityEngine;using System.Collections;using System.Collections.Generic;/// <summary>/// 窗口UI管理器/// </summary>public class CJUIWindowMgr{ private static CJUIWindowMgr instance; public static CJUIWindowMgr GetInstance() { if (instance == null) instance = new CJUIWindowMgr(); return instance; } //窗口缓存器 public Dictionary<string, GameObject> windowCache = new Dictionary<string, GameObject>(); /// <summary> /// 打开窗口 /// </summary> /// <param name="windowPath">窗口预设/。。。路径</param> /// <param name="parent">窗口挂点(父节点)</param> /// <returns></returns> public GameObject OpenWindow(string windowPath,Transform parent) { GameObject windowUI = null; if (windowCache.ContainsKey(windowPath)) { windowUI = windowCache[windowPath]; if (windowUI == null) { Debug.LogError("The Window is Deleted"); return null; } windowUI.SetActive(true); } else { //加载窗口资源 GameObject windowPrefab = Resources.Load(windowPath) as GameObject; //实例化窗口资源 windowUI = GameObject.Instantiate(windowPrefab); //Transform组件重置 windowUI.transform.parent = parent; windowUI.transform.localPosition = Vector3.zero; windowUI.transform.localScale = Vector3.one; windowUI.transform.localRotation = Quaternion.Euler(Vector3.zero); //缓存窗口 windowCache.Add(windowPath,windowUI); } return windowUI; } /// <summary> /// 关闭窗口 /// </summary> /// <param name="windowPath">窗口资源的路径</param> /// <param name="remove">是否Destroy</param> public void CloseWindow(string windowPath,bool remove = false) { if (windowCache.ContainsKey(windowPath)) { GameObject windowUI = windowCache[windowPath]; if (windowUI == null) { Debug.LogError("The Window is Deleted"); return; } else { if (remove) { GameObject.Destroy(windowUI); windowCache.Remove(windowPath); } else { windowUI.SetActive(false); } } } }}</span>
CJUIWindowCtrBase类
<span style="font-size:24px;">using UnityEngine;using System.Collections;public class CJUIWindowCtrBase : MonoBehaviour { void Awake() { OnAwake(); }void Start () { OnStart();}// Update is called once per framevoid Update () { OnUpdate();} void OnDestroy() { BeforeOnDestroy(); } protected virtual void OnAwake() { } protected virtual void OnStart() { } protected virtual void OnUpdate() { } protected virtual void BeforeOnDestroy() { CJUIWindowMgr.GetInstance().windowCache.Clear(); }}</span>
CJUIWindow_FunctionCtr类
using UnityEngine;using System.Collections;/// <summary>/// 功能菜单窗口控制器/// </summary>public class CJUIWindow_FunctionCtr : CJUIWindowCtrBase { bool toggle = false;// Use this for initialization protected override void OnStart() { base.OnStart(); Init(); } void Init() { UIButton[] btnArray = GetComponentsInChildren<UIButton>(); for (int index = 0; index < btnArray.Length; index++) { UIEventListener.Get(btnArray[index].gameObject).onClick = delegate(GameObject go) { switch (go.name) { case "Shop": break; case "Bag": if (!toggle) { CJUIWindowMgr.GetInstance().OpenWindow("UI/UIWindow/StartMenuScene/UIWindow_Bag", GameObject.Find("CenterContainer").transform); toggle = true; } else { CJUIWindowMgr.GetInstance().CloseWindow("UI/UIWindow/StartMenuScene/UIWindow_Bag", false); toggle = false; } break; default: Debug.LogError("The Button is Not Register Call Back"); break; } }; } } protected override void BeforeOnDestroy() { base.BeforeOnDestroy(); }}
0 0
- 窗口UI管理器-Dictionary
- 窗口管理器
- 窗口管理器
- 音频管理器 ,Dictionary字典的用法
- X窗口管理器大全
- 初识FVWM-窗口管理器
- 安装FLUXBOX窗口管理器
- 窗口管理器的要求
- Ubuntu设置窗口管理器
- directfb 窗口管理器调试
- tmux 多窗口管理器
- VC窗口布局管理器
- directfb与窗口管理器
- 什么是窗口管理器
- twm 窗口管理器
- GNOME窗口管理器
- DWM桌面窗口管理器
- Linux窗口管理器
- coreseek 的安装使用
- 误删电脑硬盘
- linux常用基本命令
- hdu1087 Super Jumping! Jumping! Jumping!(最长上升子序列和)
- CC1100小程序
- 窗口UI管理器-Dictionary
- c++11改进我们的程序之垃圾回收
- skyline自动化建模;DWG翻模
- c++学习笔记(1)继承与派生
- 写点什么
- Deep Learning及NLP(自然语言处理)杂谈--第三部分
- AVLTree----平衡二叉搜索树
- 多线程通信之模拟QQ聊天功能
- 如何计算一个有符号数的补码表示?