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.nickname, 0); InitRenderPlayerInfo_Online(1, info1.avatarID, info1.nickname, 0); } } void Update() { if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) { curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex(); (Sprite avatar, string nickName) = (null, null); if (GlobalData.pkMatchType == PKMatchType.LocalPK) { (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex]); } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) { (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID); nickName = GlobalData.matchPlayerInfos[curPlayerIndex].nickname; } this.transform.Find("CurrentPlayer/Avatar").GetComponent().sprite = avatar; this.transform.Find("CurrentPlayer/Name").GetComponent().text = 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) { (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(roleID); this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent().sprite = avatar; this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent().text = nickName; RenderScore(posNum, score); } void InitRenderPlayerInfo_Online(int posNum, int avatarID, string nickname, int score) { Sprite avatar = RoleMgr.GetAvatar(avatarID); this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent().sprite = avatar; this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent().text = 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); } } } }