123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace ET.Client
- {
- [FriendOf(typeof(UIMainComponent))]
- public static class UIMainComponentSystem
- {
- [ObjectSystem]
- public class UIMainComponentAwakeSystem : AwakeSystem<UIMainComponent>
- {
- protected override async void Awake(UIMainComponent self, params object[] param)
- {
- ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
- self.createRoomBtn = rc.Get<GameObject>("createRoomBtn");
- self.createRoomTxt = rc.Get<GameObject>("createRoomTxt");
- self.joinRoomBtn = rc.Get<GameObject>("joinRoomBtn");
- self.clubRoomBtn = rc.Get<GameObject>("clubBtn");
- self.playerIcon = rc.Get<GameObject>("playerIcon");
- self.playerId = rc.Get<GameObject>("playerId");
- self.playerName = rc.Get<GameObject>("playerName");
- self.playerLevel = rc.Get<GameObject>("playerLevel");
- self.vipVaule = rc.Get<GameObject>("vipVaule");
- self.expVaule = rc.Get<GameObject>("expVaule");
- self.createRoomBtn.OnClick(() => { self.OnCreateRoom(); });
- //self.createRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCreateRoom(); });
- self.joinRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnJoinRoom(); });
- self.clubRoomBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnClub(); });
- self.playerIcon.GetComponent<Button>().onClick.AddListener(() => { self.OnPlayer(); });
- var roleInfo = self.ClientScene().GetComponent<RoleInfoComponment>().GetRoleInfo();
- self.playerName.GetComponent<Text>().text = roleInfo.name;
- self.playerId.GetComponent<Text>().text = roleInfo.roleId.ToString();
- self.vipVaule.GetComponent<Text>().text = roleInfo.vip.ToString();
- self.playerLevel.GetComponent<Text>().text = "LV." + roleInfo.level.ToString();
- self.expVaule.GetComponent<Image>().fillAmount = roleInfo.exp / 100f;
- ///down btn////
- self.shopBtn = rc.Get<GameObject>("shopBtn");
- self.settingBtn = rc.Get<GameObject>("settingBtn");
- self.ruleBtn = rc.Get<GameObject>("ruleBtn");
- self.statsBtn = rc.Get<GameObject>("statsBtn");
- self.shareBtn = rc.Get<GameObject>("shareBtn");
- self.avtiveBtn = rc.Get<GameObject>("avtiveBtn");
- self.shopBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShop(); });
- self.settingBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnSetting(); });
- self.ruleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRule(); });
- self.statsBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnStats(); });
- self.avtiveBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnAvtive(); });
- self.shareBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnShare(); });
- //leftBtn
- self.iphoneBtn = rc.Get<GameObject>("iphoneBtn");
- self.invitationCodeBtn = rc.Get<GameObject>("invitationCodeBtn");
- self.realNameBtn = rc.Get<GameObject>("realNameBtn");
- self.iphoneBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnIphone(); });
- self.invitationCodeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInvitationCode(); });
- self.realNameBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnRealName(); });
- //up
- self.hourseCardAddBtn = rc.Get<GameObject>("hourseCradAddBtn");
- self.curServiceBtn = rc.Get<GameObject>("cusServiceBtn");
- self.messageBtn = rc.Get<GameObject>("messageBtn");
- self.hourseCardTxt = rc.Get<GameObject>("hourseCradTxt");
- self.hourseCardAddBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnHourseCardAdd(); });
- self.curServiceBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCurService(); });
- self.messageBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMessage(); });
-
- //提示面板
- self.titlePanelObj = rc.Get<GameObject>("titlePanle");
- //每次进来都弹一次
- self.titlePanelObj.SetActive(true);
- self.closeTitleBtn = rc.Get<GameObject>("closeTitleBtn");
- self.closeTitleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseTitle(); });
- self.createRoomType = 0;
- self.roomId = "";
- if (param != null && param.Length > 0)
- {
- Dictionary<string, object> dic = param[0] as Dictionary<string, object>;
- self.createRoomType = (int)dic["result"];
- self.roomId = dic["roomId"] as string;
- }
- //self.createRoomTxt.GetComponent<Text>().text = self.createRoomType == 0 ? "创建房间" : "返回房间";
- await SoundManager.Instance.PlaySound("common_playBg",true);
- }
- }
- #region 中间按钮
- public static async void OnCreateRoom(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- if (self.createRoomType == 0)
- {
- self.CreateRoom().Coroutine();
- }
- else
- {
- self.ReturnRoom().Coroutine();
- }
- }
- public static async void OnJoinRoom(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIJoinRoom, UILayer.High);
- }
- public static async void OnClub(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- var scene = self.ClientScene();
- await UIHelper.Remove(scene, UIType.UIMain);
- await UIHelper.Create(scene, UIType.UIClubCreate, UILayer.Mid);
- }
- #endregion
- #region 头像点击
- public static void OnPlayer(this UIMainComponent self)
- {
- }
- #endregion
- #region 下面按钮
- public static async void OnShop(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIShop, UILayer.Mid);
- }
- public static async void OnSetting(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UISetting, UILayer.Mid);
- }
- public static async void OnRule(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIRule, UILayer.Mid);
- }
- public static async void OnStats(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIStats, UILayer.Mid);
- }
- public static async void OnShare(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIShare, UILayer.Mid);
- }
- public static async void OnAvtive(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIAvtive, UILayer.Mid);
- }
- #endregion
- #region 左边按钮
- public static async void OnIphone(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIIphone, UILayer.Mid);
- }
- public static async void OnInvitationCode(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIInvate, UILayer.Mid);
- }
- public static async void OnRealName(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIRealNameAuthen, UILayer.Mid);
- }
- #endregion
- #region 上面按钮
- public static async void OnHourseCardAdd(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- }
- public static async void OnCurService(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UICustomerService, UILayer.Mid);
- }
- public static async void OnCloseTitle(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- self.titlePanelObj.SetActive(false);
- }
- public static async void OnMessage(this UIMainComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIMessage, UILayer.Mid);
- }
- #endregion
- static async ETTask CreateRoom(this UIMainComponent self)
- {
- try
- {
- await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_CreatRoom,null, async (messageObj,errorCode) =>
- {
- if (errorCode != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"创建失败,errCode={errorCode}");
- return;
- }
- RoomInfo roomInfo = messageObj as RoomInfo;
- var startFightRoomComponment = GameUtil.Instance.GetSceneComponent().GetComponent<StartFightRoomComponment>();
- if (startFightRoomComponment == null)
- {
- startFightRoomComponment = GameUtil.Instance.GetSceneComponent().AddComponent<StartFightRoomComponment>();
- }
- startFightRoomComponment.ClearStartFightRoomInfo();
- startFightRoomComponment.SetStartFightRoomInfoFromCreate(roomInfo);
- //目前就用一个场景吧,后面看再单独分开。
- //关闭主界面
- await UIHelper.Remove(GameUtil.Instance.GetSceneComponent(), UIType.UIMain);
- //打开开始打牌界面
- await UIHelper.Create(GameUtil.Instance.GetSceneComponent(), UIType.UIStartFightRoom, UILayer.Mid);
- });
- }
- catch (Exception e)
- {
- Log.Error($"创建房间出错...{e.Message}");
- }
- }
- static async ETTask ReturnRoom(this UIMainComponent self)
- {
- try
- {
- if (string.IsNullOrEmpty(self.roomId))
- {
- return;
- }
- Dictionary<string, object> dic = new Dictionary<string, object>()
- {
- { "roomId",self.roomId}
- };
- await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_JoinRoom, dic,async (messageObj, errorCode) =>
- {
- if (errorCode != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"返回房间失败,errCode={errorCode}");
- return;
- }
- //关闭主界面
- await UIHelper.Remove(GameUtil.Instance.GetSceneComponent(), UIType.UIMain);
- //打开开始打牌界面
- await UIHelper.Create(GameUtil.Instance.GetSceneComponent(), UIType.UIStartFightRoom, UILayer.Mid);
- });
- }
- catch (Exception e)
- {
- Log.Error($"返回房间出错...{e.Message}");
- }
- }
- }
- }
|