标签:处理 tiny deb value owa 破坏 font 类型 游戏
public enum UIWindowType { Normal, // 可推出界面(UIMainMenu,UIRank等) Fixed, // 固定窗体(UITopBar等) PopUp, // 模式窗体 } public enum UIWindowShowMode { DoNothing, HideOther, // 闭其它界面 NeedBack, // 点击返回button关闭当前,不关闭其它界面(须要调整好层级关系) NoNeedBack, // 关闭TopBar,关闭其它界面,不增加backSequence队列 } public enum UIWindowColliderMode { None, // 显示该界面不包括碰撞背景 Normal, // 碰撞透明背景 WithBg, // 碰撞非透明背景 }
using UnityEngine; using System.Collections; using System; namespace CoolGame { /// <summary> /// 窗体基类 /// </summary> public class UIBaseWindow : MonoBehaviour { protected UIPanel originPanel; // 假设须要能够加入一个BoxCollider屏蔽事件 private bool isLock = false; protected bool isShown = false; // 当前界面ID protected WindowID windowID = WindowID.WindowID_Invaild; // 指向上一级界面ID(BackSequence无内容,返回上一级) protected WindowID preWindowID = WindowID.WindowID_Invaild; public WindowData windowData = new WindowData(); // Return处理逻辑 private event BoolDelegate returnPreLogic = null; protected Transform mTrs; protected virtual void Awake() { this.gameObject.SetActive(true); mTrs = this.gameObject.transform; InitWindowOnAwake(); } private int minDepth = 1; public int MinDepth { get { return minDepth; } set { minDepth = value; } } /// <summary> /// 是否能加入到导航数据中 /// </summary> public bool CanAddedToBackSeq { get { if (this.windowData.windowType == UIWindowType.PopUp) return false; if (this.windowData.windowType == UIWindowType.Fixed) return false; if (this.windowData.showMode == UIWindowShowMode.NoNeedBack) return false; return true; } } /// <summary> /// 界面是否要刷新BackSequence数据 /// 1.显示NoNeedBack或者从NoNeedBack显示新界面 不更新BackSequenceData(隐藏自身就可以) /// 2.HideOther /// 3.NeedBack /// </summary> public bool RefreshBackSeqData { get { if (this.windowData.showMode == UIWindowShowMode.HideOther || this.windowData.showMode == UIWindowShowMode.NeedBack) return true; return false; } } /// <summary> /// 在Awake中调用。初始化界面(给界面元素赋值操作) /// </summary> public virtual void InitWindowOnAwake() { } /// <summary> /// 获得该窗体管理类 /// </summary> public UIManagerBase GetWindowManager { get { UIManagerBase baseManager = this.gameObject.GetComponent<UIManagerBase>(); return baseManager; } private set { } } /// <summary> /// 重置窗体 /// </summary> public virtual void ResetWindow() { } /// <summary> /// 初始化窗体数据 /// </summary> public virtual void InitWindowData() { if (windowData == null) windowData = new WindowData(); } public virtual void ShowWindow() { isShown = true; NGUITools.SetActive(this.gameObject, true); } public virtual void HideWindow(Action action = null) { IsLock = true; isShown = false; NGUITools.SetActive(this.gameObject, false); if (action != null) action(); } public void HideWindowDirectly() { IsLock = true; isShown = false; NGUITools.SetActive(this.gameObject, false); } public virtual void DestroyWindow() { BeforeDestroyWindow(); GameObject.Destroy(this.gameObject); } protected virtual void BeforeDestroyWindow() { } /// <summary> /// 界面在退出或者用户点击返回之前都能够注冊运行逻辑 /// </summary> protected void RegisterReturnLogic(BoolDelegate newLogic) { returnPreLogic = newLogic; } public bool ExecuteReturnLogic() { if (returnPreLogic == null) return false; else return returnPreLogic(); } } }动画接口设计
/// <summary> /// 窗体动画 /// </summary> interface IWindowAnimation { /// <summary> /// 显示动画 /// </summary> void EnterAnimation(EventDelegate.Callback onComplete); /// <summary> /// 隐藏动画 /// </summary> void QuitAnimation(EventDelegate.Callback onComplete); /// <summary> /// 重置动画 /// </summary> void ResetAnimation(); }
public void EnterAnimation(EventDelegate.Callback onComplete) { if (twAlpha != null) { twAlpha.PlayForward(); EventDelegate.Set(twAlpha.onFinished, onComplete); } } public void QuitAnimation(EventDelegate.Callback onComplete) { if (twAlpha != null) { twAlpha.PlayReverse(); EventDelegate.Set(twAlpha.onFinished, onComplete); } } public override void ResetWindow() { base.ResetWindow(); ResetAnimation(); }
private void AdjustBaseWindowDepth(UIBaseWindow baseWindow) { UIWindowType windowType = baseWindow.windowData.windowType; int needDepth = 1; if (windowType == UIWindowType.Normal) { needDepth = Mathf.Clamp(GameUtility.GetMaxTargetDepth(UINormalWindowRoot.gameObject, false) + 1, normalWindowDepth, int.MaxValue); Debug.Log("[UIWindowType.Normal] maxDepth is " + needDepth + baseWindow.GetID); } else if (windowType == UIWindowType.PopUp) { needDepth = Mathf.Clamp(GameUtility.GetMaxTargetDepth(UIPopUpWindowRoot.gameObject) + 1, popUpWindowDepth, int.MaxValue); Debug.Log("[UIWindowType.PopUp] maxDepth is " + needDepth); } else if (windowType == UIWindowType.Fixed) { needDepth = Mathf.Clamp(GameUtility.GetMaxTargetDepth(UIFixedWidowRoot.gameObject) + 1, fixedWindowDepth, int.MaxValue); Debug.Log("[UIWindowType.Fixed] max depth is " + needDepth); } if(baseWindow.MinDepth != needDepth) GameUtility.SetTargetMinPanel(baseWindow.gameObject, needDepth); baseWindow.MinDepth = needDepth; } /// <summary> /// 窗体背景碰撞体处理 /// </summary> private void AddColliderBgForWindow(UIBaseWindow baseWindow) { UIWindowColliderMode colliderMode = baseWindow.windowData.colliderMode; if (colliderMode == UIWindowColliderMode.None) return; if (colliderMode == UIWindowColliderMode.Normal) GameUtility.AddColliderBgToTarget(baseWindow.gameObject, "Mask02", maskAtlas, true); if (colliderMode == UIWindowColliderMode.WithBg) GameUtility.AddColliderBgToTarget(baseWindow.gameObject, "Mask02", maskAtlas, false); }
public void SetCenterBtnCallBack(string msg, UIEventListener.VoidDelegate callBack) { lbCenter.text = msg; NGUITools.SetActive(btnCenter, true); UIEventListener.Get(btnCenter).onClick = callBack; } public void SetLeftBtnCallBack(string msg, UIEventListener.VoidDelegate callBack) { lbLeft.text = msg; NGUITools.SetActive(btnLeft, true); UIEventListener.Get(btnLeft).onClick = callBack; } public void SetRightBtnCallBack(string msg, UIEventListener.VoidDelegate callBack) { lbRight.text = msg; NGUITools.SetActive(btnRight, true); UIEventListener.Get(btnRight).onClick = callBack; }
整个框架的核心部分介绍完成,有须要查看源代码的请移步GitHub。兴许会继续完好和整理,希望可以给耐心看到结尾的朋友一点启示或者带来一点帮助。存在错误和改进的地方也希望留言交流共同进步学习~
有些时候,我们总是知道这么个理明确该如何实现。可是关键的就是要动手实现出来,实现的过程会发现自己的想法在慢慢优化。不断的需求和bug的产生让框架慢慢成熟,能够投入项目使用提升一些开发效率和降低工作量。
标签:处理 tiny deb value owa 破坏 font 类型 游戏
原文地址:http://www.cnblogs.com/tlnshuju/p/7394733.html