HunterGameView.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 动物关卡游戏界面 */
  6. public class HunterGameView : MonoBehaviour
  7. {
  8. ChallengeGameMode gameMode;
  9. WolfHuntGameMode gameMode1;
  10. void Start()
  11. {
  12. gameMode = (ChallengeGameMode) GameMgr.ins.gameMode;
  13. if (ChallengeGameMode.IsChallengeWolf()) {
  14. gameMode1 = (WolfHuntGameMode) gameMode;
  15. this.transform.Find("CountBgArrows").gameObject.SetActive(false);
  16. this.transform.Find("TimeBG").gameObject.SetActive(false);
  17. } else {
  18. this.transform.Find("HpBase").gameObject.SetActive(false);
  19. }
  20. if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) {
  21. this.transform.Find("TimeBG").gameObject.SetActive(false);
  22. }
  23. }
  24. void FixedUpdate()
  25. {
  26. RenderAnimalCount();
  27. if (ChallengeGameMode.IsChallengeWolf()) {
  28. RenderHP();
  29. } else {
  30. RenderArrowCount();
  31. RenderTime();
  32. }
  33. if (GameMgr.ins.gameOver) {
  34. Destroy(this.gameObject);
  35. }
  36. }
  37. string[] animalNames = null;
  38. [SerializeField] Text animalCountValue;
  39. [SerializeField] Text animalCountText;
  40. [SerializeField] Image animalCountProgress;
  41. void RenderAnimalCount() {
  42. if (animalNames == null) {
  43. animalNames = new string[]{
  44. TextAutoLanguage2.GetTextByKey("game_challenge_surplus_rabbit"),
  45. TextAutoLanguage2.GetTextByKey("game_challenge_surplus_pheasant"),
  46. TextAutoLanguage2.GetTextByKey("game_challenge_surplus_wolf")
  47. };
  48. }
  49. string animalName = animalNames[gameMode.animalTypeID];
  50. animalCountValue.text = gameMode.animalCount.ToString();
  51. animalCountText.text = $"{animalName}: {gameMode.animalCount}/{gameMode.animalCountMax}";
  52. animalCountProgress.fillAmount = (float)gameMode.animalCount / gameMode.animalCountMax;
  53. }
  54. [SerializeField] Text arrowCountValue;
  55. [SerializeField] Text arrowCountText;
  56. [SerializeField] Image arrowCountProgress;
  57. string str_surplus_arrow = null;
  58. void RenderArrowCount() {
  59. if (str_surplus_arrow == null) {
  60. str_surplus_arrow = TextAutoLanguage2.GetTextByKey("game_challenge_surplus_arrow");
  61. }
  62. arrowCountValue.text = gameMode.arrowCount.ToString();
  63. arrowCountText.text = $"{str_surplus_arrow}: {gameMode.arrowCount}/{gameMode.arrowCountMax}";
  64. arrowCountProgress.fillAmount = (float)gameMode.arrowCount / gameMode.arrowCountMax;
  65. }
  66. [SerializeField] Text timeText;
  67. int lastRenderTime = -1;
  68. void RenderTime() {
  69. int curTime = Mathf.CeilToInt(gameMode.time);
  70. if (curTime != lastRenderTime) {
  71. lastRenderTime = curTime;
  72. timeText.text = GetTimeStr(curTime);
  73. }
  74. }
  75. string GetTimeStr(int second) {
  76. string str = "";
  77. int m = second / 60;
  78. if (m < 10) {
  79. str += 0;
  80. }
  81. str += m;
  82. str += " : ";
  83. int s = second % 60;
  84. if (s < 10)
  85. {
  86. str += 0;
  87. }
  88. str += s;
  89. return str;
  90. }
  91. [SerializeField] GameObject hpUI;
  92. [SerializeField] Image hpBar;
  93. [SerializeField] Text hpText;
  94. void RenderHP() {
  95. hpBar.fillAmount = Mathf.Lerp(hpBar.fillAmount, (float) gameMode1.hp / gameMode1.hpMax, Time.deltaTime * 6);
  96. hpText.text = $"HP {gameMode1.hp}/{gameMode1.hpMax}";
  97. }
  98. public void RenderHPImmediate() {
  99. try {
  100. hpBar.fillAmount = (float) gameMode1.hp / gameMode1.hpMax;
  101. hpText.text = $"HP {gameMode1.hp}/{gameMode1.hpMax}";
  102. } catch (System.Exception) {}
  103. }
  104. }