public void OnLogin(JsonData jd) { Debug.Log("OnLogin: "******"ErrCode"].ToString()); var errMsg = jd["ErrMsg"].ToString(); if (errMsg.Length > 0) { tips.Show(errMsg); return; } if (errCode == 0) { OnLoginSuccessful(jd); return; } var loginType = int.Parse(jd["LoginType"].ToString()); if (loginType == 2) // Token 登录 { Utils.Log("Token登录失败"); MainThread.Run(() => { Utils.SetToken(""); }); return; } }
//生成对局不存在的卡牌 private static void CreatBoardCardVitual() { MainThread.Run(() => { Info.GameUI.UiInfo.CardBoard.transform.GetChild(1).GetComponent <Text>().text = Info.GameUI.UiInfo.CardBoardTitle; Info.GameUI.UiInfo.ShowCardLIstOnBoard.ForEach(GameObject.Destroy); List <int> CardIds = Info.AgainstInfo.cardBoardIDList; for (int i = 0; i < CardIds.Count; i++) { var CardStandardInfo = Command.CardInspector.CardLibraryCommand.GetCardStandardInfo(CardIds[i]); GameObject NewCard = GameObject.Instantiate(Info.GameUI.UiInfo.CardModel); NewCard.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = CardStandardInfo.describe; //string Title = card.CardName; //string Text = card.CardIntroduction; //string Effect = ""; //int Heigh = Text.Length / 13 * 15 + 100; //Info.GameUI.UiInfo.IntroductionTextBackground.sizeDelta = new Vector2(300, Heigh); ////修改文本为富文本 //Info.GameUI.UiInfo.IntroductionTitle.text = Title; //Info.GameUI.UiInfo.IntroductionText.text = Text; //Info.GameUI.UiInfo.IntroductionEffect.text = Effect; NewCard.GetComponent <BoardCardControl>().Rank = i; NewCard.transform.SetParent(Info.GameUI.UiInfo.Constant); Texture2D texture = CardStandardInfo.icon; NewCard.GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero); Info.GameUI.UiInfo.ShowCardLIstOnBoard.Add(NewCard); } Info.GameUI.UiInfo.Constant.GetComponent <RectTransform>().sizeDelta = new Vector2(CardIds.Count * 325 + 200, 800); }); }
public static void JoinRoom() { Debug.Log("登录请求"); var client = new WebSocket($"ws://{ip}/Join"); client.OnMessage += (sender, e) => { Debug.LogError("收到了来自服务器的初始信息" + e.Data); object[] ReceiveInfo = e.Data.ToObject <GeneralCommand>().Datas; Info.AgainstInfo.RoomID = int.Parse(ReceiveInfo[0].ToString()); Debug.Log("房间号为" + Info.AgainstInfo.RoomID); Info.AgainstInfo.isPlayer1 = (bool)ReceiveInfo[1]; Debug.Log("是否玩家1?:" + Info.AgainstInfo.isPlayer1); Info.AgainstInfo.isPVP = true; //Info.AgainstInfo.isMyTurn = Info.AgainstInfo.isPlayer1; Info.AllPlayerInfo.UserInfo = ReceiveInfo[2].ToString().ToObject <PlayerInfo>(); Info.AllPlayerInfo.OpponentInfo = ReceiveInfo[3].ToString().ToObject <PlayerInfo>(); Debug.Log("收到回应: " + e.Data); //client.Close(); MainThread.Run(() => { SceneManager.LoadSceneAsync(2); InitAsyncConnection(); }); }; client.Connect(); Debug.Log("连接完成"); client.Send(Info.AllPlayerInfo.UserInfo.ToJson()); Debug.Log(Info.AllPlayerInfo.UserInfo.ToJson()); Debug.Log("发送完毕"); }
public static void Register(string name, string password) { Debug.Log("注册请求"); var client = new WebSocket($"ws://{ip}/Register"); client.OnMessage += (sender, e) => { Debug.Log("有回应了"); Debug.Log(e.Data); string result = e.Data; MainThread.Run(() => { //打开弹窗 if (result == "1") { Debug.Log("注册成功"); } if (result == "-1") { Debug.Log("账号已存在"); } }); Debug.Log("收到回应: " + e.Data); client.Close(); }; client.Connect(); client.Send(new GeneralCommand <string>(name, password).ToJson()); }
public static void SetCardBoardHide() { MainThread.Run(() => { Info.GameUI.UiInfo.CardBoard.SetActive(false); }); }
public static void OpenToPage(PageMode pageMode) { Task.Run(async() => { MainThread.Run(() => { singlePage.SetActive(false); multiplayerPage.SetActive(false); cardLibraryPage.SetActive(false); shrinePage.SetActive(false); collectPage.SetActive(false); configPage.SetActive(false); }); await Task.Delay(1000); MainThread.Run(() => { switch (pageMode) { case PageMode.single: singlePage.SetActive(true); break; case PageMode.multiplayer: multiplayerPage.SetActive(true); break; case PageMode.cardLibrary: cardLibraryPage.SetActive(true); Control.CardLibraryPageControl.InitCardLibrary(); Control.CardLibraryPageControl.InitCardDeck(); break; case PageMode.shrine: shrinePage.SetActive(true); break; case PageMode.collect: collectPage.SetActive(true); break; case PageMode.config: configPage.SetActive(true); break; case PageMode.none: singlePage.SetActive(false); multiplayerPage.SetActive(false); cardLibraryPage.SetActive(false); shrinePage.SetActive(false); collectPage.SetActive(false); configPage.SetActive(false); break; default: break; } }); }); }
public static void SetCardBoardShow() { MainThread.Run(() => { Info.GameUI.UiInfo.CardBoard.SetActive(true); Info.GameUI.UiInfo.CardBoard.transform.GetChild(1).GetComponent <Text>().text = Info.GameUI.UiInfo.CardBoardTitle; }); }
public static void DestoryAllArrow() { MainThread.Run(() => { Info.AgainstInfo.ArrowList.ForEach(Destroy); Info.AgainstInfo.ArrowList.Clear(); }); }
public static void ReSetPassState() { MainThread.Run(() => { Info.GameUI.UiInfo.MyPass.SetActive(false); Info.GameUI.UiInfo.OpPass.SetActive(false); Info.AgainstInfo.isUpPass = false; Info.AgainstInfo.isDownPass = false; }); }
private void OnLoginSuccessful(JsonData jd) { MainThread.Run(() => { Utils.SetAccount(jd["Account"].ToString()); Utils.SetToken(jd["Token"].ToString()); SceneManager.LoadScene("Hall"); }); }
public static void DestoryFreeArrow() { MainThread.Run(() => { GameObject targetArrow = Info.AgainstInfo.ArrowList.First(arrow => arrow.GetComponent <ArrowManager>().targetCard == null); Info.AgainstInfo.ArrowList.Remove(targetArrow); Destroy(targetArrow); }); }
public static void ParticlePlay(int Rank, Card card) { MainThread.Run(() => { ParticleSystem TargetParticle = GameObject.Instantiate(Info.ParticleInfo.Instance.ParticleEffect[Rank]); TargetParticle.transform.position = card.transform.position; TargetParticle.Play(); GameObject.Destroy(TargetParticle.gameObject, 2); }); }
public static void AudioEffectPlay(int Rank) { MainThread.Run(() => { AudioSource Source = Info.AudioInfo.Instance.gameObject.AddComponent <AudioSource>(); Source.clip = Info.AudioInfo.Instance.Clips[Rank]; Source.Play(); GameObject.Destroy(Source, Source.clip.length); }); }
internal static void Bullet_Hurt(TriggerInfo triggerInfo) { MainThread.Run(() => { GameObject Bullet = GameObject.Instantiate(Info.ParticleInfo.Instance.HurtBullet); BulletControl bulletControl = Bullet.GetComponent <BulletControl>(); bulletControl.Init(triggerInfo.triggerCard, triggerInfo.targetCard); bulletControl.Play(); Bullet.GetComponent <ParticleSystem>().Play(); }); }
public static async Task NoticeBoardShow() { MainThread.Run(() => { Info.GameUI.UiInfo.NoticeBoard.transform.GetChild(0).GetComponent <Text>().text = Info.GameUI.UiInfo.NoticeBoardTitle; }); Info.GameUI.UiInfo.isNoticeBoardShow = true; await Task.Delay(1000); Info.GameUI.UiInfo.isNoticeBoardShow = false; }
public static async Task BanishCard(Card card) { MainThread.Run(() => { card.GetComponent <CardControl>().CreatGap(); }); await Task.Delay(800); MainThread.Run(() => { card.GetComponent <CardControl>().FoldGap(); }); await Task.Delay(800); MainThread.Run(() => { card.GetComponent <CardControl>().DestoryGap(); }); RemoveCard(card); }
public static void DestoryFixedArrow(Card card) { MainThread.Run(() => { //Arrow定位出错? GameObject targetArrow = Info.AgainstInfo.ArrowList.First(arrow => arrow.GetComponent <ArrowManager>().targetCard == card); Debug.LogError("确实是" + targetArrow.GetComponent <ArrowManager>().targetCard); Debug.LogError("确实是" + targetArrow); Info.AgainstInfo.ArrowList.Remove(targetArrow); Destroy(targetArrow); }); }
public static void CreatFixedArrow(Card card) { MainThread.Run(() => { GameObject newArrow = Instantiate(Info.GameUI.UiInfo.Arrow); newArrow.name = "Arrow-" + card.name; newArrow.GetComponent <ArrowManager>().InitArrow( Info.AgainstInfo.ArrowStartCard, Info.AgainstInfo.PlayerFocusCard ); Info.AgainstInfo.ArrowList.Add(newArrow); }); }
//public static void SetCardBoardMode(CardBoardMode CardBoardMode) => Info.AgainstInfo.CardBoardMode = CardBoardMode; public static void SetCurrentPass() { MainThread.Run(() => { Info.GameUI.UiInfo.MyPass.SetActive(true); switch (Info.AgainstInfo.isMyTurn) { case true: Info.AgainstInfo.isDownPass = true; break; case false: Info.AgainstInfo.isUpPass = true; break; } }); }
public static void CreatFreeArrow() { MainThread.Run(() => { GameObject newArrow = Instantiate(Info.GameUI.UiInfo.Arrow); newArrow.name = "Arrow-null"; newArrow.GetComponent <ArrowManager>().InitArrow( Info.AgainstInfo.ArrowStartCard, Info.GameUI.UiInfo.ArrowEndPoint ); Info.AgainstInfo.ArrowList.Add(newArrow); }); }
public void OnServerDisonnect() { if (Global.account == "" || Global.token == "") { Debug.Log("与服务器断开连接"); MainThread.Run(() => { SceneManager.LoadScene("Login"); }); return; } Messenger.AddListener("OnServerConnect", TokenLogin); Global.gsws.Connect(); }
public static void ChangeProperty(Region region) { Task.Run(async() => { Info.AgainstInfo.SelectProperty = region; Debug.Log("设置属性为" + Info.AgainstInfo.SelectProperty); MainThread.Run(() => { center_end = new Vector3(0, 0, 360 + (int)region * 90); centerTime = Time.time; }); await Task.Delay(1000); MainThread.Run(() => Fold()); }); }
public static async Task BattleEnd(bool IsSurrender = false, bool IsWin = true) { //Debug.Log("回合结束"); await Task.Run(async() => { GameUI.UiCommand.SetNoticeBoardTitle($"对战终止\n{AgainstInfo.ShowScore.MyScore}:{AgainstInfo.ShowScore.OpScore}"); await GameUI.UiCommand.NoticeBoardShow(); await Task.Delay(2000); MainThread.Run(() => { Debug.Log("释放线程资源"); StateInfo.TaskManager.Cancel(); SceneManager.LoadSceneAsync(1); }); }); }
public void TokenLogin() { Messenger.RemoveListener("OnServerConnect", TokenLogin); if (Global.account == "" || Global.token == "") { MainThread.Run(() => { Debug.Log("token 无效"); SceneManager.LoadScene("Login"); }); return; } Global.gsws.SendMsg(new C2S_Login().CreateTokenLoginMsg(Global.account, Global.token, "zh")); }
public static async Task <Card> CreatCard(int id) { Card NewCardScript = null; MainThread.Run(() => { GameObject NewCard = GameObject.Instantiate(Info.CardInfo.cardModel); NewCard.transform.SetParent(GameObject.FindGameObjectWithTag("Card").transform); NewCard.name = "Card" + Info.CardInfo.CreatCardRank++; var CardStandardInfo = CardLibraryCommand.GetCardStandardInfo(id); NewCard.AddComponent(Type.GetType("CardSpace.Card" + id)); Card card = NewCard.GetComponent <Card>(); card.CardId = CardStandardInfo.cardId; card.basePoint = CardStandardInfo.point; card.icon = CardStandardInfo.icon; card.region = CardStandardInfo.cardProperty; card.territory = CardStandardInfo.cardTerritory; card.cardTag = CardStandardInfo.cardTag; card.cardRank = CardStandardInfo.cardRank; card.cardType = CardStandardInfo.cardType; card.GetComponent <Renderer>().material.SetTexture("_Front", card.icon); switch (card.cardRank) { case CardRank.Leader: card.GetComponent <Renderer>().material.SetColor("_side", new Color(0.43f, 0.6f, 1f)); break; case CardRank.Gold: card.GetComponent <Renderer>().material.SetColor("_side", new Color(0.8f, 0.8f, 0f)); break; case CardRank.Silver: card.GetComponent <Renderer>().material.SetColor("_side", new Color(0.75f, 0.75f, 0.75f)); break; case CardRank.Copper: card.GetComponent <Renderer>().material.SetColor("_side", new Color(1, 0.42f, 0.37f)); break; default: break; } //if (card.cardType== CardType.Special) //{ // card.transform.GetChild(0).GetChild(0).get //} card.Init(); NewCardScript = card; }); await Task.Run(() => { while (NewCardScript == null) { } }); return(NewCardScript); }
public void Show(string text, Action action) { MainThread.Run(() => { prefab.SetActive(true); tipsText.text = text; Utils.DelayRun2(3f, () => { prefab.SetActive(false); if (action != null) { action.Invoke(); } }); }); }
public static async Task SealCard(Card card) { Debug.Log("锁定卡牌!"); if (card.cardStates.ContainsKey(CardState.Seal) && card.cardStates[CardState.Seal]) { card.cardStates[CardState.Seal] = false; MainThread.Run(() => { card.transform.GetChild(2).gameObject.SetActive(false); }); } else { card.cardStates[CardState.Seal] = true; MainThread.Run(() => { card.transform.GetChild(2).gameObject.SetActive(true); }); } }
public static void UpdateDecks(PlayerInfo playerInfo) { Debug.Log("更新请求"); var client = new WebSocket($"ws://{ip}/UpdateDecks"); client.OnMessage += (sender, e) => { MainThread.Run(() => { //string result = e.Data.ToObject<GeneralCommand<string>>().Datas[0]; //string playerInfo = e.Data.ToObject<GeneralCommand<string>>().Datas[1]; Debug.Log("修改完毕"); //Info.AllPlayerInfo.UserInfo = playerInfo.ToObject<PlayerInfo>(); //SceneManager.LoadSceneAsync(1); }); Debug.Log("收到回应: " + e.Data); client.Close(); }; client.Connect(); Debug.Log("连接完成"); client.Send(playerInfo.ToJson()); }
public static void Login(string name, string password) { Debug.Log("登录请求"); var client = new WebSocket($"ws://{ip}/Login"); client.OnMessage += (sender, e) => { MainThread.Run(() => { string result = e.Data.ToObject <GeneralCommand <string> >().Datas[0]; string playerInfo = e.Data.ToObject <GeneralCommand <string> >().Datas[1]; Debug.Log("登录结果" + result); Info.AllPlayerInfo.UserInfo = playerInfo.ToObject <PlayerInfo>(); //SceneManager.LoadSceneAsync(1); }); Debug.Log("收到回应: " + e.Data); client.Close(); }; client.Connect(); Debug.Log("连接完成"); client.Send(new GeneralCommand <string>(name, password).ToJson()); }
public static void TheWorldPlay(Card card) { MainThread.Run(() => { SceneEffectInfo.theWorldEffect.gameObject.SetActive(true); Vector3 screenPoint = Camera.main.WorldToScreenPoint(card.transform.position); SceneEffectInfo.theWorldEffect.transform.position = Camera.main.ScreenPointToRay(screenPoint).GetPoint(5); }); Task.Run(async() => { TheWorldEffect.state = 0; await Task.Delay(1000); TheWorldEffect.state = 1; await Task.Delay(2000); TheWorldEffect.state = 0; await Task.Delay(1000); MainThread.Run(() => { SceneEffectInfo.theWorldEffect.gameObject.SetActive(false); }); }); }