12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.PlayerLoop;
- using UnityEngine.UI;
- using static System.Net.Mime.MediaTypeNames;
- using static UnityEditor.Progress;
- namespace ET.Client
- {
- #region 定时器 刷新
- [Invoke(TimerInvokeType.fightTimeShow)]
- public class UIStartFightRoomComponentChecker : ATimer<UIStartFightRoomComponent>
- {
- protected override void Run(UIStartFightRoomComponent self)
- {
- try
- {
- self.Check();
- }
- catch (Exception e)
- {
- Log.Error($"idle check error: {self.Id}\n{e}");
- }
- }
- }
- [Invoke(TimerInvokeType.startFightTimeCount)]
- public class UIStartFightTimeCountChecker : ATimer<UIStartFightRoomComponent>
- {
- protected override void Run(UIStartFightRoomComponent self)
- {
- try
- {
- self.UpdateTimeCount();
- }
- catch (Exception e)
- {
- Log.Error($"idle check error: {self.Id}\n{e}");
- }
- }
- }
- #endregion
- [FriendOf(typeof(UIStartFightRoomComponent))]
- public static class UIStartFightRoomComponentSystem
- {
- public static void Check(this UIStartFightRoomComponent self)
- {
- self.timeTxt.text = string.Format("{0}:{1}", DateTime.Now.Hour, DateTime.Now.Minute);
- }
- public static void UpdateTimeCount(this UIStartFightRoomComponent self)
- {
- if (self.startTimeCount > 0)
- {
- self.timeCountObj.SetActive(true);
- self.timeCountTxt.text = self.startTimeCount.ToString();
- }
- else
- {
- self.timeCountObj.SetActive(false);
- if (self.startTimer > 0)
- TimerComponent.Instance?.Remove(ref self.startTimer);
- }
- self.startTimeCount = self.startTimeCount - 1;
- }
- [ObjectSystem]
- public class UIStartFightRoomComponentAwakeSystem : AwakeSystem<UIStartFightRoomComponent>
- {
- protected override void Awake(UIStartFightRoomComponent self, params object[] param)
- {
- ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
- //头像部分
- self.houseIcon = rc.Get<GameObject>("houseIcon");
- self.houseIdTxt = rc.Get<GameObject>("houseIdTxt");
- self.gameNumTxt = rc.Get<GameObject>("gameNumTxt");
- self.curResidueTxt = rc.Get<GameObject>("curResidueTxt");
- //右上系统信息部分
- self.wifiImage = rc.Get<GameObject>("wifiImage");
- self.powerImage = rc.Get<GameObject>("powerImage");
- var timeTxt = rc.Get<GameObject>("timeTxt");
- self.timeTxt = timeTxt.GetComponent<UnityEngine.UI.Text>();
- self.menuBtn = rc.Get<GameObject>("menuBtn");
- self.menuBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuBtn(); });
- self.faceBtn = rc.Get<GameObject>("faceBtn");
- self.faceBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceBtn(); });
- self.videoBtn = rc.Get<GameObject>("videoBtn");
- self.videoBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnVideoBtn(); });
- //菜单
- self.menuPanel = rc.Get<GameObject>("menuPanel");
- self.menuPanel.SetActive(false);
- self.maskBtn = rc.Get<GameObject>("maskBtn");
- self.maskBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelClose(); });
- self.menuBackBtn = rc.Get<GameObject>("menuBackBtn");
- self.menuBackBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelBack(); });
- self.menuQuitBtn = rc.Get<GameObject>("menuQuitBtn");
- self.menuQuitBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelQuit(); });
- self.menuSettingBtn = rc.Get<GameObject>("menuSettingBtn");
- self.menuSettingBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnMenuPanelSetting(); });
- //表情面板
- self.facePanel = rc.Get<GameObject>("facePanel");
- self.facePanel.SetActive(false);
- self.fastToggleBtn = rc.Get<GameObject>("fastToggleBtn");
- self.fastToggleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceFastToggleBtn(0); });
- self.faceToggleBtn = rc.Get<GameObject>("faceToggleBtn");
- self.faceToggleBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnFaceFastToggleBtn(1); });
- self.faceAndVideoObj = rc.Get<GameObject>("faceAndVideoObj");
- self.faceAndVideoObj.SetActive(false);
- self.facePanelCloseBtn = rc.Get<GameObject>("facePanelCloseBtn");
- self.facePanelCloseBtn.GetComponent<Button>().onClick.AddListener(() => { self.facePanel.SetActive(false); });
- //表情列表以及快捷语列表
- self.listFastGridBg = rc.Get<GameObject>("listFastGridBg");
- self.listFastGridBg.SetActive(false);
- self.listFastContent = rc.Get<GameObject>("listFastContent");
- self.gridFastItem = rc.Get<GameObject>("gridFastItem");
- self.listFaceGridBg = rc.Get<GameObject>("listFaceGridBg");
- self.listFaceGridBg.SetActive(false);
- self.listFaceContent = rc.Get<GameObject>("listFaceContent");
- self.gridFaceItem = rc.Get<GameObject>("gridFaceItem");
- self.timeCountObj = rc.Get<GameObject>("timeCountObj");
- self.timeCountTxt = rc.Get<GameObject>("timeCountTxt").GetComponent<UnityEngine.UI.Text>();
- //玩
- self.readyBtn = rc.Get<GameObject>("readyBtn");
- self.readyBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnReadyAndInviteBtn(0); });
- self.inviteBtn = rc.Get<GameObject>("inviteBtn");
- self.inviteBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnReadyAndInviteBtn(1); });
- self.fightCardItem = rc.Get<GameObject>("fightCardItem");
- self.fightCardItem.SetActive(false);
- GameUtil.Instance.SetCardCloneItem(self.fightCardItem,0);
- self.fightCardItem1 = rc.Get<GameObject>("fightCardItem1");
- self.fightCardItem1.SetActive(false);
- GameUtil.Instance.SetCardCloneItem(self.fightCardItem1, 1);
- for (int i = 1;i <= 4;i++)
- {
- UIStartFightRoomPlayerCom uIStartFightRoomPlayerCom = new UIStartFightRoomPlayerCom();
- var playerObj = rc.Get<GameObject>("player" + i);
- var playerIconObj = rc.Get<GameObject>("playerIcon" + i);
- var readyImage = rc.Get<GameObject>("readyImage" + i);
- var playerIconImage = playerIconObj.GetComponent<UnityEngine.UI.Image>();
- uIStartFightRoomPlayerCom.playerObj = playerObj;
- uIStartFightRoomPlayerCom.readyImage = readyImage;
- uIStartFightRoomPlayerCom.playerIcon = playerIconImage;
- var fightCardContentNode = rc.Get<GameObject>("fightCardContent" + i);
- uIStartFightRoomPlayerCom.fightCardNode = fightCardContentNode;
- var disCardContentNode = rc.Get<GameObject>("disCardContent" + i);
- uIStartFightRoomPlayerCom.disCardsNode = disCardContentNode;
- self.uIStartFightRoomPlayerComs.Add(uIStartFightRoomPlayerCom);
- playerObj.SetActive(false);
- var playChatObj = rc.Get<GameObject>("playChatObj" + i);
- self.playChatObjList.Add(playChatObj);
- }
- //操作
- self.operatorObj = rc.Get<GameObject>("operatorObj");
- self.operatorObj.SetActive(false);
- int operatorIndex = 1;
- for (int i = 1;i <= 5;i++)
- {
- var operatorObjBtn = rc.Get<GameObject>("operatorBtn" + i);
- var btn = operatorObjBtn.GetComponent<Button>();
- operatorIndex = i;
- btn.onClick.AddListener(()=>
- {
- self.OnOperatorBtn(operatorIndex);
- });
- self.operatorObj_btn.Add(operatorObjBtn);
- }
- self.Init();
- }
- }
- private static async void Init(this UIStartFightRoomComponent self)
- {
- self.RepeatedTimer = TimerComponent.Instance.NewRepeatedTimer(ConstValue.fightTimeRefreshTime / 2 + 100, TimerInvokeType.fightTimeShow, self);
- var startFightRoomInfo = self.ClientScene().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- CommonBridge.Instance.dispathPush += DispathPush;
- self.readyBtn.SetActive(true);
- self.inviteBtn.SetActive(true);
- self.houseIdTxt.GetComponent<UnityEngine.UI.Text>().text = startFightRoomInfo.roomInfo.RoomId.ToString();
- self.gameNumTxt.GetComponent<UnityEngine.UI.Text>().text = startFightRoomInfo.roomInfo.OwnerId.ToString();
- self.curResidueTxt.GetComponent<UnityEngine.UI.Text>().text = "0";
- await SoundManager.Instance.PlaySound("common_playing", true);
- }
- private static void DispathPush(Scene scene, object type)
- {
- switch (type)
- {
- case EventType.JoinRoomPush:
- {
- var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
- var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- //处理其他玩家信息
- for (int i = 1; i < startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count; i++)
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
- }
- if (startFightRoomInfo.roomInfo.OtherInfo != null && startFightRoomInfo.roomInfo.OtherInfo.Count > 0)
- {
- for (int i = 0; i < startFightRoomInfo.roomInfo.OtherInfo.Count; i++)
- {
- var otherPlayInfo = startFightRoomInfo.roomInfo.OtherInfo[i];
- if (i >= startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count - 1)
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
- }
- else
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(false);
- }
- }
- }
- break;
- }
- case EventType.KickPush:
- {
- break;
- }
- case EventType.ReadyPush:
- {
- var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
- var startFightRoomComponent = ui.GetComponent<UIStartFightRoomComponent>();
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- //先处理自己的信息
- if (startFightRoomInfo.roomInfo.MyInfo != null)
- {
- startFightRoomComponent.readyBtn.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 0);
- startFightRoomComponent.inviteBtn.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 0);
- startFightRoomComponent.uIStartFightRoomPlayerComs[0].playerObj.SetActive(true);
- startFightRoomComponent.faceAndVideoObj.SetActive(true);
- startFightRoomComponent.uIStartFightRoomPlayerComs[0].readyImage.SetActive(startFightRoomInfo.roomInfo.MyInfo.state == 1);
- }
- //处理其他玩家信息
- for (int i = 1;i < startFightRoomComponent.uIStartFightRoomPlayerComs.Count;i++)
- {
- startFightRoomComponent.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
- }
- if (startFightRoomInfo.roomInfo.OtherInfo != null && startFightRoomInfo.roomInfo.OtherInfo.Count > 0)
- {
- for (int i = 0; i < startFightRoomInfo.roomInfo.OtherInfo.Count; i++)
- {
- var otherPlayInfo = startFightRoomInfo.roomInfo.OtherInfo[i];
- if (i >= startFightRoomComponent.uIStartFightRoomPlayerComs.Count - 1)
- {
- startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
- }
- else
- {
- startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
- startFightRoomComponent.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(otherPlayInfo.state == 1);
- }
- }
- }
- break;
- }
- case EventType.ReadyStartPush:
- {
- //开始 倒计时
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- Log.Error("@@@@@ 倒计时: " + startFightRoomInfo.readyStartTimeCount);
- var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
- var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
- startFightRoomComponentUI.startTimeCount = startFightRoomInfo.readyStartTimeCount;
- startFightRoomComponentUI.startTimer = TimerComponent.Instance.NewRepeatedTimer(ConstValue.fightTimeRefreshTime / 2 + 100, TimerInvokeType.startFightTimeCount, startFightRoomComponentUI);
- break;
- }
- case EventType.GameStartPush:
- case EventType.GameDrawCardPush:
- case EventType.GameOperationPush:
- {
- //正式开始 发牌
- var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
- var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- var myCardInfo = startFightRoomInfo.roomInfo.MyInfo;
- var otherCardInfo = startFightRoomInfo.roomInfo.OtherInfo;
- #region 其他玩家牌处理
- //处理其他玩家信息
- for (int i = 1; i < startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count; i++)
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i].playerObj.SetActive(false);
- }
- if (otherCardInfo != null && otherCardInfo.Count > 0)
- {
- RefreshPlayCardList(0, otherCardInfo, startFightRoomInfo.roomInfo, startFightRoomComponentUI);
- }
- #endregion
- #region 自己牌处理
- //处理牌型
- //自己牌
- if (myCardInfo != null)
- {
- RefreshPlayCardList(1, new List<PlayerInfo>() { myCardInfo }, startFightRoomInfo.roomInfo, startFightRoomComponentUI);
- }
- #endregion
- break;
- }
- case EventType.GameDisCardPush:
- {
- //其他玩家出推送,处理自己的操作
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- var myCardInfo = startFightRoomInfo.roomInfo.MyInfo;
- if (myCardInfo != null && myCardInfo.cardInfo != null && myCardInfo.cardInfo.Acts.Count > 0)
- {
- var ui = scene.GetComponent<UIComponent>().Get(UIType.UIStartFightRoom);
- var startFightRoomComponentUI = ui.GetComponent<UIStartFightRoomComponent>();
- startFightRoomComponentUI.operatorObj.SetActive(true);
- //处理操作按钮
- for (int i = 0;i < startFightRoomComponentUI.operatorObj_btn.Count;i++)
- {
- startFightRoomComponentUI.operatorObj_btn[i].SetActive(false);
- }
- for (int i = 0; i < myCardInfo.cardInfo.Acts.Count; i++)
- {
- if (myCardInfo.cardInfo.Acts[i] == 1)
- {
- startFightRoomComponentUI.operatorObj_btn[i].SetActive(true);
- }
- }
- //重置所有牌的状态
- var parentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].fightCardNode;
- for (int i = 0;i < parentNode.transform.childCount;i++)
- {
- StartFightCardItem startFightCardItem = parentNode.transform.GetChild(i).gameObject.GetComponent<StartFightCardItem>();
- startFightCardItem.GetDown();
- }
- GameObjectPool.Instance.ClearRealySelCardList();
- //抬起
- for (int i = 0; i < myCardInfo.cardInfo.ActInfo.Count; i++)
- {
- //根据服务器信息 弹起响应的牌
- DisCardPushWithOperator(parentNode.transform, myCardInfo.cardInfo.ActInfo[i]);
- }
- //记录当前出的牌
- startFightRoomComponentUI.curCardVal = startFightRoomInfo.roomInfo.CurDisCard;
- Log.Error("当前出的牌: " + startFightRoomComponentUI.curCardVal);
- }
- break;
- }
- }
- }
- #region 右上系统部分
- public static void OnMenuBtn(this UIStartFightRoomComponent self)
- {
- self.menuPanel.SetActive(!self.menuPanel.activeInHierarchy);
- }
- public static async void OnFaceBtn(this UIStartFightRoomComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- self.facePanel.SetActive(true);
- self.LoadChatData(0);
- }
- public static void OnVideoBtn(this UIStartFightRoomComponent self)
- {
- }
- #endregion
- #region 菜单
- public static void OnMenuPanelClose(this UIStartFightRoomComponent self)
- {
- self.menuPanel.SetActive(false);
- }
- public static async void OnMenuPanelBack(this UIStartFightRoomComponent self)
- {
- Action<object> myAction = (param) =>
- {
- int result = (int)param;
- if (result == 1)
- {
- self.ReturnMainUI().Coroutine();
- }
- };
- Dictionary<string,object> dic = new Dictionary<string, object>()
- {
- { "callback",myAction},
- { "title","提示"},
- { "content","返回大厅,你的房间仍会保留。"},
- { "yesTxt","确定"},
- { "cancelTxt","取消"},
- };
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Create(self.ClientScene(), UIType.UIAlert, UILayer.High, dic);
- }
- public static void OnMenuPanelQuit(this UIStartFightRoomComponent self)
- {
- }
- public static void OnMenuPanelSetting(this UIStartFightRoomComponent self)
- {
- }
- #endregion
- #region 表情
- public static async void OnFaceFastToggleBtn(this UIStartFightRoomComponent self,int index)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- self.LoadChatData(index);
- }
- static async void LoadChatData(this UIStartFightRoomComponent self, int index)
- {
- self.listFaceGridBg.SetActive(false);
- self.listFastGridBg.SetActive(false);
- string[] abName = new string[] { "com_bg1", "com_bg2" };
- await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "commonatlas");
- Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("commonatlas", abName[0]);
- Sprite sprite1 = ResourcesComponentHelper.Instance.GetSprite("commonatlas", abName[1]);
- self.fastToggleBtn.GetComponent<UnityEngine.UI.Image>().sprite = index == 0 ? sprite: sprite1;
- self.faceToggleBtn.GetComponent<UnityEngine.UI.Image>().sprite = index == 1 ? sprite : sprite1;
- self.CleanChatItem(index);
- if (index == 0)
- {
- self.listFastGridBg.SetActive(true);
- var startFightRoomInfo = self.ClientScene().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- int sexType = startFightRoomInfo.roomInfo.MyInfo.sex;
- var fightConfig = FightChatConfigCategory.Instance.GetAll();
- var achievedDic = fightConfig.Where(kvp => kvp.Value.Type == sexType);
- foreach (var item in achievedDic)
- {
- if (GameObjectPool.Instance.chatFastItemPools.Count > 0)
- {
- GameObject uiFastItem = GameObjectPool.Instance.chatFastItemPools[0];
- GameObjectPool.Instance.chatFastItemPools.RemoveAt(0);
- uiFastItem.SetActive(true);
- uiFastItem.transform.SetParent(self.listFastContent.transform, false);
- var txt = uiFastItem.GetComponentInChildren<UnityEngine.UI.Text>();
- txt.text = item.Value.Content;
- var btn = txt.gameObject.GetComponent<Button>();
- btn.onClick.RemoveAllListeners();
- btn.onClick.AddListener(async () =>
- {
- Log.Error("btn click1: " + item.Value.Content + " vedio: " + item.Value.VedioPath);
- await SoundManager.Instance.PlaySound(item.Value.VedioPath);
- self.facePanel.SetActive(false);
- self.playChatObjList[0].SetActive(true);
- var playChatTxt = self.playChatObjList[0].GetComponentInChildren<UnityEngine.UI.Text>();
- playChatTxt.text = item.Value.Content;
- await TimerComponent.Instance.WaitAsync(3000);
- self.playChatObjList[0].SetActive(false);
- });
- }
- else
- {
- var uiFastItem = GameUtil.Instance.InitializeObj(self.gridFastItem);
- uiFastItem.gameObject.SetActive(true);
- uiFastItem.transform.SetParent(self.listFastContent.transform, false);
- var txt = uiFastItem.GetComponentInChildren<UnityEngine.UI.Text>();
- txt.text = item.Value.Content;
- var btn = txt.gameObject.GetComponent<Button>();
- btn.onClick.RemoveAllListeners();
- btn.onClick.AddListener(async () =>
- {
- Log.Error("btn click1: " + item.Value.Content + " vedio: " + item.Value.VedioPath);
- await SoundManager.Instance.PlaySound(item.Value.VedioPath);
- self.facePanel.SetActive(false);
- self.playChatObjList[0].SetActive(true);
- var playChatTxt = self.playChatObjList[0].GetComponentInChildren<UnityEngine.UI.Text>();
- playChatTxt.text = item.Value.Content;
- await TimerComponent.Instance.WaitAsync(3000);
- self.playChatObjList[0].SetActive(false);
- });
- }
- }
- }
- else
- {
-
- }
- }
- static void CleanChatItem(this UIStartFightRoomComponent self,int index)
- {
- Transform node = null;
- List<GameObject> list = null;
- if (index == 0)
- {
- node = self.listFastContent.transform;
- list = GameObjectPool.Instance.chatFastItemPools;
- }
- else
- {
- node = self.listFaceContent.transform;
- list = GameObjectPool.Instance.chatFaceItemPools;
- }
- for (int i = 0; i < node.childCount; i++)
- {
- var child = node.GetChild(i);
- list.Add(child.gameObject);
- child.gameObject.SetActive(false);
- }
- }
- #endregion
- #region 邀请以及准备
- public static void OnReadyAndInviteBtn(this UIStartFightRoomComponent self, int index)
- {
- if (index == 0)
- {
- self.ReadyRes().Coroutine();
- }
- else
- {
- //邀请
- }
- }
- #endregion
- public static void SetBattery()
- {
- //var level = SystemInfo.batteryLevel == -1 ? 1 : SystemInfo.batteryLevel;
- //batteryLevelImg.fillAmount = level;
- //batteryTxt.text = (level * 100).ToString() + "%";
- //var isCharging = SystemInfo.batteryStatus == BatteryStatus.Charging;
- //charging.gameObject.SetActive(isCharging);
- }
- static async ETTask ReturnMainUI(this UIStartFightRoomComponent self)
- {
- var scene = self.ClientScene();
- await UIHelper.Remove(scene, UIType.UIStartFightRoom);
- var startFightRoomInfo = scene.GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- Dictionary<string, object> dic = new Dictionary<string, object>()
- {
- { "result",1},
- { "roomId",startFightRoomInfo.roomInfo.RoomId.ToString()}
- };
- await UIHelper.Create(scene, UIType.UIMain, UILayer.Mid, dic);
- }
- static async ETTask ReadyRes(this UIStartFightRoomComponent self)
- {
- //try
- {
- var scene = self.ClientScene();
- var session = scene.GetComponent<SessionComponent>().Session;
- if (session != null)
- {
- G2C_Ready g2Ready = (G2C_Ready)await session.Call(
- new C2G_Ready() { });
- if (g2Ready.Error != ErrorCode.ERR_Success)
- {
- Log.Error($"g2Ready错误...errCode={g2Ready.Error}" + " mess: " + g2Ready.Message);
- return;
- }
- }
- }
- //catch (Exception e)
- //{
- // Log.Error($"准备出错...{e.Message}");
- //}
- }
- public static async void OnCloseAsync(this UIStartFightRoomComponent self)
- {
- await UIHelper.Remove(self.ClientScene(),UIType.UIStartFightRoom);
- }
- public static async void OnOperatorBtn(this UIStartFightRoomComponent self, int operatorIndex)
- {
- var startFightRoomInfo = GameUtil.Instance.GetSceneComponent().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- int sexType = startFightRoomInfo.roomInfo.MyInfo.sex;
- switch (operatorIndex)
- {
- case 1:
- {
- //吃
- var list = GameObjectPool.Instance.GetRealySelCardList();
- if (list == null || list.Count <= 0 || list.Count > 3)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- return;
- }
- var isSequence = GameUtil.Instance.CheckIsSequence(list);
- if (!isSequence)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- return;
- }
- int cardVal = list[0];
- Log.Error("当前吃牌请求发送的值: " + cardVal);
- Dictionary<string, object> dic = new Dictionary<string, object>()
- {
- { "OpType",operatorIndex},
- { "Card",cardVal}
- };
- await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_Operation,dic,async (messageObj, errorCode) =>
- {
- if (errorCode != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"操作失败,errCode={errorCode},operatorType={operatorIndex}");
- return;
- }
- string soundStrType = sexType == 0 ? GameSetting.Instance.disCardBoySoundName : GameSetting.Instance.disCardGirlSoundName;
- await SoundManager.Instance.PlaySound(string.Concat(soundStrType, "chi"));
- });
- break;
- }
- //case 2:
- // {
- // //碰
- // var list = GameObjectPool.Instance.GetRealySelCardList();
- // if (list == null || list.Count <= 0 || list.Count > 3)
- // {
- // await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- // return;
- // }
- // var isSequence = GameUtil.Instance.CheckIsSame(list,0);
- // if (!isSequence)
- // {
- // await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- // return;
- // }
- // int cardVal = list[0];
- // Log.Error("当前碰牌请求发送的值: " + cardVal);
- // Dictionary<string, object> dic = new Dictionary<string, object>()
- // {
- // { "OpType",operatorIndex},
- // { "Card",0}
- // };
- // await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_Operation, dic, async (messageObj, errorCode) =>
- // {
- // if (errorCode != ErrorCode.ERR_Success)
- // {
- // await CommonUtil.Instance.OpenCommonServerMsgPanel($"操作失败,errCode={errorCode},operatorType={operatorIndex}");
- // return;
- // }
- // });
- // break;
- // }
- case 2:
- case 3:
- case 5:
- {
- //胡 peng guo
- Dictionary<string, object> dic = new Dictionary<string, object>()
- {
- { "OpType",operatorIndex},
- { "Card",0}
- };
- await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_Operation, dic, async (messageObj, errorCode) =>
- {
- if (errorCode != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"操作失败,errCode={errorCode},operatorType={operatorIndex}");
- return;
- }
-
- if (operatorIndex == 2 || operatorIndex == 3)
- {
- string soundStrType = sexType == 0 ? GameSetting.Instance.disCardBoySoundName : GameSetting.Instance.disCardGirlSoundName;
- string destSoundStr = operatorIndex == 2? "peng": "hu";
- await SoundManager.Instance.PlaySound(string.Concat(soundStrType, destSoundStr));
- }
- });
- break;
- }
- case 4:
- {
- //杠
- var list = GameObjectPool.Instance.GetRealySelCardList();
- if (list == null || list.Count <= 0 || list.Count > 4)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- return;
- }
- var isSequence = GameUtil.Instance.CheckIsSame(list, 1);
- if (!isSequence)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel("出牌不符合条件,请重新调整 " + string.Join(", ", list));
- return;
- }
- int cardVal = list[0];
- Log.Error("当前杠牌请求发送的值: " + cardVal);
- Dictionary<string, object> dic = new Dictionary<string, object>()
- {
- { "OpType",operatorIndex},
- { "Card",cardVal}
- };
- await RequestServerUtil.Instance.OpenRequestServer(OuterMessage.C2G_Operation, dic, async (messageObj, errorCode) =>
- {
- if (errorCode != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"操作失败,errCode={errorCode},operatorType={operatorIndex}");
- return;
- }
- string soundStrType = sexType == 0 ? GameSetting.Instance.disCardBoySoundName : GameSetting.Instance.disCardGirlSoundName;
- await SoundManager.Instance.PlaySound(string.Concat(soundStrType, "gang"));
- });
- break;
- }
- }
- }
- public static async void RefreshPlayCardList(int index, List<PlayerInfo> playerInfos,RoomInfo roomInfo, UIStartFightRoomComponent startFightRoomComponentUI)
- {
- if (index == 0)
- {
- for (int i = 0; i < playerInfos.Count; i++)
- {
- var otherPlayInfo = playerInfos[i];
- if (i >= startFightRoomComponentUI.uIStartFightRoomPlayerComs.Count - 1)
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(false);
- }
- else
- {
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].playerObj.SetActive(true);
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].readyImage.SetActive(false);
- var fightCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].fightCardNode;
- var disCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[i + 1].disCardsNode;
- CleanCardItemList(fightCardParentNode.transform,0);
- for (int p = 0; p < otherPlayInfo.cardInfo.RemainCardsNum; p++)
- {
- if (GameObjectPool.Instance.fightCardItemPools.Count > 0)
- {
- GameObject uifightItem = GameObjectPool.Instance.fightCardItemPools[0];
- GameObjectPool.Instance.fightCardItemPools.RemoveAt(0);
- uifightItem.gameObject.SetActive(true);
- uifightItem.transform.SetParent(fightCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(GameSetting.Instance.otherPlayCardSpiteName);
- UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- var btn = icon.gameObject.GetComponent<Button>();
- btn.onClick.RemoveAllListeners();
- btn.onClick.AddListener(() =>
- {
- Log.Error("card Click...");
- });
- }
- else
- {
- int cloneItemIndex = i % 2 == 0? 1 : 0;
- var uifightItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(cloneItemIndex));
- uifightItem.SetActive(true);
- uifightItem.transform.SetParent(fightCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(GameSetting.Instance.otherPlayCardSpiteName);
- UnityEngine.UI.Image icon = uifightItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- }
- }
- //已经出过的牌列表
- CleanCardItemList(disCardParentNode.transform, 1);
- if (otherPlayInfo.cardInfo.DisCards != null)
- {
- for (int l = 0; l < otherPlayInfo.cardInfo.DisCards.Count; l++)
- {
- int value = otherPlayInfo.cardInfo.DisCards[l];
- if (GameObjectPool.Instance.disCardItemPools.Count > 0)
- {
- GameObject uiDisItem = GameObjectPool.Instance.disCardItemPools[0];
- GameObjectPool.Instance.disCardItemPools.RemoveAt(0);
- uiDisItem.gameObject.SetActive(true);
- uiDisItem.transform.SetParent(disCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
- UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- }
- else
- {
- int cloneItemIndex = i % 2 == 0 ? 1 : 0;
- var uiDisItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(cloneItemIndex));
- uiDisItem.SetActive(true);
- uiDisItem.transform.SetParent(disCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
- UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- }
- }
- }
- }
- }
- }
- else
- {
- var myCardInfo = playerInfos[0];
- if (myCardInfo.cardInfo.RemainCards == null)
- {
- Log.Error("自己牌队列为NULL");
- return;
- }
- var parentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].fightCardNode;
- var disCardParentNode = startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].disCardsNode;
- startFightRoomComponentUI.uIStartFightRoomPlayerComs[0].readyImage.SetActive(false);
- Log.Error("card数量: " + myCardInfo.cardInfo.RemainCards.Count);
- CleanCardItemList(parentNode.transform,0);
- for (int i = 0; i < myCardInfo.cardInfo.RemainCards.Count;i++)
- {
- var value = myCardInfo.cardInfo.RemainCards[i];
- if (GameObjectPool.Instance.fightCardItemPools.Count > 0)
- {
- GameObject uifightItem = GameObjectPool.Instance.fightCardItemPools[0];
- StartFightCardItem startFightCardItem = uifightItem.GetComponent<StartFightCardItem>();
- if(startFightCardItem == null)
- startFightCardItem = uifightItem.AddComponent<StartFightCardItem>();
- GameObjectPool.Instance.fightCardItemPools.RemoveAt(0);
- uifightItem.gameObject.SetActive(true);
- uifightItem.transform.SetParent(parentNode.transform, false);
- startFightCardItem.Init(uifightItem.GetComponentInChildren<UnityEngine.UI.Image>(), value,(val)=>
- {
- if (myCardInfo.state != roomInfo.OpPos || myCardInfo.id != roomInfo.OpId)
- {
- Log.Error("不是自己回合");
- return;
- }
- DisCardRequest(val).Coroutine();
- });
- }
- else
- {
- var uifightItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(0));
- StartFightCardItem startFightCardItem = uifightItem.GetComponent<StartFightCardItem>();
- if (startFightCardItem == null)
- startFightCardItem = uifightItem.AddComponent<StartFightCardItem>();
- uifightItem.gameObject.SetActive(true);
- uifightItem.transform.SetParent(parentNode.transform, false);
- startFightCardItem.Init(uifightItem.GetComponentInChildren<UnityEngine.UI.Image>(), value, (val) =>
- {
- if (myCardInfo.state != roomInfo.OpPos || myCardInfo.id != roomInfo.OpId)
- {
- Log.Error("不是自己回合");
- return;
- }
- DisCardRequest(val).Coroutine();
- });
- }
- }
- //已经出过的牌列表
- CleanCardItemList(disCardParentNode.transform, 1);
- if (myCardInfo.cardInfo.DisCards != null)
- {
- for (int l = 0; l < myCardInfo.cardInfo.DisCards.Count; l++)
- {
- int value = myCardInfo.cardInfo.DisCards[l];
- if (GameObjectPool.Instance.disCardItemPools.Count > 0)
- {
- GameObject uiDisItem = GameObjectPool.Instance.disCardItemPools[0];
- GameObjectPool.Instance.disCardItemPools.RemoveAt(0);
- uiDisItem.gameObject.SetActive(true);
- uiDisItem.transform.SetParent(disCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
- UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- }
- else
- {
- var uiDisItem = GameUtil.Instance.InitializeObj(GameUtil.Instance.GetCardCloneItem(0));
- uiDisItem.SetActive(true);
- uiDisItem.transform.SetParent(disCardParentNode.transform, false);
- var sprite = await GameObjectPool.Instance.AcquireSprite(string.Concat(GameSetting.Instance.selfPlayCardSpiteName, value));
- UnityEngine.UI.Image icon = uiDisItem.GetComponentInChildren<UnityEngine.UI.Image>();
- icon.sprite = sprite;
- }
- }
- }
- }
- }
- #region 请求相关
- //操作,chi p hu
- public static async ETTask OperationCardRequest(int operationType,int firstCard)
- {
- try
- {
- var scene = GameUtil.Instance.GetSceneComponent();
- var session = scene.GetComponent<SessionComponent>().Session;
- if (session != null)
- {
- G2C_Operation g2Operation = (G2C_Operation)await session.Call(
- new C2G_Operation() { OpType = operationType , Card = firstCard });
- if (g2Operation.Error != ErrorCode.ERR_Success)
- {
- Log.Error($"操作 {operationType} 出错...errCode={g2Operation.Error}");
- return;
- }
- //之后走推送
- }
- }
- catch (Exception e)
- {
- Log.Error($"操作 {operationType} 出错...{e.Message}");
- }
- }
- //出
- public static async ETTask DisCardRequest(int disCard)
- {
- try
- {
- var scene = GameUtil.Instance.GetSceneComponent();
- var session = scene.GetComponent<SessionComponent>().Session;
- if (session != null)
- {
- G2C_DisCard g2DisCard = (G2C_DisCard)await session.Call(
- new C2G_DisCard() { Card = disCard });
- if (g2DisCard.Error != ErrorCode.ERR_Success)
- {
- await CommonUtil.Instance.OpenCommonServerMsgPanel($"出牌{disCard} 出错...errCode={g2DisCard.Error}");
- return;
- }
- var startFightRoomInfo = GameUtil.Instance.GetSceneComponent().GetComponent<StartFightRoomComponment>().GetStartFightRoomInfo();
- int sexType = startFightRoomInfo.roomInfo.MyInfo.sex;
- string soundStrType = sexType == 0 ? GameSetting.Instance.disCardBoySoundName : GameSetting.Instance.disCardGirlSoundName;
- await SoundManager.Instance.PlaySound(string.Concat(soundStrType, disCard));
- //之后走推送
- }
- }
- catch (Exception e)
- {
- Log.Error($"操作 {disCard} 出错...{e.Message}");
- }
- }
- #endregion
- public static void CleanCardItemList(Transform node,int index)
- {
- List<GameObject> tempList = index == 0? GameObjectPool.Instance.fightCardItemPools: GameObjectPool.Instance.disCardItemPools;
- for (int i = 0;i < node.childCount;i++)
- {
- var child = node.GetChild(i);
- tempList.Add(child.gameObject);
- child.gameObject.SetActive(false);
- }
- }
- public static void DisCardPushWithOperator(Transform node, ActInfo actInfo)
- {
- ActInfoType actInfoType = (ActInfoType)actInfo.Type;
- switch (actInfoType)
- {
- case ActInfoType.LightPole:
- case ActInfoType.BackPole:
- case ActInfoType.DarkPole:
- {
- var cardVal = actInfo.Card;
- int loopIndex = 1;
- for (int i = 0; i < node.childCount; i++)
- {
- if (loopIndex > 3)
- {
- break;
- }
- var child = node.GetChild(i);
- StartFightCardItem startFightCardItem = child.gameObject.GetComponent<StartFightCardItem>();
- if (startFightCardItem.val == cardVal)
- {
- startFightCardItem.StandUp();
- }
- loopIndex++;
- }
- //将出的牌添加到操作列表里面去
- GameObjectPool.Instance.OperatoRarealySelCardList(0, cardVal);
- break;
- }
- case ActInfoType.Peng:
- {
- var cardVal = actInfo.Card;
- int loopIndex = 1;
- for (int i = 0; i < node.childCount; i++)
- {
- if (loopIndex >= 3)
- {
- break;
- }
- var child = node.GetChild(i);
- StartFightCardItem startFightCardItem = child.gameObject.GetComponent<StartFightCardItem>();
- if (startFightCardItem.val == cardVal)
- {
- startFightCardItem.StandUp();
- }
- loopIndex++;
- }
- GameObjectPool.Instance.OperatoRarealySelCardList(0, cardVal);
- break;
- }
- case ActInfoType.Chi:
- {
- var cardVal = actInfo.Card;
- int loopIndex = 1;
- for (int i = 0; i < node.childCount; i++)
- {
- if (loopIndex >= 3)
- {
- break;
- }
- var child = node.GetChild(i);
- StartFightCardItem startFightCardItem = child.gameObject.GetComponent<StartFightCardItem>();
- if (startFightCardItem.val == cardVal + 1)
- {
- startFightCardItem.StandUp();
- }
- cardVal = startFightCardItem.val;
- loopIndex++;
- }
- GameObjectPool.Instance.OperatoRarealySelCardList(0, cardVal);
- break;
- }
- }
- }
- [ObjectSystem]
- public class UIStartFightRoomComponentDestroySystem : DestroySystem<UIStartFightRoomComponent>
- {
- protected override void Destroy(UIStartFightRoomComponent self)
- {
- TimerComponent.Instance?.Remove(ref self.RepeatedTimer);
- CommonBridge.Instance.Clear();
- }
- }
- }
- }
|