2、WindowManager源码分析--最后一战
在最后一站中,几乎所有的UI界面都是这个WindowManager管理的,那么他是如何调度的呢?我们来看看一些项目中的界面。
上面有登陆界面,专门管理登陆。战斗界面,用户界面,专门管理用户属性等等。
既然UI有分类型,那么我们要设计不同类型的UI类,每个类负责自己的功能。
然后WindowManager管理这些不同类型的UI类。
虽然UI有着不同的类型,但是他们本质都是一样的,都是界面,所以我们设计一个界面父类,你看每个界面都根目录吧,都有自己的名字吧,都可以打开关闭吧,都要有事件监听吧。
所以最后一站抽象出了一个UI抽象基类,WindowBase.cs
接下来我们来分析一下类图和其中重点代码!
BaseWindow.cs
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 /// 1、这里运用到了里斯替换原则,父类出现得地方,子类都可以出现,但是反过来就不行 17 /// 2、例如BaseWindow login = new LoginWindow();这段代码是正确的,而 LoginWindow login = new BaseWindow();就无法创建 18 /// 3、这样的好处:子类可以有自己的个性,也可以继承父类的方法和属性,比如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是什么东西呢?
可以看到类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> /// 1、这里windowManger实现了Singleton接口,让自己成为一个单例 /// 2、这里的Singleton<T> where T : new() /// 3、单例这里就不讲了,直接给他人博客: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; } }