97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Game
|
|
{
|
|
[UIType(UIType.GameStorePurchaseUI)]
|
|
public class GameStorePurchaseUI : UIBase
|
|
{
|
|
private TMP_Text txtName;
|
|
private TMP_Text txtDesc;
|
|
private TMP_InputField inpNumber;
|
|
private Button btnAdd;
|
|
private Button btnRemove;
|
|
private Button btnBuy;
|
|
|
|
private int number;
|
|
private int count;
|
|
private bool isBuyFinish;
|
|
|
|
public override void Init()
|
|
{
|
|
base.Init();
|
|
txtName = self.transform.FindChildDeep<TMP_Text>("txtName");
|
|
txtDesc = self.transform.FindChildDeep<TMP_Text>("txtDesc");
|
|
inpNumber = self.transform.FindChildDeep<TMP_InputField>("inpNumber");
|
|
btnAdd = self.transform.FindChildDeep<Button>("btnAdd");
|
|
btnRemove = self.transform.FindChildDeep<Button>("btnRemove");
|
|
btnBuy = self.transform.FindChildDeep<Button>("btnBuy");
|
|
|
|
number = 0;
|
|
this.inpNumber.text = "0";
|
|
isBuyFinish = false;
|
|
this.count = 0;
|
|
|
|
this.btnAdd.onClick.AddListener(ClickAddNumber);
|
|
this.btnRemove.onClick.AddListener(ClickRemoveNumber);
|
|
this.btnBuy.onClick.AddListener(ClickBuy);
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
this.btnAdd.onClick.RemoveListener(ClickAddNumber);
|
|
this.btnRemove.onClick.RemoveListener(ClickRemoveNumber);
|
|
this.btnBuy.onClick.RemoveListener(ClickBuy);
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
base.Close();
|
|
isBuyFinish = false;
|
|
this.count = 0;
|
|
this.inpNumber.text = "0";
|
|
this.number = 0;
|
|
}
|
|
|
|
private void ClickBuy()
|
|
{
|
|
Debug.Log($"number is {this.number}");
|
|
// TODO:
|
|
isBuyFinish = true;
|
|
}
|
|
|
|
private void ClickRemoveNumber()
|
|
{
|
|
if (this.number == 0) return;
|
|
this.number--;
|
|
this.inpNumber.text = number.ToString();
|
|
}
|
|
|
|
private void ClickAddNumber()
|
|
{
|
|
if (this.number == this.count) return;
|
|
this.number++;
|
|
this.inpNumber.text = number.ToString();
|
|
}
|
|
|
|
public async UniTask<int> WaitBuyFinish(string name, string desc, float price, int count)
|
|
{
|
|
this.txtName.text = name;
|
|
this.txtDesc.text = desc;
|
|
this.number = 0;
|
|
this.count = count;
|
|
|
|
while (!isBuyFinish)
|
|
{
|
|
await UniTask.Yield();
|
|
}
|
|
|
|
int num = this.number;
|
|
Game.uiManager.CloseLast();
|
|
return num;
|
|
}
|
|
}
|
|
} |