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 coinsConvertVolut { public float voluteCoin; public int convertType; } public class coinsConvertBeans { 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 FixedUpdate() { if (mymode == mode.ShellToEgg) { Image1.sprite = shellSprite; Image2.sprite = eggSprite; } else { Image2.sprite = shellSprite; Image1.sprite = eggSprite; } } public async void ConfirmOnClick(Button button)//确定按钮 { await ButtonClickAnimationAsync(button.gameObject); if (IsGreaterThanZeroDecimal(inputField.text)) { coinsConvertVolut body = new coinsConvertVolut(); string send = ""; if (mymode == mode.ShellToEgg) send = "{\"convertType\":" + ((int)mymode).ToString() + ",\"voluteCoin\":" + inputField.text + "}"; else send = "{\"convertType\":" + ((int)mymode).ToString() + ",\"beansCoin\":" + inputField.text + "}"; body.convertType = (int)mymode; Debug.Log(send); //string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", send, testhead);//测试 string response = await web.SendRequest(web.URL + "/snail/user/coinsConvert", "POST", send, Global.global.CreateHeaders());//正式接入 Debug.Log("入参:"+ JsonUtility.ToJson(body) + " 1.8返回: " + response); ServerResponse18 serverResponse = JsonConvert.DeserializeObject(response); if (serverResponse.code != 200) { 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); } }