HunterGameView_LocalPK.cs 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. bool[] dieList = {false, false};
  9. int curPlayerIndex = -1;
  10. ChallengeGameModeLocalPK gameModeLocalPK;
  11. HunterGamePlayerScoreCounter scoreCounter;
  12. void Awake() {
  13. gameModeLocalPK = (ChallengeGameModeLocalPK) GameMgr.ins.gameMode;
  14. scoreCounter = gameModeLocalPK.getHunterGamePlayerScoreCounter();
  15. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  16. InitRenderPlayerInfo_Local(0, GlobalData.localPK_playerRoleIDs[0], 0);
  17. InitRenderPlayerInfo_Local(1, GlobalData.localPK_playerRoleIDs[1], 0);
  18. } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  19. MatchPlayerInfo info0 = GlobalData.matchPlayerInfos[0];
  20. MatchPlayerInfo info1 = GlobalData.matchPlayerInfos[1];
  21. InitRenderPlayerInfo_Online(0, info0.avatarID, info0.nickname, 0);
  22. InitRenderPlayerInfo_Online(1, info1.avatarID, info1.nickname, 0);
  23. }
  24. }
  25. void Update() {
  26. if (gameModeLocalPK.GetCurrentPlayIndex() != curPlayerIndex) {
  27. curPlayerIndex = gameModeLocalPK.GetCurrentPlayIndex();
  28. (Sprite avatar, string nickName) = (null, null);
  29. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  30. (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.localPK_playerRoleIDs[curPlayerIndex]);
  31. } else if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  32. (avatar, nickName) = RoleMgr.GetRoleInfo(GlobalData.matchPlayerInfos[curPlayerIndex].avatarID);
  33. nickName = GlobalData.matchPlayerInfos[curPlayerIndex].nickname;
  34. }
  35. this.transform.Find("CurrentPlayer/Avatar").GetComponent<Image>().sprite = avatar;
  36. this.transform.Find("CurrentPlayer/Name").GetComponent<Text>().text = nickName;
  37. } else {
  38. //索引相同,则渲染对应的玩家时间
  39. (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime();
  40. this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = t / tMax;
  41. this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().text = TimeUtil.GetTimeStr(t);
  42. }
  43. //渲染得分
  44. for (int i = 0; i < 2; i++) {
  45. if (hitScores[i] != scoreCounter.hitScores[i]) {
  46. RenderScore(i, scoreCounter.hitScores[i]);
  47. }
  48. }
  49. //渲染死亡
  50. if (ChallengeGameMode.IsChallengeWolf()) {
  51. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  52. ShowPlayerDie(((WolfHuntGameMode_LocalPK)gameModeLocalPK).playerDieList);
  53. }
  54. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  55. ShowPlayerDie(((WolfHuntGameMode_OnlinePK)gameModeLocalPK).playerDieList);
  56. }
  57. }
  58. //游戏结束
  59. if (GameMgr.ins.gameOver) {
  60. this.transform.Find("CurrentPlayer").gameObject.SetActive(false);
  61. }
  62. }
  63. void InitRenderPlayerInfo_Local(int posNum, int roleID, int score)
  64. {
  65. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(roleID);
  66. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  67. this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
  68. RenderScore(posNum, score);
  69. }
  70. void InitRenderPlayerInfo_Online(int posNum, int avatarID, string nickname, int score)
  71. {
  72. Sprite avatar = RoleMgr.GetAvatar(avatarID);
  73. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  74. this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickname;
  75. RenderScore(posNum, score);
  76. }
  77. void RenderScore(int posNum, int score) {
  78. hitScores[posNum] = score;
  79. this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text = "得分: " + score.ToString();
  80. }
  81. public void ShowPlayerDie(bool[] playerDieList) {
  82. for (int i = 0; i < playerDieList.Length; i++) {
  83. if (playerDieList[i] && !dieList[i]) {
  84. dieList[i] = true;
  85. this.transform.Find("ScoreBox/Item" + i + "/IconDie").gameObject.SetActive(true);
  86. this.transform.Find("ScoreBox/Item" + i + "/MaskDie").gameObject.SetActive(true);
  87. }
  88. }
  89. }
  90. }