Cute_demon_attacks/meng_yao/Assets/script/scene_Main/AssetsPanel.cs
2024-12-30 16:47:34 +08:00

106 lines
2.3 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 Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class AssetsPanel : MonoBehaviour
{
[Header("按钮,记得对应关系")]
public Button but1;
public Button but2;
public Button but3;
public Button but4;
[Header("按下按钮显示的panel目前是同一个")]
public GameObject mygameObject;
public bool is_one = false;
public Text Stone;
public Text Coin;
public Text Ore;
public Text Forging;
private bool isUpdating=false;
// Start is called before the first frame update
private void Awake()
{
}
void Start()
{
UpDateText();
if (but1 != null)
{
but1.onClick.AddListener(() =>
{
mygameObject.GetComponent<Asset_Details>().ShowPanel(2);
});
}
if (but2 != null)
{
but2.onClick.AddListener(() => {
mygameObject.GetComponent<Asset_Details>().ShowPanel(1);
});
}
if (but3 != null)
{
but3.onClick.AddListener(() => {
mygameObject.GetComponent<Asset_Details>().ShowPanel(4);
});
}
if (but4 != null)
{
but4.onClick.AddListener(() => {
mygameObject.GetComponent<Asset_Details>().ShowPanel(3);
});
}
InvokeRepeating("UpDateText", 1f,1f);
}
private void UpDateText()
{
// 如果正在执行异步操作,直接返回,不进行重复调用
if (isUpdating)
return;
UpdateTaxt();
}
async void UpdateTaxt()
{
isUpdating = true;
CapitalbalanceIndefo CapitalbalanceData = await Scene_main_jiekou.instance.CapitalbalanceInfos();
Stone.text = CapitalbalanceData.data.gem.ToString("F2");
Coin.text = CapitalbalanceData.data.gold.ToString("F2");
Ore.text = CapitalbalanceData.data.water.ToString("F2");
Forging.text = CapitalbalanceData.data.forge.ToString("F2");
CapitalbalanceData = null;
// 异步操作完成,标记为未执行
isUpdating = false;
}
private void OnEnable()
{
InvokeRepeating("UpDateText", 1f, 1f);
}
private void OnDisable()
{
CancelInvoke("UpDateText");
}
}