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 (ChallengeGameMode.IsChallengeWolf()) { 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); } if (GlobalData.pkMatchType == PKMatchType.None && UserSettings.ins.trainMode) { this.transform.Find("TimeBG").gameObject.SetActive(false); } } void FixedUpdate() { RenderAnimalCount(); if (ChallengeGameMode.IsChallengeWolf()) { RenderHP(); } else { RenderArrowCount(); RenderTime(); } if (GameMgr.ins.gameOver) { Destroy(this.gameObject); } } string[] animalNames = null; [SerializeField] Text animalCountValue; [SerializeField] Text animalCountText; [SerializeField] Image animalCountProgress; void RenderAnimalCount() { if (animalNames == null) { animalNames = new string[]{ TextAutoLanguage2.GetTextByKey("game_challenge_surplus_rabbit"), TextAutoLanguage2.GetTextByKey("game_challenge_surplus_pheasant"), TextAutoLanguage2.GetTextByKey("game_challenge_surplus_wolf") }; } string animalName = animalNames[gameMode.animalTypeID]; animalCountValue.text = gameMode.animalCount.ToString(); animalCountText.text = $"{animalName}: {gameMode.animalCount}/{gameMode.animalCountMax}"; if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan) { animalCountText.fontSize = 18; } animalCountProgress.fillAmount = (float)gameMode.animalCount / gameMode.animalCountMax; } [SerializeField] Text arrowCountValue; [SerializeField] Text arrowCountText; [SerializeField] Image arrowCountProgress; string str_surplus_arrow = null; void RenderArrowCount() { if (str_surplus_arrow == null) { str_surplus_arrow = TextAutoLanguage2.GetTextByKey("game_challenge_surplus_arrow"); } arrowCountValue.text = gameMode.arrowCount.ToString(); arrowCountText.text = $"{str_surplus_arrow}: {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 = $"HP {gameMode1.hp}/{gameMode1.hpMax}"; } public void RenderHPImmediate() { try { hpBar.fillAmount = (float) gameMode1.hp / gameMode1.hpMax; hpText.text = $"HP {gameMode1.hp}/{gameMode1.hpMax}"; } catch (System.Exception) {} } }