_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Conversion/ConversionItem.cs
2024-11-25 23:31:50 +08:00

55 lines
1.6 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Text.RegularExpressions;
public class ConversionItem : BaseUIPanel
{
public TMP_InputField inputField;
public TextMeshProUGUI TextMeshProUGUI;
public Button button1;
public Button button2;
public mode mymode = mode.ShellToEgg;
private void Start()
{
inputField.onValueChanged.AddListener(GetInputData);
button1.onClick.AddListener(() => CancelOnClick(button1));
button2.onClick.AddListener(() => ConfirmOnClick(button2));
TextMeshProUGUI.text = "0";
}
public enum mode
{
ShellToEgg,
EggToShell
}
public async void CancelOnClick(Button button)//È¡Ïû°´Å¥
{
await ButtonClickAnimationAsync(button.gameObject);
Destroy(gameObject);
}
public async void ConfirmOnClick(Button button)//È·¶¨°´Å¥
{
await ButtonClickAnimationAsync(button.gameObject);
Regex.IsMatch(inputField.text, @"^[1-9]\d*$");
addEventPopUp("²âÊÔµ¯´°");
}
public void GetInputData(string userInput)
{
if (string.IsNullOrWhiteSpace(userInput)) {
userInput = "0";
}
TextMeshProUGUI.text = "0";
if (mymode == mode.ShellToEgg)
TextMeshProUGUI.text = (int.Parse(userInput) * 3).ToString();
if (mymode == mode.EggToShell)
TextMeshProUGUI.text = (int.Parse(userInput) / 3).ToString();
ButtonClickAnimationAsync(TextMeshProUGUI.gameObject);
}
}