二、WindowManager源碼分析--最後一戰

 

在最後一站中,幾乎全部的UI界面都是這個WindowManager管理的,那麼他是如何調度的呢?咱們來看看一些項目中的界面。html

 

上面有登錄界面,專門管理登錄。戰鬥界面,用戶界面,專門管理用戶屬性等等。服務器

既然UI有分類型,那麼咱們要設計不一樣類型的UI類,每一個類負責本身的功能。session

而後WindowManager管理這些不一樣類型的UI類。框架

雖然UI有着不一樣的類型,可是他們本質都是同樣的,都是界面,因此咱們設計一個界面父類,你看每一個界面都根目錄吧,都有本身的名字吧,均可以打開關閉吧,都要有事件監聽吧。ide

因此最後一站抽象出了一個UI抽象基類,WindowBase.cs 函數

接下來咱們來分析一下類圖和其中重點代碼!ui


 

 

 BaseWindow.csspa


 

 

 

  1 using UnityEngine;
  2 using System.Collections;
  3 using BlGame;
  4 using GameDefine;
  5 
  6 namespace BlGame.View
  7 {
  8     /// <summary>
  9     /// 抽象出來一個UI抽象基類,每個窗口都有本身的屬性方法字段等等
 10     /// </summary>
 11     public abstract class BaseWindow
 12     {
 13         protected Transform mRoot;          //UI根目錄
 14 
 15         protected EScenesType mScenesType; //場景類型
 16         protected string mResName;         //資源名
 17         protected bool mResident;          //是否常駐 
 18         protected bool mVisible = false;   //是否可見
 19         #region 這裏面的抽象方法都須要子類本身實現
 20 
 21         //類對象初始化
 22         public abstract void Init();
 23 
 24         //類對象釋放
 25         public abstract void Realse();
 26 
 27         //窗口控制初始化
 28         protected abstract void InitWidget();
 29 
 30         //窗口控件釋放
 31         protected abstract void RealseWidget();
 32 
 33         //遊戲事件註冊
 34         protected abstract void OnAddListener();
 35 
 36         //遊戲事件注消
 37         protected abstract void OnRemoveListener();
 38 
 39         //顯示初始化
 40         public abstract void OnEnable();
 41 
 42         //隱藏處理
 43         public abstract void OnDisable();
 44 
 45         //每幀更新
 46         public virtual void Update(float deltaTime) { }
 47 
 48         #endregion
 49 
 50         #region 基類本身的方法,子類也能夠用,由於子類是繼承父類的,父類的屬性方法都會被繼承
 51 
 52         //取得場景類型
 53         public EScenesType GetScenseType()
 54         {
 55             return mScenesType;
 56         }
 57 
 58         //是否已打開
 59         public bool IsVisible() { return mVisible; }
 60 
 61         //是否常駐內存
 62         public bool IsResident() { return mResident; }
 63 
 64         //顯示
 65         public void Show()
 66         {
 67             if (mRoot == null)
 68             {
 69                 if (Create())
 70                 {
 71                     InitWidget();
 72                 }
 73             }
 74 
 75             if (mRoot && mRoot.gameObject.activeSelf == false)
 76             {
 77                 mRoot.gameObject.SetActive(true);
 78 
 79                 mVisible = true;
 80 
 81                 OnEnable();
 82 
 83                 OnAddListener();
 84             }
 85         }
 86 
 87         //隱藏
 88         public void Hide()
 89         {
 90             if (mRoot && mRoot.gameObject.activeSelf == true)
 91             {
 92                 OnRemoveListener();
 93                 OnDisable();
 94 
 95                 if (mResident)
 96                 {
 97                     mRoot.gameObject.SetActive(false);//若是是常駐內存直接隱藏,不銷燬
 98                 }
 99                 else
100                 {
101                     RealseWidget();
102                     Destroy();
103                 }
104             }
105 
106             mVisible = false;
107         }
108 
109         //預加載
110         public void PreLoad()
111         {
112             if (mRoot == null)
113             {
114                 if (Create())
115                 {
116                     InitWidget();
117                 }
118             }
119         }
120 
121         //延時刪除
122         public void DelayDestory()
123         {
124             if (mRoot)
125             {
126                 RealseWidget();
127                 Destroy();
128             }
129         }
130 
131         //建立窗體
132         private bool Create()
133         {
134             if (mRoot)
135             {
136                 Debug.LogError("Window Create Error Exist!");
137                 return false;
138             }
139 
140             if (mResName == null || mResName == "")
141             {
142                 Debug.LogError("Window Create Error ResName is empty!");
143                 return false;
144             }
145 
146             if (GameMethod.GetUiCamera.transform == null)
147             {
148                 Debug.LogError("Window Create Error GetUiCamera is empty! WindowName = " + mResName);
149                 return false;
150             }
151 
152             GameObject obj = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, mResName);
153 
154             if (obj == null)
155             {
156                 Debug.LogError("Window Create Error LoadRes WindowName = " + mResName);
157                 return false;
158             }
159 
160             mRoot = obj.transform;
161 
162             mRoot.gameObject.SetActive(false);
163 
164             return true;
165         }
166 
167         //銷燬窗體
168         protected void Destroy()
169         {
170             if (mRoot)
171             {
172                 LoadUiResource.DestroyLoad(mRoot.gameObject);
173                 mRoot = null;
174             }
175         }
176 
177         //取得根節點
178         public Transform GetRoot()
179         {
180             return mRoot;
181         }
182 
183     }
184         #endregion
185        
186 }

LoginWindow .cs設計

 

  1 using UnityEngine;
  2 using System.Collections;
  3 using System.Collections.Generic;
  4 using JT.FWW.GameData;
  5 using GameDefine;
  6 using UICommon;
  7 using BlGame;
  8 using BlGame.GameData;
  9 using BlGame.Network;
 10 using System.Linq;
 11 using BlGame.Ctrl;
 12 
 13 namespace BlGame.View
 14 {
 15     /// <summary>
 16     /// 一、這裏運用到了里斯替換原則,父類出現得地方,子類均可以出現,可是反過來就不行
 17     /// 二、例如BaseWindow login = new LoginWindow();這段代碼是正確的,而 LoginWindow login = new BaseWindow();就沒法建立
 18     /// 三、這樣的好處:子類能夠有本身的個性,也能夠繼承父類的方法和屬性,好比loginWindow就能夠用來處理登陸功能,而BattleWindow就能夠專門用於處理戰鬥模塊
 19     /// </summary>
 20     public class LoginWindow : BaseWindow
 21     {
 22         /// <summary>
 23         /// 在子類的構造函數中,咱們先初始化父類的屬性
 24         /// </summary>
 25         public LoginWindow()
 26         {
 27             mScenesType = EScenesType.EST_Login;//場景類型
 28             mResName = GameConstDefine.LoadGameLoginUI;
 29             mResident = false;
 30         }
 31 
 32         ////////////////////////////繼承接口/////////////////////////
 33 
 34         //類對象初始化
 35         /// <summary>
 36         /// 在初始化方法裏面,它添加了委託監聽事件show()和hide()
 37         /// 這裏面的EventCenter是個什麼呢?最初呢!我認爲是否是一個框架裏面東西呢?
 38         /// 好比StrangeIOC框架裏面的全局dispatcher(事件中間者)
 39         /// 看了大神的解釋:這裏的eventcenter就是事件中介者,好比你想在進入登陸狀態的時候顯示登陸UI。
 40         /// 你要先註冊show()顯示UI事件到事件中介者那邊,而後當進入登陸狀態的時候,觸發這個委託事件,就執行show()
 41         /// 方法,UI就會被顯示。
 42         /// </summary>
 43         public override void Init()
 44         {
 45             EventCenter.AddListener(EGameEvent.eGameEvent_LoginEnter, Show);
 46             EventCenter.AddListener(EGameEvent.eGameEvent_LoginExit, Hide);
 47         }
 48 
 49         //類對象釋放
 50         public override void Realse()
 51         {
 52             EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginEnter, Show);
 53             EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginExit, Hide);
 54         }
 55 
 56         //窗口控件初始化
 57        /// <summary>
 58        /// 初始化各個組件,好比Button這些
 59        /// </summary>
 60         protected override void InitWidget()
 61         {
 62             mLoginParent = mRoot.FindChild("Server_Choose");
 63             mLoginInput = mRoot.FindChild("Server_Choose/Loginer");
 64             mLoginSubmit = mRoot.FindChild("Server_Choose/Button");
 65             mLoginAccountInput = mRoot.FindChild("Server_Choose/Loginer/AcountInput").GetComponent<UIInput>();
 66             mLoginPassInput = mRoot.FindChild("Server_Choose/Loginer/PassInput").GetComponent<UIInput>();
 67 
 68             mPlayParent = mRoot.Find("LoginBG");
 69             mPlaySubmitBtn = mRoot.Find("LoginBG/LoginBtn");
 70             mPlayServerBtn = mRoot.Find("LoginBG/CurrentSelection");
 71             mPlayNameLabel = mRoot.FindChild("LoginBG/CurrentSelection/Label3").GetComponent<UILabel>();
 72             mPlayStateLabel = mRoot.FindChild("LoginBG/CurrentSelection/Label4").GetComponent<UILabel>();
 73             mPlayAnimate = mPlaySubmitBtn.GetComponent<Animator>();
 74 
 75             mChangeAccountBtn = mRoot.FindChild("ChangeAccount");
 76             mChangeAccountName = mRoot.FindChild("ChangeAccount/Position/Label1").GetComponent<UILabel>();
 77 
 78             mServerParent = mRoot.FindChild("UIGameServer");
 79 
 80             mReLoginParent = mRoot.FindChild("LogInAgain");
 81             mReLoginSubmit = mRoot.FindChild("LogInAgain/Status1/Button");
 82 
 83             mVersionLable = mRoot.FindChild("Label").GetComponent<UILabel>();
 84             mWaitingParent = mRoot.FindChild("Connecting");
 85 
 86 
 87             UIEventListener.Get(mPlaySubmitBtn.gameObject).onClick += OnPlaySubmit;
 88             UIEventListener.Get(mPlayServerBtn.gameObject).onClick += OnPlayServer;
 89 
 90             UIEventListener.Get(mChangeAccountBtn.gameObject).onClick += OnChangeAccount;
 91 
 92             UIEventListener.Get(mReLoginSubmit.gameObject).onClick += OnReLoginSubmit;
 93 
 94             UIEventListener.Get(mLoginSubmit.gameObject).onClick += OnLoginSubmit;
 95 
 96             mServerList.Clear();
 97             for (int i = 0; i < 4; i++)
 98             {
 99                 UIToggle toggle = mLoginParent.FindChild("Server" + (i + 1).ToString()).GetComponent<UIToggle>();
100                 mServerList.Add(toggle);
101             }
102 
103             for (int i = 0; i < mServerList.Count; i++)
104             {
105                 EventDelegate.Add(mServerList.ElementAt(i).onChange, OnSelectIp);
106             }
107 
108 
109             DestroyOtherUI();
110         }
111 
112         //刪除Login外其餘控件,例如
113         public static void DestroyOtherUI()
114         {
115             Camera camera = GameMethod.GetUiCamera;
116             for (int i = 0; i < camera.transform.childCount; i++)
117             {
118                 if (camera.transform.GetChild(i) != null && camera.transform.GetChild(i).gameObject != null)
119                 {
120 
121                     GameObject obj = camera.transform.GetChild(i).gameObject;
122                     if (obj.name != "UIGameLogin(Clone)")
123                     {
124                         GameObject.DestroyImmediate(obj);
125                     }                    
126                 }
127             }
128         }
129 
130         //窗口控件釋放
131         protected override void RealseWidget()
132         {
133         }
134 
135         //遊戲事件註冊
136         protected override void OnAddListener()
137         {
138             EventCenter.AddListener<EErrorCode>(EGameEvent.eGameEvent_LoginError, LoginFail);//登錄反饋
139             EventCenter.AddListener(EGameEvent.eGameEvent_LoginSuccess, LoginSuceess);
140             EventCenter.AddListener<string,string>(EGameEvent.eGameEvent_SdkRegisterSuccess, SdkRegisterSuccess);//sdk register success
141             EventCenter.AddListener(EGameEvent.eGameEvent_SdkServerCheckSuccess, SdkServerCheckSuccess);//sdk register success
142             EventCenter.AddListener(EGameEvent.eGameEvent_SelectServer, SelectServer);//選擇了服務器
143             EventCenter.AddListener(EGameEvent.eGameEvent_LoginFail, ShowLoginFail);
144             EventCenter.AddListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);
145         }
146 
147         //遊戲事件注消
148         protected override void OnRemoveListener()
149         {
150             EventCenter.RemoveListener<EErrorCode>(EGameEvent.eGameEvent_LoginError, LoginFail);
151             EventCenter.RemoveListener<string,string>(EGameEvent.eGameEvent_SdkRegisterSuccess, SdkRegisterSuccess);
152             EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkServerCheckSuccess, SdkServerCheckSuccess);
153             EventCenter.RemoveListener(EGameEvent.eGameEvent_SelectServer, SelectServer);
154             EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginFail, ShowLoginFail);
155             EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginSuccess, LoginSuceess);
156             EventCenter.RemoveListener(EGameEvent.eGameEvent_SdkLogOff, SdkLogOff);
157         }
158 
159         //顯示
160         public override void OnEnable()
161         {
162             mVersionLable.text = SdkConector.GetBundleVersion();
163             mPlayAnimate.enabled = true;
164             ShowServer(LOGINUI.None);
165 
166 #if UNITY_STANDALONE_WIN || UNITY_EDITOR || SKIP_SDK
167             mLoginInput.gameObject.SetActive(true);
168 #endif
169         }
170 
171         //隱藏
172         public override void OnDisable()
173         {
174         }
175 
176         ////////////////////////////////UI事件響應////////////////////////////////////
177 
178         void OnPlaySubmit(GameObject go)
179         {
180             mWaitingParent.gameObject.SetActive(true);
181             UIEventListener.Get(mPlaySubmitBtn.gameObject).onClick -= OnPlaySubmit;
182 
183             LoginCtrl.Instance.GamePlay();
184         }
185 
186         void OnPlayServer(GameObject go)
187         {
188             ShowServer(LOGINUI.SelectServer);
189         }
190 
191         void OnChangeAccount(GameObject go)
192         {
193             LoginCtrl.Instance.SdkLogOff();
194         }
195 
196         void OnReLoginSubmit(GameObject go)
197         {
198             mReLoginParent.gameObject.SetActive(false);
199 
200             LoginCtrl.Instance.SdkLogOff();
201         }
202 
203         void OnLoginSubmit(GameObject go)
204         {
205 #if UNITY_STANDALONE_WIN
206             if (string.IsNullOrEmpty(mLoginAccountInput.value))
207                 return;
208             mLoginPassInput.value = "123";
209 #else
210            if (string.IsNullOrEmpty(mLoginAccountInput.value) || string.IsNullOrEmpty(mLoginPassInput.value))
211                 return;
212 #endif
213 
214 
215             mWaitingParent.gameObject.SetActive(true);
216 
217             LoginCtrl.Instance.Login(mLoginAccountInput.value, mLoginPassInput.value);
218         }
219 
220         void OnSelectIp()
221         {
222             if (UIToggle.current == null || !UIToggle.current.value)
223                 return;
224             for (int i = 0; i < mServerList.Count; i++)
225             {
226                 if (mServerList.ElementAt(i) == UIToggle.current)
227                 {
228                     LoginCtrl.Instance.SelectLoginServer(i);
229                     break;
230                 }
231             }
232         }
233 
234 
235         ////////////////////////////////遊戲事件響應////////////////////////////////////
236 
237         //登陸失敗
238         void LoginFail(EErrorCode errorCode)
239         {
240             mPlayAnimate.enabled = true;
241 
242             mPlaySubmitBtn.gameObject.SetActive(true);
243             GameObject.DestroyImmediate(mPlayEffect.gameObject);
244         }
245 
246         //登錄失敗反饋
247         void ShowLoginFail()
248         {
249             mReLoginParent.gameObject.SetActive(true);
250             mWaitingParent.gameObject.SetActive(false);
251             UIEventListener.Get(mPlaySubmitBtn.gameObject).onClick += OnPlaySubmit;
252         }
253 
254         //登錄成功
255         void LoginSuceess()
256         {
257             UIEventListener.Get(mPlaySubmitBtn.gameObject).onClick -= OnPlaySubmit;
258         }
259 
260         //選擇了服務器
261         void SelectServer()
262         {
263             ShowSelectServerInfo();
264             ShowServer(LOGINUI.Login);
265         }
266 
267         //顯示服務器信息或者顯示登陸信息
268         void ShowServer(LOGINUI state)
269         {
270             bool showLogin = false;
271             bool showServer = false;
272             bool showSelectServer = false;
273             switch (state)
274             {
275                 case LOGINUI.Login:
276                     ShowSelectServerInfo();
277                     showLogin = true;
278                     showServer = false;
279                     showSelectServer = false;
280                     break;
281                 case LOGINUI.SelectServer:
282                     showLogin = false;
283                     showServer = true;
284                     showSelectServer = false;
285                     break;
286                 case LOGINUI.None:
287                     showLogin = false;
288                     showServer = false;
289 #if UNITY_STANDALONE_WIN || UNITY_EDITOR || SKIP_SDK
290                     showSelectServer = true;
291 #endif
292                     break;
293             }
294             mPlayParent.gameObject.SetActive(showLogin);
295             mServerParent.gameObject.SetActive(showServer);
296             mLoginParent.gameObject.SetActive(showSelectServer);
297             if (showLogin)
298             {
299 #if UNITY_STANDALONE_WIN || UNITY_EDITOR|| SKIP_SDK
300                 mChangeAccountName.text = mLoginAccountInput.value;
301 #else
302                 mChangeAccountName.text = SdkConector.NickName();
303 #endif
304             }
305             mChangeAccountBtn.gameObject.SetActive(showLogin);
306         }
307 
308         //顯示選中的server信息 
309         void ShowSelectServerInfo()
310         {
311             SelectServerData.ServerInfo info = SelectServerData.Instance.curSelectServer;
312             mPlayNameLabel.text = info.name;
313             mPlayStateLabel.text = "(" + SelectServerData.Instance.StateString[(int)info.state] + ")";
314             SelectServerData.Instance.SetLabelColor(mPlayStateLabel, info.state);
315         }
316 
317         //SDK註冊成功
318         void SdkRegisterSuccess(string uid, string sessionId)
319         {
320             LoginCtrl.Instance.SdkRegisterSuccess(uid, sessionId);
321 
322             mWaitingParent.gameObject.SetActive(true);
323         }
324 
325         //SDK檢查成功
326         void SdkServerCheckSuccess()
327         {
328             ShowServer(LOGINUI.Login);
329             mWaitingParent.gameObject.SetActive(false);
330 
331             #if UNITY_STANDALONE_WIN || UNITY_EDITOR|| SKIP_SDK
332             #else
333                 SdkConector.ShowToolBar(0);
334             #endif
335         }
336 
337         //SDK退出
338         void SdkLogOff()
339         {
340             
341             ShowServer(LOGINUI.None);
342 
343             mLoginPassInput.value = "";
344             mLoginAccountInput.value = "";
345         }
346 
347         IEnumerator ShakeLabel()
348         {
349             mPlayEffect = GameMethod.CreateWindow(GameConstDefine.LoadGameLoginEffectPath, new Vector3(-5, -270, 0), mRoot.transform);
350             mPlaySubmitBtn.gameObject.SetActive(false);
351             yield return new WaitForSeconds(1.4f);
352         }
353         
354         enum LOGINUI
355         {
356             None = -1,
357             Login,
358             SelectServer,
359         }
360 
361         //開始
362         Transform mPlayParent;
363         Transform mPlaySubmitBtn;
364         Transform mPlayServerBtn;
365         UILabel mPlayNameLabel;
366         UILabel mPlayStateLabel;
367         Animator mPlayAnimate;
368         GameObject mPlayEffect;
369 
370         //登陸
371         Transform mLoginParent;
372         Transform mLoginInput;
373         Transform mLoginSubmit;
374         UIInput mLoginPassInput;
375         UIInput mLoginAccountInput;
376 
377         //改變賬號
378         Transform mChangeAccountBtn;
379         UILabel mChangeAccountName;
380 
381         //選服
382         Transform mServerParent;
383 
384         //從新登陸選擇
385         Transform mReLoginParent;
386         Transform mReLoginSubmit;
387 
388         //等待中
389         Transform mWaitingParent;
390 
391         //版本號   
392         UILabel mVersionLable;
393 
394         //服務器列表
395         private List<UIToggle> mServerList = new List<UIToggle>();
396 
397     }
398 
399 }

這裏面的EventCenter是什麼東西呢?3d

 

 能夠看到類A和類b沒有直接交互,而是經過了EventCenter分發事件。好比類b想要執行類A的show()方法,直接取EventCenter取這個事件委託,而後執行。

 

那麼引入這個中介者模式有什麼好處呢,有些人確定會問不是畫蛇添足嗎?原本A和B能夠直接交互,偏要引入這個中介者。主要是由於,當兩個類或者多個類相互交互,會出現這樣的狀況。

 

 者也就是違背了類低耦合的遠着,類與類之間的依賴過分,咱們要減輕這樣的練習,引入了中介者。

這樣就讓一個類只和中介者交互,從一對多變成了一對一,減小了依賴。

 

 


 

windowManger.cs

 



using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using BlGame;
using BlGame.GameState;

namespace BlGame.View
{
    /// <summary>
    /// 場景類型枚舉,用於場景判斷
    /// </summary>
    public enum EScenesType
    {
        EST_None,
        EST_Login,    
        EST_Play,
    }

   /// <summary>
   /// 窗口類型,
   /// </summary>
    public enum EWindowType
    {
        EWT_LoginWindow,
        EWT_UserWindow,
        EWT_LobbyWindow,
        EWT_BattleWindow,
        EWT_RoomWindow,
        EWT_HeroWindow,
        EWT_BattleInfoWindow,
        EWT_MarketWindow,
        EWT_MarketHeroListWindow,
        EWT_MarketHeroInfoWindow,
        EWT_MarketRuneListWindow,
        EWT_MarketRuneInfoWindow,
        EWT_SocialWindow,
        EWT_GamePlayWindow,
        EWT_InviteWindow,
        EWT_ChatTaskWindow,
        EWT_ScoreWindow,
        EWT_InviteAddRoomWindow,
        EWT_RoomInviteWindow,
        EWT_TeamMatchWindow,
        EWT_TeamMatchInvitationWindow,
        EWT_TeamMatchSearchingWindow,
        EWT_MailWindow,
        EWT_HomePageWindow,
        EWT_PresonInfoWindow,
        EWT_ServerMatchInvitationWindow,
        EWT_SoleSoldierWindow,
        EWT_MessageWindow,
        EWT_MiniMapWindow,
        EWT_VIPPrerogativeWindow,
        EWT_RuneEquipWindow,
        EWT_DaliyBonusWindow,
        EWT_EquipmentWindow,
        EWT_SystemNoticeWindow,
        EWT_TimeDownWindow,
        EWT_RuneCombineWindow,
        EWT_HeroDatumWindow,
        EWT_RuneRefreshWindow,
        EWT_GamePlayGuideWindow,
        EMT_PurchaseSuccessWindow,
        EMT_GameSettingWindow,
        EMT_AdvancedGuideWindow,
        EMT_ExtraBonusWindow,
        EMT_EnemyWindow,
        EMT_HeroTimeLimitWindow,
        EMT_SkillWindow,
        EMT_SkillDescribleWindow,
        EMT_RuneBuyWindow,
        EMT_DeathWindow,
    }

    /// <summary>
    /// 一、這裏windowManger實現了Singleton接口,讓本身成爲一個單例
    /// 二、這裏的Singleton<T> where T : new() 
    /// 三、單例這裏就不講了,直接給他人博客:http://www.cnblogs.com/neverdie/p/Learn_Unity3D_Singleton.html
    /// 
    /// 總結就是如今WindowManager裏面new你的UI子類,而後在Init()添加show,hide事件監聽,而後改變遊戲狀態,在GameStateManger裏面的Enter某個遊戲狀態
    /// 而後出發show事件,顯示UI就是這樣
    /// </summary>
    public class WindowManager : Singleton<WindowManager>
    {
        public WindowManager()
        {
            mWidowDic = new Dictionary<EWindowType, BaseWindow>();

            mWidowDic[EWindowType.EWT_LoginWindow] = new LoginWindow();
            mWidowDic[EWindowType.EWT_UserWindow] = new UserInfoWindow();
            mWidowDic[EWindowType.EWT_LobbyWindow] = new LobbyWindow();
            mWidowDic[EWindowType.EWT_BattleWindow] = new BattleWindow();
            mWidowDic[EWindowType.EWT_RoomWindow] = new RoomWindow();
            mWidowDic[EWindowType.EWT_HeroWindow] = new HeroWindow();
            mWidowDic[EWindowType.EWT_BattleInfoWindow] = new BattleInfoWindow();
            mWidowDic[EWindowType.EWT_MarketWindow] = new MarketWindow();
            mWidowDic[EWindowType.EWT_MarketHeroListWindow] = new MarketHeroListWindow();
            mWidowDic[EWindowType.EWT_MarketHeroInfoWindow] = new MarketHeroInfoWindow();    
            mWidowDic[EWindowType.EWT_SocialWindow] = new SocialWindow();
            mWidowDic[EWindowType.EWT_GamePlayWindow] = new GamePlayWindow();
            mWidowDic[EWindowType.EWT_InviteWindow] = new InviteWindow();
            mWidowDic[EWindowType.EWT_ChatTaskWindow] = new ChatTaskWindow();
            mWidowDic[EWindowType.EWT_ScoreWindow] = new ScoreWindow();
            mWidowDic[EWindowType.EWT_InviteAddRoomWindow] = new InviteAddRoomWindow();
            mWidowDic[EWindowType.EWT_RoomInviteWindow] = new RoomInviteWindow();
            mWidowDic[EWindowType.EWT_TeamMatchWindow] = new TeamMatchWindow();
            mWidowDic[EWindowType.EWT_TeamMatchInvitationWindow] = new TeamMatchInvitationWindow();
            mWidowDic[EWindowType.EWT_TeamMatchSearchingWindow] = new TeamMatchSearchingWindow();
            mWidowDic[EWindowType.EWT_MailWindow] = new MailWindow();
            mWidowDic[EWindowType.EWT_HomePageWindow] = new HomePageWindow(); 
            mWidowDic[EWindowType.EWT_PresonInfoWindow] = new PresonInfoWindow();
            mWidowDic[EWindowType.EWT_ServerMatchInvitationWindow] = new ServerMatchInvitationWindow();
            mWidowDic[EWindowType.EWT_SoleSoldierWindow] = new SoleSoldierWindow();
            mWidowDic[EWindowType.EWT_MessageWindow] = new MessageWindow();
            mWidowDic[EWindowType.EWT_MarketRuneListWindow] = new MarketRuneListWindow();
            mWidowDic[EWindowType.EWT_MiniMapWindow] = new MiniMapWindow();
            mWidowDic[EWindowType.EWT_MarketRuneInfoWindow] = new MarketRuneInfoWindow();
            mWidowDic[EWindowType.EWT_VIPPrerogativeWindow] = new VIPPrerogativeWindow();
            mWidowDic[EWindowType.EWT_RuneEquipWindow] = new RuneEquipWindow();
            mWidowDic[EWindowType.EWT_DaliyBonusWindow] = new DaliyBonusWindow();
            mWidowDic[EWindowType.EWT_EquipmentWindow] = new EquipmentWindow();
            mWidowDic[EWindowType.EWT_SystemNoticeWindow] = new SystemNoticeWindow();
            mWidowDic[EWindowType.EWT_TimeDownWindow] = new TimeDownWindow();
            mWidowDic[EWindowType.EWT_RuneCombineWindow] = new RuneCombineWindow();
            mWidowDic[EWindowType.EWT_HeroDatumWindow] = new HeroDatumWindow();
            mWidowDic[EWindowType.EWT_RuneRefreshWindow] = new RuneRefreshWindow();
            mWidowDic[EWindowType.EWT_GamePlayGuideWindow] = new GamePlayGuideWindow();
            mWidowDic[EWindowType.EMT_PurchaseSuccessWindow] = new PurchaseSuccessWindow();
            mWidowDic[EWindowType.EMT_GameSettingWindow] = new GameSettingWindow();
            mWidowDic[EWindowType.EMT_AdvancedGuideWindow] = new AdvancedGuideWindow();
            mWidowDic[EWindowType.EMT_ExtraBonusWindow] = new ExtraBonusWindow();
            mWidowDic[EWindowType.EMT_EnemyWindow] = new EnemyWindow();
            mWidowDic[EWindowType.EMT_HeroTimeLimitWindow] = new HeroTimeLimitWindow();
            mWidowDic[EWindowType.EMT_SkillWindow] = new SkillWindow();
            mWidowDic[EWindowType.EMT_SkillDescribleWindow] = new SkillDescribleWindow();
            mWidowDic[EWindowType.EMT_RuneBuyWindow] = new RuneBuyWindow();
            mWidowDic[EWindowType.EMT_DeathWindow] = new DeathWindow();
        }

        public BaseWindow GetWindow(EWindowType type)
        {
            if (mWidowDic.ContainsKey(type))
                return mWidowDic[type];

            return null;
        }

        public void Update(float deltaTime)
        {
            foreach (BaseWindow pWindow in mWidowDic.Values)
            {
                if (pWindow.IsVisible())
                {
                    pWindow.Update(deltaTime);
                }
            }
        }

        public void ChangeScenseToPlay(EScenesType front)
        {
            foreach (BaseWindow pWindow in mWidowDic.Values)
            {
                if (pWindow.GetScenseType() == EScenesType.EST_Play)
                {
                    pWindow.Init();

                    if(pWindow.IsResident())
                    {
                        pWindow.PreLoad();
                    }
                }
                else if ((pWindow.GetScenseType() == EScenesType.EST_Login) && (front == EScenesType.EST_Login))
                {
                    pWindow.Hide();
                    pWindow.Realse();

                    if (pWindow.IsResident())
                    {
                        pWindow.DelayDestory();
                    }
                }
            }
        }

        public void ChangeScenseToLogin(EScenesType front)
        {
            foreach (BaseWindow pWindow in mWidowDic.Values)
            {
                if (front == EScenesType.EST_None && pWindow.GetScenseType() == EScenesType.EST_None)
                {
                    pWindow.Init();

                    if (pWindow.IsResident())
                    {
                        pWindow.PreLoad();
                    }
                }

                if (pWindow.GetScenseType() == EScenesType.EST_Login)
                {
                    pWindow.Init();

                    if (pWindow.IsResident())
                    {
                        pWindow.PreLoad();
                    }
                }
                else if ((pWindow.GetScenseType() == EScenesType.EST_Play) && (front == EScenesType.EST_Play))
                {
                    pWindow.Hide();
                    pWindow.Realse();

                    if (pWindow.IsResident())
                    {
                        pWindow.DelayDestory();
                    }
                }
            }
        }

        /// <summary>
        /// 隱藏該類型的全部Window
        /// </summary>
        /// <param name="front"></param>
        public void HideAllWindow(EScenesType front)
        {
            foreach (var item in mWidowDic)
            {
                if (front == item.Value.GetScenseType())
                {
                    Debug.Log(item.Key);
                    item.Value.Hide();
                    //item.Value.Realse();
                }
            }
        }

        public void ShowWindowOfType(EWindowType type)
        { 
            BaseWindow window;
            if(!mWidowDic.TryGetValue(type , out window))
            {
                return;
            }
            window.Show();
        }

        private Dictionary<EWindowType, BaseWindow> mWidowDic;
    }


}
相關文章
相關標籤/搜索