using System.Collections; using System.Collections.Generic; using System.Net.Mime; using UnityEngine; using UnityEngine.UI; public class Islandpanel : MonoBehaviour { public Text gold; public Text introtext; public Text islandname; public Text InvesttotalText; public Button UpButton; public Button DownButton; public Button TouruButton; public Text tourutext; private int count=0; public Text TimeText; private float lastCallTime = 0f; private float interval = 1f; // 每秒调用一次 public Image Dao; float remainingTime = 0f; public CertificatePanel Certificate; public Sprite[] dao; public Button zhengshu; private async void OnEnable() { AuctionResponse response = await Scene_main_jiekou.instance.Auctioninformations(); //IslandResponse jinpairesponse = await Scene_main_jiekou.instance.Island(count); gold.text = response.Data.gold.ToString(); introtext.text = response.Data.intro_text; InvesttotalText.text = response.Data.invest_total.ToString(); remainingTime = response.Data.countdown; if (response.Data.island_id == 0) { Dao.gameObject.SetActive(false); islandname.gameObject.SetActive(false); } zhengshu.onClick.AddListener(async () => { Certificate.response = await Scene_main_jiekou.instance.AuctionCertificate(); }); islandname.text = response.Data.island_name; UpdateCountdownText(remainingTime); Dao.sprite = dao[response.Data.island_id]; Certificate.response = await Scene_main_jiekou.instance.AuctionCertificate(); } async void Start() { UpButton.onClick.AddListener(() => { count += 1; tourutext.text= count.ToString(); }); DownButton.onClick.AddListener(() => { if(count<=0) return; count -= 1; tourutext.text = count.ToString(); }); TouruButton.onClick.AddListener(() => { Toutu(count); }); if (remainingTime == 0) { } } async void Toutu(int count1) { IslandResponse jinpairesponse = await Scene_main_jiekou.instance.Island(count1); if (jinpairesponse.code == 200) { gold.text = jinpairesponse.Data.balance.ToString(); InvesttotalText.text = jinpairesponse.Data.invest_total.ToString(); count = 0; tourutext.text = count.ToString(); Promptmgr.Instance.PromptBubble(jinpairesponse.message); } else { Promptmgr.Instance.PromptBubble(jinpairesponse.message); } } // Update is called once per frame void UpdateCountdownText(float remainingTime) { // 将剩余时间转换为小时、分钟和秒 int hours = Mathf.FloorToInt(remainingTime / 3600); int minutes = Mathf.FloorToInt((remainingTime % 3600) / 60); int seconds = Mathf.FloorToInt(remainingTime % 60); // 使用格式化字符串显示倒计时(00:00:00) TimeText.text = string.Format("{0:D2}:{1:D2}:{2:D2}", hours, minutes, seconds); } private void Update() { if (Time.time - lastCallTime >= interval) { // 每秒调用一次的代码 if (remainingTime > 0) { remainingTime -= 1; UpdateCountdownText(remainingTime); Debug.Log("进入倒计时"); } // 更新上次调用时间 lastCallTime = Time.time; } } }