using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /* 动物关卡游戏界面-本地双人 */ public class HunterGameView_LocalPK : MonoBehaviour { int[] hitScores = {0, 0}; bool[] dieList = {false, false}; int curPlayerIndex = -1; ChallengeGameModeLocalPK gameModeLocalPK; HunterGamePlayerScoreCounter scoreCounter; void Awake() { gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode; scoreCounter = gameModeLocalPK.getHunterGamePlayerScoreCounter(); if (GlobalData.pkMatchType == PKMatchType.LocalPK) { InitRenderPlayerInfo_Local(0, GlobalData.localPK_playerRoleIDs[0], 0); InitRenderPlayerInfo_Local(1, GlobalData.localPK_playerRoleIDs[1], 0); } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) { MatchPlayerInfo info0 = GlobalData.matchPlayerInfos[0]; MatchPlayerInfo info1 = GlobalData.matchPlayerInfos[1]; InitRenderPlayerInfo_Online(0, info0.avatarID, info0.avatarUrl, info0.nickname, 0); InitRenderPlayerInfo_Online(1, info1.avatarID, info1.avatarUrl, info1.nickname, 0); } } void Update() { if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) { curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex(); string nickName = null; Image avatarImage = this.transform.Find("CurrentPlayer/Avatar").GetComponent(); if (GlobalData.pkMatchType == PKMatchType.LocalPK) { nickName = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex], avatarImage); } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) { int avatarID = GlobalData.matchPlayerInfos[curPlayerIndex].avatarID; string avatarUrl = GlobalData.matchPlayerInfos[curPlayerIndex].avatarUrl; RoleMgr.SetAvatarToImage(avatarImage, avatarID, avatarUrl); nickName = GlobalData.matchPlayerInfos[curPlayerIndex].nickname; } //this.transform.Find("CurrentPlayer/Name").GetComponent().text = nickName; TextEllipsis.SetTextWithEllipsis(transform.Find("CurrentPlayer/Name").GetComponent(), nickName); } else { //索引相同,则渲染对应的玩家时间 (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime(); this.transform.Find("CurrentPlayer/Progress").GetComponent().fillAmount = t / tMax; this.transform.Find("CurrentPlayer/Time").GetComponent().text = TimeUtil.GetTimeStr(t); } //渲染得分 for (int i = 0; i < 2; i++) { if (hitScores[i] != scoreCounter.hitScores[i]) { RenderScore(i, scoreCounter.hitScores[i]); } } //渲染死亡 if (ChallengeGameMode.IsChallengeWolf()) { if (GlobalData.pkMatchType == PKMatchType.LocalPK) { ShowPlayerDie(((WolfHuntGameMode_LocalPK)gameModeLocalPK).playerDieList); } if (GlobalData.pkMatchType == PKMatchType.OnlinePK) { ShowPlayerDie(((WolfHuntGameMode_OnlinePK)gameModeLocalPK).playerDieList); } } //游戏结束 if (GameMgr.ins.gameOver) { this.transform.Find("CurrentPlayer").gameObject.SetActive(false); } } void InitRenderPlayerInfo_Local(int posNum, int roleID, int score) { string nickName = RoleMgr.GetRoleInfo(roleID, this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent()); //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent().text = nickName; TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent(), nickName); RenderScore(posNum, score); } void InitRenderPlayerInfo_Online(int posNum, int avatarID, string avatarUrl, string nickname, int score) { RoleMgr.SetAvatarToImage( this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent(), avatarID, avatarUrl ); //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent().text = nickname; TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent(), nickname); RenderScore(posNum, score); } void RenderScore(int posNum, int score) { hitScores[posNum] = score; this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent().text = System.String.Format(TextAutoLanguage2.GetTextByKey("game_challenge_pk_score"), score); } public void ShowPlayerDie(bool[] playerDieList) { for (int i = 0; i < playerDieList.Length; i++) { if (playerDieList[i] && !dieList[i]) { dieList[i] = true; this.transform.Find("ScoreBox/Item" + i + "/IconDie").gameObject.SetActive(true); this.transform.Find("ScoreBox/Item" + i + "/MaskDie").gameObject.SetActive(true); } } } }