UI框架
来源:互联网 发布:winebottler mac 下载 编辑:程序博客网 时间:2024/05/16 19:31
功能:
显示,再显示,冻结,隐藏,拖拽,单击显示到最前面
模式:
正常窗口,模态窗口
using UnityEngine;public class BaseWindow :MonoBehaviour { public virtual void InitWindow() { }}
public interface IUIAnimation{ void EnterAnimation(); void PauseAnimation(); void ExitAnimation();}
using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public enum UIWindowType{ Normal, /// <summary> /// 模态窗口 /// </summary> PopUp}public enum UIWindowShowMode{ DoNothing, /// <summary> /// 关闭其他窗口,不破坏导航,当关闭时会显示上一个窗口 /// </summary> HideOther, /// <summary> /// 关闭其他窗口,并破坏导航 /// </summary> NoNeedBack}public class UIBaseWindow : BaseWindow{ #region field [HideInInspector] public GameObject m_Panel; public bool m_IsClickPanelClose; [Range(0, 1)] public float m_Alpha; public float m_CloseTimer; public IUIAnimation m_UIAnimation; public UIWindowType m_UIWindowType; public UIWindowShowMode m_UIWindowShowMode; public GameObject m_DragGameObject; public GameObject[] m_ShowButton; public GameObject[] m_CloseButton; public List<GameObject> m_FrontGameObject; public Action<UIBaseWindow> ShowEvent; public Action<UIBaseWindow> CloseEvent; private Vector3 m_MouseOffset; private Transform m_Transform; #region encapsulation private Transform MyTransform { get { if (m_Transform == null) m_Transform = transform; return m_Transform; } } #endregion #endregion #region public function public override void InitWindow() { } public void OnShow() { if (null != ShowEvent) ShowEvent(this); if (m_UIWindowType == UIWindowType.PopUp) m_Panel.transform.SetAsLastSibling(); else MyTransform.SetAsLastSibling(); gameObject.SetActive(true); if (null != m_UIAnimation) m_UIAnimation.EnterAnimation(); if (m_IsClickPanelClose) EventListener.Get(m_Panel).onClick += OnClose; } public void OnClose() { if (null != m_UIAnimation) m_UIAnimation.ExitAnimation(); if (CloseEvent != null) CloseEvent(this); if (m_IsClickPanelClose) EventListener.Get(m_Panel).onClick -= OnClose; StartCoroutine(CloseAnimation(m_CloseTimer)); } public void OnSelect() { MyTransform.SetAsLastSibling(); m_MouseOffset = MyTransform.position - Input.mousePosition; } public void OnDrag(Vector3 pos) { MyTransform.position = Input.mousePosition + m_MouseOffset; } public void OnFront() { MyTransform.SetAsLastSibling(); } #endregion #region private function private IEnumerator CloseAnimation(float timer) { yield return new WaitForSeconds(timer); gameObject.SetActive(false); if (m_UIWindowType == UIWindowType.PopUp) gameObject.transform.parent.gameObject.SetActive(false); } #endregion}
using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class UIBaseManager : MonoBehaviour{ #region field public Image m_Panel; public UIBaseWindow[] m_UIBaseWindow; private UIBaseWindow m_CurrentWindow; private Stack<UIBaseWindow> m_Navigation; #endregion #region public function #endregion #region private function private void Awake() { m_Panel.transform.SetAsLastSibling(); m_Panel.gameObject.SetActive(false); //加载数据类 BaseWindow[] baseWindow = transform.GetComponentsInChildren<BaseWindow>(); foreach (BaseWindow window in baseWindow) { window.InitWindow(); } SetWindowEvent(); } private void SetWindowEvent() { foreach (UIBaseWindow window in m_UIBaseWindow) { if (null == window) continue; window.InitWindow(); window.ShowEvent += PushWindow; window.CloseEvent += PopWindow; if (window.m_IsClickPanelClose) window.m_Panel = m_Panel.gameObject; if (window.m_UIWindowType == UIWindowType.PopUp) window.transform.parent = m_Panel.transform; if (null != window.m_ShowButton) { foreach (GameObject button in window.m_ShowButton) { if (null == button) continue; EventListener.Get(button).onClick += window.OnShow; } window.m_ShowButton = null; } if (null != window.m_CloseButton) { foreach (GameObject button in window.m_CloseButton) { if (null == button) continue; EventListener.Get(button).onClick += window.OnClose; } window.m_CloseButton = null; } if (null != window.m_FrontGameObject) { foreach (GameObject go in window.m_FrontGameObject) { if (null == go) continue; EventListener.Get(go).onLeftDown += window.OnFront; } window.m_FrontGameObject = null; } if (null != window.m_DragGameObject) { EventListener.Get(window.m_DragGameObject).onInitializePotentialDrag += window.OnSelect; EventListener.Get(window.m_DragGameObject).onDrag += window.OnDrag; window.m_DragGameObject = null; } window.gameObject.SetActive(false); } } private void PushWindow(UIBaseWindow window) { if (null == m_Navigation) m_Navigation = new Stack<UIBaseWindow>(); if (window.m_UIWindowType == UIWindowType.PopUp) { m_Panel.color = new Color(1, 1, 1, window.m_Alpha); m_Panel.gameObject.SetActive(true); } if (window.m_UIWindowShowMode == UIWindowShowMode.NoNeedBack) { int count = m_Navigation.Count; for (int i = 0; i < count; i++) { UIBaseWindow w = m_Navigation.Pop(); w.gameObject.SetActive(false); } } else if (window.m_UIWindowShowMode == UIWindowShowMode.HideOther) { foreach (UIBaseWindow w in m_UIBaseWindow) { if (w == window) continue; w.gameObject.SetActive(false); } m_CurrentWindow = window; } m_Navigation.Push(window); } private void PopWindow(UIBaseWindow window) { if (null == m_Navigation) return; if (m_Navigation.Count < 1) return; m_Navigation.Pop(); if (window.m_UIWindowShowMode == UIWindowShowMode.HideOther) { if (m_Navigation.Count < 1) return; UIBaseWindow w = m_Navigation.Peek(); w.gameObject.SetActive(true); } } #endregion}
阅读全文
0 0
- UI框架
- UI框架
- UI框架
- UI框架
- ui框架
- UI框架
- UI框架
- UI框架
- javascript 的 UI 框架
- javascript 的 UI 框架
- symbian ui框架设计
- JS通用UI框架
- Web UI框架
- UI框架和应用
- Jquery UI框架
- Liger UI框架
- Blackberry UI框架
- jquery easy ui 框架
- Flot Pie Examples
- qcustomplot.h中double minDistSqr = (std::numeric_limits<double>::max)()这一句报错
- bash基本功能之别名(alias)
- 如何利用缺陷的管理提高软件开发质量五——缺陷预测
- java 掩码2
- UI框架
- 架构以及我理解中架构的本质
- Win32 API之Setlocale函数配置地域化信息函数
- 部署zookeeper
- C++ map键值对容器demo
- C++语言基本教程 第16课: C++概谈和与C的差异
- LinkedList
- 解决python虚拟环境用pip装包报Permission denied
- MyEclipse 2016 反编译插件安装