using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HunterGameView : MonoBehaviour { ChallengeGameMode gameMode; WolfHuntGameMode gameMode1; void Start() { gameMode = (ChallengeGameMode) GameMgr.ins.gameMode; if (GameMgr.gameType == 5) { gameMode1 = (WolfHuntGameMode) gameMode; this.transform.Find("CountBgArrows").gameObject.SetActive(false); this.transform.Find("TimeBG").gameObject.SetActive(false); } else { this.transform.Find("HpBase").gameObject.SetActive(false); } } void FixedUpdate() { RenderAnimalCount(); if (GameMgr.gameType == 5) { RenderHP(); } else { RenderArrowCount(); RenderTime(); } if (GameMgr.ins.gameOver) { Destroy(this.gameObject); } } string[] animalNames = {"野兔", "野鸡", "野狼"}; [SerializeField] Text animalCountValue; [SerializeField] Text animalCountText; [SerializeField] Image animalCountProgress; void RenderAnimalCount() { string animalName = animalNames[gameMode.animalTypeID]; animalCountValue.text = gameMode.animalCount.ToString(); animalCountText.text = $"剩余{animalName}: {gameMode.animalCount}/{gameMode.animalCountMax}"; animalCountProgress.fillAmount = (float)gameMode.animalCount / gameMode.animalCountMax; } [SerializeField] Text arrowCountValue; [SerializeField] Text arrowCountText; [SerializeField] Image arrowCountProgress; void RenderArrowCount() { arrowCountValue.text = gameMode.arrowCount.ToString(); arrowCountText.text = $"剩余箭矢: {gameMode.arrowCount}/{gameMode.arrowCountMax}"; arrowCountProgress.fillAmount = (float)gameMode.arrowCount / gameMode.arrowCountMax; } [SerializeField] Text timeText; int lastRenderTime = -1; void RenderTime() { int curTime = Mathf.CeilToInt(gameMode.time); if (curTime != lastRenderTime) { lastRenderTime = curTime; timeText.text = GetTimeStr(curTime); } } string GetTimeStr(int second) { string str = ""; int m = second / 60; if (m < 10) { str += 0; } str += m; str += " : "; int s = second % 60; if (s < 10) { str += 0; } str += s; return str; } [SerializeField] GameObject hpUI; [SerializeField] Image hpBar; [SerializeField] Text hpText; void RenderHP() { hpBar.fillAmount = Mathf.Lerp(hpBar.fillAmount, (float) gameMode1.hp / gameMode1.hpMax, Time.deltaTime * 6); hpText.text = $"{gameMode1.hp}/{gameMode1.hpMax}"; } }