HunterGameView.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 (GameMgr.gameType == 5) {
  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. }
  20. void FixedUpdate()
  21. {
  22. RenderAnimalCount();
  23. if (GameMgr.gameType == 5) {
  24. RenderHP();
  25. } else {
  26. RenderArrowCount();
  27. RenderTime();
  28. }
  29. if (GameMgr.ins.gameOver) {
  30. Destroy(this.gameObject);
  31. }
  32. }
  33. string[] animalNames = {"野兔", "野鸡", "野狼"};
  34. [SerializeField] Text animalCountValue;
  35. [SerializeField] Text animalCountText;
  36. [SerializeField] Image animalCountProgress;
  37. void RenderAnimalCount() {
  38. string animalName = animalNames[gameMode.animalTypeID];
  39. animalCountValue.text = gameMode.animalCount.ToString();
  40. animalCountText.text = $"剩余{animalName}: {gameMode.animalCount}/{gameMode.animalCountMax}";
  41. animalCountProgress.fillAmount = (float)gameMode.animalCount / gameMode.animalCountMax;
  42. }
  43. [SerializeField] Text arrowCountValue;
  44. [SerializeField] Text arrowCountText;
  45. [SerializeField] Image arrowCountProgress;
  46. void RenderArrowCount() {
  47. arrowCountValue.text = gameMode.arrowCount.ToString();
  48. arrowCountText.text = $"剩余箭矢: {gameMode.arrowCount}/{gameMode.arrowCountMax}";
  49. arrowCountProgress.fillAmount = (float)gameMode.arrowCount / gameMode.arrowCountMax;
  50. }
  51. [SerializeField] Text timeText;
  52. int lastRenderTime = -1;
  53. void RenderTime() {
  54. int curTime = Mathf.CeilToInt(gameMode.time);
  55. if (curTime != lastRenderTime) {
  56. lastRenderTime = curTime;
  57. timeText.text = GetTimeStr(curTime);
  58. }
  59. }
  60. string GetTimeStr(int second) {
  61. string str = "";
  62. int m = second / 60;
  63. if (m < 10) {
  64. str += 0;
  65. }
  66. str += m;
  67. str += " : ";
  68. int s = second % 60;
  69. if (s < 10)
  70. {
  71. str += 0;
  72. }
  73. str += s;
  74. return str;
  75. }
  76. [SerializeField] GameObject hpUI;
  77. [SerializeField] Image hpBar;
  78. [SerializeField] Text hpText;
  79. void RenderHP() {
  80. hpBar.fillAmount = Mathf.Lerp(hpBar.fillAmount, (float) gameMode1.hp / gameMode1.hpMax, Time.deltaTime * 6);
  81. hpText.text = $"{gameMode1.hp}/{gameMode1.hpMax}";
  82. }
  83. }