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