| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<Image>().sprite = avatar;
- this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
- } else {
- //索引相同,则渲染对应的玩家时间
- (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime();
- this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = t / tMax;
- this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().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<Image>().sprite = avatar;
- this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
- RenderScore(posNum, score);
- }
- void RenderScore(int posNum, int score) {
- this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().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);
- }
- }
|