編寫一個簡單通用UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn)._第1頁
編寫一個簡單通用UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn)._第2頁
編寫一個簡單通用UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn)._第3頁
編寫一個簡單通用UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn)._第4頁
編寫一個簡單通用UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn)._第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、目標(biāo):編寫一個簡單通用 UI框架用于管理頁面和完成導(dǎo)航跳轉(zhuǎn) 最終的實(shí)現(xiàn)效果請拉到最下方查看框架具體實(shí)現(xiàn)的功能和需求加載,顯示,隱藏,關(guān)閉頁面,根據(jù)標(biāo)示獲得相應(yīng)界面實(shí)例提供界面顯示隱藏動畫接口單獨(dú)界面層級,Collider,背景管理根據(jù)存儲的導(dǎo)航信息完成界面導(dǎo)航界面通用對話框管理(多類型Message Box)便于進(jìn)行需求和功能擴(kuò)展(比如,在跳出頁面之前添加邏輯處理等)編寫UI框架意義打開,關(guān)閉,層級,頁面跳轉(zhuǎn)等管理問題集中化,將外部切換等邏輯交給UlManager處理功能邏輯分散化,每個頁面維護(hù)自身邏輯,依托于框架便于多人協(xié)同開發(fā),不用關(guān)心跳轉(zhuǎn)和顯示關(guān)閉細(xì)節(jié)通用性框架能夠做到簡單的代碼復(fù)用和”

2、項(xiàng)目經(jīng)驗(yàn)沉淀步入正題,如何實(shí)現(xiàn)1. 窗口類設(shè)計:基本窗口對象,維護(hù)自身邏輯維護(hù)2. 窗口管理類:控制被管理窗口的打開和關(guān)閉等邏輯 (具體設(shè)計請看下文)3. 動畫接口:提供打開和關(guān)閉動畫接口,提供動畫完成回調(diào)函數(shù)等4. 層級,Collider背景管理窗口基類設(shè)計public enu mUIWi ndowTypeNormal,/可推出界面(UlMainMenu,UIRank等Fixed,/固定窗口 (UITopBar等)PopUp,/模式窗口public enumUIWindowShowModeDoNothi ng,HideOther,/ 閉其他界面NeedBack,/點(diǎn)擊返回按鈕關(guān)閉當(dāng)前,不關(guān)閉

3、其他界面(需要調(diào)整好層級關(guān)系)NoNeedBack, / 關(guān)閉TopBar,關(guān)閉其他界面,不加入 backSeque nee 隊(duì)歹 Upublic enumUIWindowColliderModeNone,/ 顯示該界面不包含碰撞背景Normal,/ 碰撞透明背景WithBg,/ 碰撞非透明背景using UnityEngine;using System.Collections;using System;namespace CoolGame/ / 窗口基類/ public class UIBaseWindow : MonoBehaviourprotected UIPanel originPan

4、el;/ 如果需要可以添加一個 BoxCollider 屏蔽事件private bool isLock = false;protected bool isShown = false;/ 當(dāng)前界面 IDprotected WindowID windowID = WindowID.WindowID_Invaild;/ 指向上一級界面 ID(BackSequence 無內(nèi)容,返回上一級 ) protected WindowID preWindowID = WindowID.WindowID_Invaild; public WindowData windowData = new WindowData(

5、);/ Return 處理邏輯private event BoolDelegate returnPreLogic = null;protected Transform mTrs;protected virtual void Awake() this.gameObject.SetActive(true); mTrs = this.gameObject.transform; InitWindowOnAwake();privateintminDepth = 1;publicintMinDepthget returnminDepth; set minDepth= value; / / 能否添加到導(dǎo)航數(shù)

6、據(jù)中/ public bool CanAddedToBackSeqgetif (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 數(shù)據(jù)/ 1. 顯示NoNeedBack或者從

7、 NoNeedBack顯示新界面 不更新BackSequenceData(隱藏 自身即可 )/ 2.HideOther/ 3.NeedBack/ public bool RefreshBackSeqDataget if (this.windowData.showMode = UIWindowShowMode.HideOther | this.windowData.showMode =UIWindowShowMode.NeedBack)return true; return false;/ /在Awake中調(diào)用,初始化界面(給界面元素賦值操作)/ public virtual void Init

8、WindowOnAwake()/ / 獲得該窗口管理類/ public UIManagerBase GetWindowManagerget UIManagerBase baseManager = this.gameObject.GetComponent();return baseManager; private set / / 重置窗口/ public virtual void ResetWindow()/ / 初始化窗口數(shù)據(jù)/ public virtual void InitWindowData()if (windowData = null) windowData = new WindowD

9、ata();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;

10、 isShown = false; NGUITools.SetActive(this.gameObject, false);public virtual void DestroyWindow() BeforeDestroyWindow(); GameObject.Destroy(this.gameObject);protected virtual void BeforeDestroyWindow()/ /界面在退岀或者用戶點(diǎn)擊返回之前都可以注冊執(zhí)行邏輯/ protected void RegisterReturnLogic(BoolDelegate newLogic)returnPreLogi

11、c = newLogic;public bool ExecuteReturnLogic()if (returnPreLogic = null)return false;elsereturn returnPreLogic。;動畫接口設(shè)計界面可以繼承該接口進(jìn)行實(shí)現(xiàn)打開和關(guān)閉動畫/ / 窗口動畫/ in terfaceIWin dowA nimatio n/ /顯示動畫/ void En terA ni matio n( Eve ntDelegate.Callback on Complete);/ /隱藏動畫/ void QuitA ni matio n(Eve ntDelegate.Callbac

12、k on Complete);/ / 重置動畫/ void ResetAnimation(); public void En terA ni mati on( Eve ntDelegate.Callback on Complete)if (twAlpha != null)twAlpha.PlayForward();Eve ntDelegate.Set(twAlpha. onFini shed, on Complete);public void QuitA nimatio n(Eve ntDelegate.Callback on Complete)if (twAlpha != null)twAl

13、pha.PlayReverse();Eve ntDelegate.Set(twAlpha. onFini shed, on Complete);public override void ResetWindow()base.ResetWi ndow();ResetA nimatio n();窗口管理和導(dǎo)航設(shè)計實(shí)現(xiàn)導(dǎo)航功能實(shí)現(xiàn)通過一個顯示窗口堆棧實(shí)現(xiàn),每次打開和關(guān)閉窗口通過判斷窗口屬性和類型更新處理BackSequence數(shù)據(jù)打開界面:將當(dāng)前界面狀態(tài)壓入堆棧中更新 BackSequence數(shù)據(jù)返回操作(主動關(guān)閉當(dāng)前界面或者點(diǎn)擊返回按鈕):從堆棧中Pop出一個界面狀態(tài),將相應(yīng)的界面重新打開* 怎么銜

14、接:比如從一個界面沒有回到上一個狀態(tài)而是直接的跳轉(zhuǎn)到其他的界面,這個時候需要將BackSequence清空因?yàn)楫?dāng)前的導(dǎo)航鏈已經(jīng)被破壞,當(dāng) BackSequence為空需要根據(jù)當(dāng)前窗口指定的 PreWindowId告知系統(tǒng)當(dāng)從該界面返回,需要到達(dá)的指定頁面,這樣就能解決怎么銜接的問題,如果沒斷,繼 續(xù)執(zhí)行導(dǎo)航,否則清空數(shù)據(jù),根據(jù) PreWindowId進(jìn)行導(dǎo)航導(dǎo)航系統(tǒng)中關(guān)鍵性設(shè)計:游戲中可以存在多個的Manager進(jìn)行管理(一般在很少需求下才會使用),每個管理對象需要維護(hù)自己的導(dǎo)航信息 BackSequence,每次退出一個界面需要檢測當(dāng)前退出的界面是否存在相應(yīng)的Manager管理,如果存在則需

15、要先執(zhí)行Manager退出操作(退出過程分步進(jìn)行)保證界面一層接著一層正確退出窗口層級,Collider,統(tǒng)一背景添加如何實(shí)現(xiàn)?有很多方式進(jìn)行層級管理,該框架選擇的方法如下設(shè)置三個常用層級Root,根據(jù)窗口類型在加載到游戲中時添加到對應(yīng)的層級Root下面即可,每次添加重新計算設(shè)置層級(通過UIPanel的depth實(shí)現(xiàn))保證每次打開一個新窗口層級顯示正確,每次窗口內(nèi)通過depth的大小區(qū)分層級關(guān)系* 根據(jù)窗口 Collider和背景類型,在窗口的最小 Panel上面添加Collider或者帶有碰撞體的BackGround即可UI RootCameraUIManager Test UIFixed

16、WidowRoot UITopBar(Cl one) UIPopUpWindowRoot UIMessageBox(Clone) UINormalWi ndowRoot UIMai nMenu (Clone) UIRank(Clone)A UILevelWindow(Clone) UILevelDetailWindow(Clone) UIMatching(Clone) UIMatchResult(Clone) UlSkill(Clone)CubeGameMonoHelper/保存UI常用節(jié)點(diǎn)public Transform UIRoot;/ NormalWindow節(jié)點(diǎn)System.NonSe

17、rializedpublic Transform UINormalWindowRoot; / PopUpWindow節(jié)點(diǎn)System.NonSerializedpublic Transform UIPopUpWindowRoot; / Fixed Window節(jié)點(diǎn)System.NonSerialized public Transform UIFixedWidowRoot;/界面固定window起始depth / PopUp類型window起始depth / Normal類型window起始depth/層級分離depthprivate int fixedWindowDepth = 100; pr

18、ivate int popUpWindowDepth = 150; private int nonnalWindowDepth = 2;private void AdjustBaseWindowDepth(UIBaseWindow baseWindow) UIWindowType windowType = baseWindow.windowData.windowType;int needDepth = 1;if (windowType = UIWindowType.Normal)needDepth = Mathf.Clamp(GameUtility.GetMaxTargetDepth(UINo

19、rmalWindowRoot.gameObject, false) + 1, normalWindowDepth, int.MaxValue);Debug.Log(UIWindowType.NormalmaxDepth is + needDepth + baseWindow.GetID);else if (windowType = UIWindowType.PopUp)needDepth =Mathf.Clamp(GameUtility.GetMaxTargetDepth(UIPopUpWindowRoot.gameObject) + 1,popUpWindowDepth,int.MaxVal

20、ue);Debug .L og(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 !=

21、 needDepth)GameUtility.SetTargetMinPanel(baseWindow.gameObject, needDepth); baseWindow.MinDepth = needDepth;/ / 窗口背景碰撞體處理/ private void AddColliderBgForWindow(UIBaseWindow baseWindow) UIWindowColliderMode colliderMode = baseWindow.windowData.colliderMode;if (colliderMode = UIWindowColliderMode.None)

22、return;if (colliderMode = UIWindowColliderMode.Normal)GameUtility.AddColliderBgToTarget(baseWindow.gameObject,Mask02, maskAtlas,true);if (colliderMode = UIWindowColliderMode.WithBg) GameUtility.AddColliderBgToTarget(baseWindow.gameObject,Mask02, maskAtlas,false);多形態(tài)MessageBox 實(shí)現(xiàn)這個應(yīng)該是項(xiàng)目中一定會用到的功能,說下該框

23、架簡單的實(shí)現(xiàn)三個按鈕三種回調(diào)邏輯:左中右三個按鈕,提供設(shè)置內(nèi)容,設(shè)置回調(diào)函數(shù)的接口即可提供接口設(shè)置核心Content不同作用下不同的按鈕不會隱藏和顯示public void SetCenterBtnCallBack(stringmsg,UlEve ntListe ner.VoidDelegate callBack)lbCe nter.text = msg;NGUITools.SetActive(bt nCen ter, true);UIEve ntListe ner.Get(bt nCen ter).o nClick = callBack;public void SetLeftBtnCallBack(stringmsg,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論