HunterGameView_LocalPK.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class HunterGameView_LocalPK : MonoBehaviour
  6. {
  7. int[] hitScores = {0, 0};
  8. int curPlayerIndex = -1;
  9. ChallengeGameModeLocalPK gameModeLocalPK;
  10. void Awake() {
  11. gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode;
  12. InitRenderPlayerInfo(0, GlobalData.localPK_playerRoleIDs[0], 0);
  13. InitRenderPlayerInfo(1, GlobalData.localPK_playerRoleIDs[1], 0);
  14. GameEventCenter.ins.onTargetAnimalHurt += (a, hurtValue) => {
  15. int playerIndex = gameModeLocalPK.GetCurrentPlayIndex();
  16. hitScores[playerIndex] += hurtValue;
  17. RenderScore(playerIndex, hitScores[playerIndex]);
  18. };
  19. }
  20. void Update() {
  21. if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) {
  22. curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex();
  23. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex]);
  24. this.transform.Find("CurrentPlayer/Avatar").GetComponent<Image>().sprite = avatar;
  25. this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
  26. } else {
  27. //索引相同,则渲染对应的玩家时间
  28. (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime();
  29. this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = t / tMax;
  30. this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().text = TimeUtil.GetTimeStr(t);
  31. }
  32. if (GameMgr.ins.gameOver) {
  33. this.transform.Find("CurrentPlayer").gameObject.SetActive(false);
  34. }
  35. }
  36. void InitRenderPlayerInfo(int posNum, int playerID, int score)
  37. {
  38. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(playerID);
  39. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  40. this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
  41. RenderScore(posNum, score);
  42. }
  43. void RenderScore(int posNum, int score) {
  44. this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text = "得分: " + score.ToString();
  45. }
  46. public void ShowPlayerDie(int playerIndex) {
  47. this.transform.Find("ScoreBox/Item" + playerIndex + "/IconDie").gameObject.SetActive(true);
  48. this.transform.Find("ScoreBox/Item" + playerIndex + "/MaskDie").gameObject.SetActive(true);
  49. }
  50. }