赞
踩
- public enum UIWindowType
- {
- Normal, // 可推出界面(UIMainMenu,UIRank等)
- Fixed, // 固定窗口(UITopBar等)
- PopUp, // 模式窗口
- }
-
- public enum UIWindowShowMode
- {
- DoNothing,
- HideOther, // 闭其他界面
- NeedBack, // 点击返回按钮关闭当前,不关闭其他界面(需要调整好层级关系)
- NoNeedBack, // 关闭TopBar,关闭其他界面,不加入backSequence队列
- }
-
- public enum UIWindowColliderMode
- {
- None, // 显示该界面不包含碰撞背景
- Normal, // 碰撞透明背景
- WithBg, // 碰撞非透明背景
- }

- 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; }
- }
-
- ///
- /// 能否添加到导航数据中
- ///
-
- 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;
- }
- }
-
- ///
- /// 界面是否要刷新BackSequence数据
- /// 1.显示NoNeedBack或者从NoNeedBack显示新界面 不更新BackSequenceData(隐藏自身即可)
- /// 2.HideOther
- /// 3.NeedBack
- ///
-
- public bool RefreshBackSeqData
- {
- get
- {
- if (this.windowData.showMode == UIWindowShowMode.HideOther
- || this.windowData.showMode == UIWindowShowMode.NeedBack)
- return true;
- return false;
- }
- }
-
- ///
- /// 在Awake中调用,初始化界面(给界面元素赋值操作)
- ///
-
- public virtual void InitWindowOnAwake()
- {
- }
-
- ///
- /// 获得该窗口管理类
- ///
- public UIManagerBase GetWindowManager
- {
- get
- {
- UIManagerBase baseManager = this.gameObject.GetComponent();
- return baseManager;
- }
- private set { }
- }
-
- ///
- /// 重置窗口
- ///
- public virtual void ResetWindow()
- {
- }
-
- ///
- /// 初始化窗口数据
- ///
- public virtual void InitWindowData()
- {
- if (windowData == null)
- windowData = new WindowData();
- }
-
- public virtual void ShowWindow()
- {
- }
-
- public virtual void HideWindow(Action action = null)
- {
- }
-
- public void HideWindowDirectly()
- {
- }
-
- public virtual void DestroyWindow()
- {
- }
-
- protected virtual void BeforeDestroyWindow()
- {
- }
-
- ///
- /// 界面在退出或者用户点击返回之前都可以注册执行逻辑
- ///
- protected void RegisterReturnLogic(BoolDelegate newLogic)
- {
- returnPreLogic = newLogic;
- }
-
- public bool ExecuteReturnLogic()
- {
- if (returnPreLogic == null)
- return false;
- else
- return returnPreLogic();
- }
- }

- ///
- /// 窗口动画
- ///
- interface IWindowAnimation
- {
- ///
- /// 显示动画
- ///
- void EnterAnimation(EventDelegate.Callback onComplete);
- ///
- /// 隐藏动画
- ///
- void QuitAnimation(EventDelegate.Callback onComplete);
-
- ///
- /// 重置动画
- ///
- void ResetAnimation();
- }

- private void AdjustBaseWindowDepth(UIBaseWindow baseWindow)
- {
- // 不同类型窗口添加不同的父节点下面
- // 根据当前父节点下面合法窗口的depth设置新打开窗口depth
- // 根据当前窗口背景和Collider模式,自动添加背景和碰撞
- 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;
- }
-
- ///
- /// 窗口背景碰撞体处理
- ///
- 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;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。