HunterGameView_LocalPK.cs 4.6 KB

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