HunterGameView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan) {
  53. animalCountText.fontSize = 18;
  54. }
  55. animalCountProgress.fillAmount = (float)gameMode.animalCount / gameMode.animalCountMax;
  56. }
  57. [SerializeField] Text arrowCountValue;
  58. [SerializeField] Text arrowCountText;
  59. [SerializeField] Image arrowCountProgress;
  60. string str_surplus_arrow = null;
  61. void RenderArrowCount() {
  62. if (str_surplus_arrow == null) {
  63. str_surplus_arrow = TextAutoLanguage2.GetTextByKey("game_challenge_surplus_arrow");
  64. }
  65. arrowCountValue.text = gameMode.arrowCount.ToString();
  66. arrowCountText.text = $"{str_surplus_arrow}: {gameMode.arrowCount}/{gameMode.arrowCountMax}";
  67. arrowCountProgress.fillAmount = (float)gameMode.arrowCount / gameMode.arrowCountMax;
  68. }
  69. [SerializeField] Text timeText;
  70. int lastRenderTime = -1;
  71. void RenderTime() {
  72. int curTime = Mathf.CeilToInt(gameMode.time);
  73. if (curTime != lastRenderTime) {
  74. lastRenderTime = curTime;
  75. timeText.text = GetTimeStr(curTime);
  76. }
  77. }
  78. string GetTimeStr(int second) {
  79. string str = "";
  80. int m = second / 60;
  81. if (m < 10) {
  82. str += 0;
  83. }
  84. str += m;
  85. str += " : ";
  86. int s = second % 60;
  87. if (s < 10)
  88. {
  89. str += 0;
  90. }
  91. str += s;
  92. return str;
  93. }
  94. [SerializeField] GameObject hpUI;
  95. [SerializeField] Image hpBar;
  96. [SerializeField] Text hpText;
  97. void RenderHP() {
  98. hpBar.fillAmount = Mathf.Lerp(hpBar.fillAmount, (float) gameMode1.hp / gameMode1.hpMax, Time.deltaTime * 6);
  99. hpText.text = $"HP {gameMode1.hp}/{gameMode1.hpMax}";
  100. }
  101. public void RenderHPImmediate() {
  102. try {
  103. hpBar.fillAmount = (float) gameMode1.hp / gameMode1.hpMax;
  104. hpText.text = $"HP {gameMode1.hp}/{gameMode1.hpMax}";
  105. } catch (System.Exception) {}
  106. }
  107. }