Cute_demon_attacks/meng_yao/Assets/script/Panel/Islandpanel.cs
2025-01-06 16:53:51 +08:00

126 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}