HunterGameView_LocalPK.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. TextEllipsis.SetTextWithEllipsis(transform.Find("CurrentPlayer/Name").GetComponent<Text>(), nickName);
  41. } else {
  42. //索引相同,则渲染对应的玩家时间
  43. (float t, float tMax) = gameModeLocalPK.GetSingleShootReadyTime();
  44. this.transform.Find("CurrentPlayer/Progress").GetComponent<Image>().fillAmount = t / tMax;
  45. this.transform.Find("CurrentPlayer/Time").GetComponent<Text>().text = TimeUtil.GetTimeStr(t);
  46. }
  47. //渲染得分
  48. for (int i = 0; i < 2; i++) {
  49. if (hitScores[i] != scoreCounter.hitScores[i]) {
  50. RenderScore(i, scoreCounter.hitScores[i]);
  51. }
  52. }
  53. //渲染死亡
  54. if (ChallengeGameMode.IsChallengeWolf()) {
  55. if (GlobalData.pkMatchType == PKMatchType.LocalPK) {
  56. ShowPlayerDie(((WolfHuntGameMode_LocalPK)gameModeLocalPK).playerDieList);
  57. }
  58. if (GlobalData.pkMatchType == PKMatchType.OnlinePK) {
  59. ShowPlayerDie(((WolfHuntGameMode_OnlinePK)gameModeLocalPK).playerDieList);
  60. }
  61. }
  62. //游戏结束
  63. if (GameMgr.ins.gameOver) {
  64. this.transform.Find("CurrentPlayer").gameObject.SetActive(false);
  65. }
  66. }
  67. void InitRenderPlayerInfo_Local(int posNum, int roleID, int score)
  68. {
  69. string nickName = RoleMgr.GetRoleInfo(roleID,
  70. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>());
  71. //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickName;
  72. TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>(), nickName);
  73. RenderScore(posNum, score);
  74. }
  75. void InitRenderPlayerInfo_Online(int posNum, int avatarID, string avatarUrl, string nickname, int score)
  76. {
  77. RoleMgr.SetAvatarToImage(
  78. this.transform.Find("ScoreBox/Item" + posNum + "/Avatar/Sprite").GetComponent<Image>(),
  79. avatarID, avatarUrl
  80. );
  81. //this.transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>().text = nickname;
  82. TextEllipsis.SetTextWithEllipsis(transform.Find("ScoreBox/Item" + posNum + "/Name").GetComponent<Text>(), nickname);
  83. RenderScore(posNum, score);
  84. }
  85. void RenderScore(int posNum, int score) {
  86. hitScores[posNum] = score;
  87. this.transform.Find("ScoreBox/Item" + posNum + "/Score").GetComponent<Text>().text =
  88. System.String.Format(TextAutoLanguage2.GetTextByKey("game_challenge_pk_score"), score);
  89. }
  90. public void ShowPlayerDie(bool[] playerDieList) {
  91. for (int i = 0; i < playerDieList.Length; i++) {
  92. if (playerDieList[i] && !dieList[i]) {
  93. dieList[i] = true;
  94. this.transform.Find("ScoreBox/Item" + i + "/IconDie").gameObject.SetActive(true);
  95. this.transform.Find("ScoreBox/Item" + i + "/MaskDie").gameObject.SetActive(true);
  96. }
  97. }
  98. }
  99. }