123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.UI;
- using static System.Net.Mime.MediaTypeNames;
- namespace ET.Client
- {
- [FriendOf(typeof(UIJoinRoomComponent))]
- public static class UIJoinRoomComponentSystem
- {
- [ObjectSystem]
- public class UIJoinRoomComponentAwakeSystem : AwakeSystem<UIJoinRoomComponent>
- {
- protected override void Awake(UIJoinRoomComponent self, params object[] param)
- {
- ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
- self.inputBackBtn = rc.Get<GameObject>("inputBack");
- self.inputClearBtn = rc.Get<GameObject>("inputClear");
- self.closeBtn = rc.Get<GameObject>("closeBtn");
- self.showTxt = rc.Get<GameObject>("showTxt");
- for (int i = 0;i <= 9;i++)
- {
- var tempInput = rc.Get<GameObject>("input" + i);
- int index = i;
- tempInput.GetComponent<Button>().onClick.AddListener(() => { self.OnInputNumber(index); });
- }
- self.inputBackBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInputBack(); });
- self.inputClearBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnInputClear(); });
- self.closeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseAsync(); });
- self.showTxt.GetComponent<UnityEngine.UI.Text>().text = "";
- }
- }
- private static void updateShowText(this UIJoinRoomComponent self, string add = "")
- {
- if (!string.IsNullOrEmpty(add) && self.inputText.Length < 6)
- {
- self.inputText = self.inputText + add;
- }
- if (self.inputText.Length == 6)
- {
- //已经6位了。。。
- //加入房间请求。。
- self.JoinRoom().Coroutine();
- }
- self.showTxt.GetComponent<UnityEngine.UI.Text>().text = self.inputText;
- }
- public static async void OnInputNumber(this UIJoinRoomComponent self,int index)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- self.updateShowText(index.ToString());
- }
- public static async void OnInputBack(this UIJoinRoomComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- if (self.inputText.Length > 0)
- {
- self.inputText = self.inputText.Substring(0, self.inputText.Length - 1);
- self.showTxt.GetComponent<UnityEngine.UI.Text>().text = self.inputText;
- }
- }
- public static async void OnInputClear(this UIJoinRoomComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- self.inputText = string.Empty;
- self.updateShowText();
- }
- static async ETTask JoinRoom(this UIJoinRoomComponent self)
- {
- if (string.IsNullOrEmpty(self.inputText) || self.inputText.Length < 6)
- {
- Log.Error("输入房间号");
- return;
- }
- try
- {
- var scene = self.ClientScene();
- var session = scene.GetComponent<SessionComponent>().Session;
- if (session != null)
- {
- G2C_JoinRoom g2JoinRoom = (G2C_JoinRoom)await session.Call(
- new C2G_JoinRoom() { RoomId = int.Parse(self.inputText) });
- if (g2JoinRoom.Error != ErrorCode.ERR_Success)
- {
- Log.Error($"g2JoinRoom错误...errCode={g2JoinRoom.Error}");
- return;
- }
- //改成推送了
- //var startFightRoomComponment = scene.GetComponent<StartFightRoomComponment>();
- //if (startFightRoomComponment == null)
- //{
- // startFightRoomComponment = scene.AddComponent<StartFightRoomComponment>();
- //}
- //startFightRoomComponment.ClearStartFightRoomInfo();
- //startFightRoomComponment.SetStartFightRoomInfo(g2JoinRoom);
- //目前就用一个场景吧,后面看再单独分开。
- //关闭主界面
- await UIHelper.Remove(scene, UIType.UIMain);
- await UIHelper.Remove(scene, UIType.UIJoinRoom);
- //打开开始打牌界面
- await UIHelper.Create(scene, UIType.UIStartFightRoom, UILayer.Mid);
- }
- }
- catch (Exception e)
- {
- Log.Error($"创建房间出错...{e.Message}");
- }
- }
- public static async void OnCloseAsync(this UIJoinRoomComponent self)
- {
- await SoundManager.Instance.PlaySound("clickbtnsound");
- await UIHelper.Remove(self.ClientScene(),UIType.UIJoinRoom);
- }
- }
- }
|