UIMainComponentSystem.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace ET.Client
  6. {
  7. [FriendOf(typeof(UIMainComponent))]
  8. public static class UIMainComponentSystem
  9. {
  10. [ObjectSystem]
  11. public class UIMainComponentAwakeSystem : AwakeSystem<UIMainComponent>
  12. {
  13. protected override async void Awake(UIMainComponent self, params object[] param)
  14. {
  15. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  16. self.createRoomBtn = rc.Get<GameObject>("createRoomBtn");
  17. self.createRoomTxt = rc.Get<GameObject>("createRoomTxt");
  18. self.joinRoomBtn = rc.Get<GameObject>("joinRoomBtn");
  19. self.clubRoomBtn = rc.Get<GameObject>("clubBtn");
  20. self.playerIcon = rc.Get<GameObject>("playerIcon");
  21. self.playerId = rc.Get<GameObject>("playerId");
  22. self.playerName = rc.Get<GameObject>("playerName");
  23. self.playerLevel = rc.Get<GameObject>("playerLevel");
  24. self.vipVaule = rc.Get<GameObject>("vipVaule");
  25. self.expVaule = rc.Get<GameObject>("expVaule");
  26. self.createRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateRoom(); });
  27. self.joinRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnJoinRoom(); });
  28. self.clubRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnClub(); });
  29. self.playerIcon.GetComponent<Button>().onClick.AddListener(() => { self.OnPlayer(); });
  30. var roleInfo = self.ClientScene().GetComponent<RoleInfoComponment>().GetRoleInfo();
  31. self.playerName.GetComponent<Text>().text = roleInfo.name;
  32. self.playerId.GetComponent<Text>().text = roleInfo.roleId.ToString();
  33. self.vipVaule.GetComponent<Text>().text = roleInfo.vip.ToString();
  34. self.playerLevel.GetComponent<Text>().text = "LV." + roleInfo.level.ToString();
  35. self.expVaule.GetComponent<Image>().fillAmount = roleInfo.exp / 100f;
  36. ///down btn////
  37. self.shopBtn = rc.Get<GameObject>("shopBtn");
  38. self.settingBtn = rc.Get<GameObject>("settingBtn");
  39. self.ruleBtn = rc.Get<GameObject>("ruleBtn");
  40. self.statsBtn = rc.Get<GameObject>("statsBtn");
  41. self.shareBtn = rc.Get<GameObject>("shareBtn");
  42. self.avtiveBtn = rc.Get<GameObject>("avtiveBtn");
  43. self.shopBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShop(); });
  44. self.settingBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnSetting(); });
  45. self.ruleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRule(); });
  46. self.statsBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnStats(); });
  47. self.avtiveBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnAvtive(); });
  48. self.shareBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShare(); });
  49. //leftBtn
  50. self.iphoneBtn = rc.Get<GameObject>("iphoneBtn");
  51. self.invitationCodeBtn = rc.Get<GameObject>("invitationCodeBtn");
  52. self.realNameBtn = rc.Get<GameObject>("realNameBtn");
  53. self.iphoneBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnIphone(); });
  54. self.invitationCodeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInvitationCode(); });
  55. self.realNameBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRealName(); });
  56. //up
  57. self.hourseCardAddBtn = rc.Get<GameObject>("hourseCradAddBtn");
  58. self.curServiceBtn = rc.Get<GameObject>("cusServiceBtn");
  59. self.messageBtn = rc.Get<GameObject>("messageBtn");
  60. self.hourseCardTxt = rc.Get<GameObject>("hourseCradTxt");
  61. self.hourseCardAddBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnHourseCardAdd(); });
  62. self.curServiceBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCurService(); });
  63. self.messageBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMessage(); });
  64. //提示面板
  65. self.titlePanelObj = rc.Get<GameObject>("titlePanle");
  66. //每次进来都弹一次
  67. self.titlePanelObj.SetActive(true);
  68. self.closeTitleBtn = rc.Get<GameObject>("closeTitleBtn");
  69. self.closeTitleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseTitle(); });
  70. self.createRoomType = 0;
  71. self.roomId = "";
  72. if (param != null && param.Length > 0)
  73. {
  74. Dictionary<string, object> dic = param[0] as Dictionary<string, object>;
  75. self.createRoomType = (int)dic["result"];
  76. self.roomId = dic["roomId"] as string;
  77. }
  78. self.createRoomTxt.GetComponent<Text>().text = self.createRoomType == 0 ? "创建房间" : "返回房间";
  79. await SoundManager.Instance.PlaySound("common_playBg",true);
  80. }
  81. }
  82. #region 中间按钮
  83. public static async void OnCreateRoom(this UIMainComponent self)
  84. {
  85. await SoundManager.Instance.PlaySound("clickbtnsound");
  86. if (self.createRoomType == 0)
  87. {
  88. self.CreateRoom().Coroutine();
  89. }
  90. else
  91. {
  92. self.ReturnRoom().Coroutine();
  93. }
  94. }
  95. public static async void OnJoinRoom(this UIMainComponent self)
  96. {
  97. await SoundManager.Instance.PlaySound("clickbtnsound");
  98. await UIHelper.Create(self.ClientScene(), UIType.UIJoinRoom, UILayer.High);
  99. }
  100. public static async void OnClub(this UIMainComponent self)
  101. {
  102. await SoundManager.Instance.PlaySound("clickbtnsound");
  103. var scene = self.ClientScene();
  104. await UIHelper.Remove(scene, UIType.UIMain);
  105. await UIHelper.Create(scene, UIType.UIClubCreate, UILayer.Mid);
  106. }
  107. #endregion
  108. #region 头像点击
  109. public static void OnPlayer(this UIMainComponent self)
  110. {
  111. }
  112. #endregion
  113. #region 下面按钮
  114. public static async void OnShop(this UIMainComponent self)
  115. {
  116. await SoundManager.Instance.PlaySound("clickbtnsound");
  117. await UIHelper.Create(self.ClientScene(), UIType.UIShop, UILayer.Mid);
  118. }
  119. public static async void OnSetting(this UIMainComponent self)
  120. {
  121. await SoundManager.Instance.PlaySound("clickbtnsound");
  122. await UIHelper.Create(self.ClientScene(), UIType.UISetting, UILayer.Mid);
  123. }
  124. public static async void OnRule(this UIMainComponent self)
  125. {
  126. await SoundManager.Instance.PlaySound("clickbtnsound");
  127. await UIHelper.Create(self.ClientScene(), UIType.UIRule, UILayer.Mid);
  128. }
  129. public static async void OnStats(this UIMainComponent self)
  130. {
  131. await SoundManager.Instance.PlaySound("clickbtnsound");
  132. await UIHelper.Create(self.ClientScene(), UIType.UIStats, UILayer.Mid);
  133. }
  134. public static async void OnShare(this UIMainComponent self)
  135. {
  136. await SoundManager.Instance.PlaySound("clickbtnsound");
  137. await UIHelper.Create(self.ClientScene(), UIType.UIShare, UILayer.Mid);
  138. }
  139. public static async void OnAvtive(this UIMainComponent self)
  140. {
  141. await SoundManager.Instance.PlaySound("clickbtnsound");
  142. await UIHelper.Create(self.ClientScene(), UIType.UIAvtive, UILayer.Mid);
  143. }
  144. #endregion
  145. #region 左边按钮
  146. public static async void OnIphone(this UIMainComponent self)
  147. {
  148. await SoundManager.Instance.PlaySound("clickbtnsound");
  149. await UIHelper.Create(self.ClientScene(), UIType.UIIphone, UILayer.Mid);
  150. }
  151. public static async void OnInvitationCode(this UIMainComponent self)
  152. {
  153. await SoundManager.Instance.PlaySound("clickbtnsound");
  154. await UIHelper.Create(self.ClientScene(), UIType.UIInvate, UILayer.Mid);
  155. }
  156. public static async void OnRealName(this UIMainComponent self)
  157. {
  158. await SoundManager.Instance.PlaySound("clickbtnsound");
  159. await UIHelper.Create(self.ClientScene(), UIType.UIRealNameAuthen, UILayer.Mid);
  160. }
  161. #endregion
  162. #region 上面按钮
  163. public static async void OnHourseCardAdd(this UIMainComponent self)
  164. {
  165. await SoundManager.Instance.PlaySound("clickbtnsound");
  166. }
  167. public static async void OnCurService(this UIMainComponent self)
  168. {
  169. await SoundManager.Instance.PlaySound("clickbtnsound");
  170. await UIHelper.Create(self.ClientScene(), UIType.UICustomerService, UILayer.Mid);
  171. }
  172. public static async void OnCloseTitle(this UIMainComponent self)
  173. {
  174. await SoundManager.Instance.PlaySound("clickbtnsound");
  175. self.titlePanelObj.SetActive(false);
  176. }
  177. public static async void OnMessage(this UIMainComponent self)
  178. {
  179. await SoundManager.Instance.PlaySound("clickbtnsound");
  180. await UIHelper.Create(self.ClientScene(), UIType.UIMessage, UILayer.Mid);
  181. }
  182. #endregion
  183. static async ETTask CreateRoom(this UIMainComponent self)
  184. {
  185. try
  186. {
  187. var scene = self.ClientScene();
  188. var session = scene.GetComponent<SessionComponent>().Session;
  189. if (session != null)
  190. {
  191. G2C_CreatRoom g2CreatRoom = (G2C_CreatRoom)await session.Call(
  192. new C2G_CreatRoom() { });
  193. if (g2CreatRoom.Error != ErrorCode.ERR_Success)
  194. {
  195. Log.Error($"CreateRoom错误...errCode={g2CreatRoom.Error}");
  196. return;
  197. }
  198. var startFightRoomComponment = scene.GetComponent<StartFightRoomComponment>();
  199. if (startFightRoomComponment == null)
  200. {
  201. startFightRoomComponment = scene.AddComponent<StartFightRoomComponment>();
  202. }
  203. startFightRoomComponment.ClearStartFightRoomInfo();
  204. startFightRoomComponment.SetStartFightRoomInfoFromCreate(g2CreatRoom.Info);
  205. //目前就用一个场景吧,后面看再单独分开。
  206. //关闭主界面
  207. await UIHelper.Remove(scene, UIType.UIMain);
  208. //打开开始打牌界面
  209. await UIHelper.Create(scene, UIType.UIStartFightRoom, UILayer.Mid);
  210. }
  211. }
  212. catch (Exception e)
  213. {
  214. Log.Error($"创建房间出错...{e.Message}");
  215. }
  216. }
  217. static async ETTask ReturnRoom(this UIMainComponent self)
  218. {
  219. try
  220. {
  221. if (string.IsNullOrEmpty(self.roomId))
  222. {
  223. return;
  224. }
  225. var scene = self.ClientScene();
  226. var session = scene.GetComponent<SessionComponent>().Session;
  227. if (session != null)
  228. {
  229. G2C_JoinRoom g2JoinRoom = (G2C_JoinRoom)await session.Call(
  230. new C2G_JoinRoom() { RoomId = int.Parse(self.roomId) });
  231. if (g2JoinRoom.Error != ErrorCode.ERR_Success)
  232. {
  233. Log.Error($"g2JoinRoom错误...errCode={g2JoinRoom.Error}");
  234. return;
  235. }
  236. //关闭主界面
  237. await UIHelper.Remove(scene, UIType.UIMain);
  238. //打开开始打牌界面
  239. await UIHelper.Create(scene, UIType.UIStartFightRoom, UILayer.Mid);
  240. }
  241. }
  242. catch (Exception e)
  243. {
  244. Log.Error($"返回房间出错...{e.Message}");
  245. }
  246. }
  247. public static async ETTask EnterMap(this UIMainComponent self)
  248. {
  249. await EnterMapHelper.EnterMapAsync(self.ClientScene());
  250. await UIHelper.Remove(self.ClientScene(), UIType.UIMain);
  251. }
  252. }
  253. }