using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HunterGameView_LocalPK : MonoBehaviour { int[] hitScores = {0, 0}; int curPlayerIndex = -1; ChallengeGameModeLocalPK gameModeLocalPK; void Awake() { gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode; InitRenderPlayerInfo(0, GlobalData.localPK_playerRoleIDs[0], 0); InitRenderPlayerInfo(1, GlobalData.localPK_playerRoleIDs[1], 0); GameEventCenter.ins.onTargetAnimalHurt += (a, hurtValue) => { int playerIndex = gameModeLocalPK.GetCurrentPlayIndex(); hitScores[playerIndex] += hurtValue; RenderScore(playerIndex, hitScores[playerIndex]); }; } void Update() { if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) { curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex(); (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex]); 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); } if (GameMgr.ins.gameOver) { this.transform.Find("CurrentPlayer").gameObject.SetActive(false); } } void InitRenderPlayerInfo(int posNum, int playerID, int score) { (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(playerID); 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) { this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent().text = "得分: " + score.ToString(); } public void ShowPlayerDie(int playerIndex) { this.transform.Find("ScoreBox/Item" + playerIndex + "/IconDie").gameObject.SetActive(true); this.transform.Find("ScoreBox/Item" + playerIndex + "/MaskDie").gameObject.SetActive(true); } }