115 lines
3.3 KiB
C#
115 lines
3.3 KiB
C#
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;
|
||
async void Start()
|
||
{
|
||
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);
|
||
}
|
||
islandname.text = response.Data.island_name;
|
||
UpdateCountdownText(remainingTime);
|
||
Dao.sprite = dao[response.Data.island_id];
|
||
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)
|
||
{
|
||
Certificate.response = await Scene_main_jiekou.instance.AuctionCertificate();
|
||
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
}
|