HunterGameView_LocalPK.cs 4.7 KB

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