HunterGameView.cs 3.7 KB

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