HunterGameView_LocalPK.cs 4.4 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. }
  56. }
  57. //游戏结束
  58. if (GameMgr.ins.gameOver) {
  59. this.transform.Find("CurrentPlayer").gameObject.SetActive(false);
  60. }
  61. }
  62. void InitRenderPlayerInfo_Local(int posNum, int roleID, int score)
  63. {
  64. (Sprite avatar, string nickName) = RoleMgr.GetRoleInfo(roleID);
  65. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  66. this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
  67. RenderScore(posNum, score);
  68. }
  69. void InitRenderPlayerInfo_Online(int posNum, int avatarID, string nickname, int score)
  70. {
  71. Sprite avatar = RoleMgr.GetAvatar(avatarID);
  72. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>().sprite = avatar;
  73. this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickname;
  74. RenderScore(posNum, score);
  75. }
  76. void RenderScore(int posNum, int score) {
  77. hitScores[posNum] = score;
  78. this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text = "得分: " + score.ToString();
  79. }
  80. public void ShowPlayerDie(bool[] playerDieList) {
  81. for (int i = 0; i < playerDieList.Length; i++) {
  82. if (playerDieList[i] && !dieList[i]) {
  83. dieList[i] = true;
  84. this.transform.Find("ScoreBox/Item" + i + "/IconDie").gameObject.SetActive(true);
  85. this.transform.Find("ScoreBox/Item" + i + "/MaskDie").gameObject.SetActive(true);
  86. }
  87. }
  88. }
  89. }