UIMainComponentSystem.cs 12 KB

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