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; using Newtonsoft.Json; public class ConversionItem : BaseUIPanel { public TMP_InputField inputField; public TextMeshProUGUI TextMeshProUGUI; public Button button1; public Button button2; public Image Image1; public Image Image2; public Sprite shellSprite; public Sprite eggSprite; public mode mymode = mode.ShellToEgg; public class coinsConvert { public float voluteCoin; public float beansCoin; public int convertType; } private async void Start() { inputField.onValueChanged.AddListener(GetInputData); button1.onClick.AddListener(() => CancelOnClick(button1)); button2.onClick.AddListener(() => ConfirmOnClick(button2)); TextMeshProUGUI.text = "0"; //testhead = await testLogo();//测试登录 } public enum mode { ShellToEgg = 0,//蜗壳转蜗蛋 EggToShell = 1//蜗蛋转蜗壳 } private void Update() { if (mymode == mode.ShellToEgg) { Image1.sprite = shellSprite; Image2.sprite = eggSprite; } else { Image2.sprite = shellSprite; Image1.sprite = eggSprite; } } public async void CancelOnClick(Button button)//取消按钮 { await ButtonClickAnimationAsync(button.gameObject); Destroy(gameObject); } public async void ConfirmOnClick(Button button)//确定按钮 { await ButtonClickAnimationAsync(button.gameObject); if (IsGreaterThanZeroDecimal(inputField.text)) { coinsConvert body = new coinsConvert(); if (mymode == mode.ShellToEgg) { body.voluteCoin = float.Parse(inputField.text); body.beansCoin = float.Parse(TextMeshProUGUI.text); } else { body.voluteCoin = float.Parse(TextMeshProUGUI.text); body.beansCoin = float.Parse(inputField.text); } body.convertType = (int)mymode; //string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", JsonUtility.ToJson(body), testhead);//测试 string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());//正式接入 Debug.Log("入参:"+ JsonUtility.ToJson(body) + " 1.8返回: " + response); ServerResponse18 serverResponse = JsonConvert.DeserializeObject(response); addEventPopUp(serverResponse.message); Destroy(gameObject); } else { addEventPopUp("请输入正确的数量"); } } public void GetInputData(string userInput) { if (string.IsNullOrWhiteSpace(userInput) || !IsGreaterThanZeroDecimal(inputField.text)) { userInput = "0"; } TextMeshProUGUI.text = "0"; if (mymode == mode.ShellToEgg) TextMeshProUGUI.text = (float.Parse(userInput) * 3).ToString("F2"); if (mymode == mode.EggToShell) TextMeshProUGUI.text = (float.Parse(userInput) / 3).ToString("F2"); ButtonClickAnimationAsync(TextMeshProUGUI.gameObject); } }