UIMainComponentSystem.cs 13 KB

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