using DG.Tweening; using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading.Tasks; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class Base : MonoBehaviour { public Button retbutton; public GameObject ClosureObj; private void Awake() { if (retbutton != null) { retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj)); } } public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f)//按钮动画 { TaskCompletionSource tcs = new TaskCompletionSource(); Sequence mySequence = DOTween.Sequence(); mySequence.Append(button.transform.DOScale(max, 0.1f)) // 第一个动画 .Append(button.transform.DOScale(1f, 0.2f)).OnComplete(() => { // 动画播放完成后执行的代码 tcs.SetResult(true); }); // 第二个动画 await tcs.Task; } public void addEventPopUp(string Details)//添加弹窗 { GameObject prefab = Resources.Load("base/EventPopUp"); Canvas canvas = GetComponentInParent(); prefab.GetComponent().text = Details; Instantiate(prefab, canvas.transform); } logoPanel.ServerResponse TestserverResponse; protected Dictionary testhead; public async void testLogo()//测试登录 { LoginAndGetToken.loginbody body = new LoginAndGetToken.loginbody { userName = "15151658596", password = "123456", verifyCode = 111111 }; string loginResponse = await web.SendRequest(web.URL + "/snail/user/login", "POST", JsonUtility.ToJson(body)); logoPanel.ServerResponse response = JsonUtility.FromJson(loginResponse); if (response != null && response.code == 200 && response.data != null) { TestserverResponse = response; addEventPopUp("测试登录成功"); testhead = new Dictionary { { "Authorization", TestserverResponse.data.token } }; } addEventPopUp("测试登录失败"); testhead = new Dictionary(); } public bool IsGreaterThanZeroDecimal(string text)//判断必须为小数而且大于0 { // 使用正则表达式匹配大于0的小数 string pattern = @"^(?!0(\.0+)?$)(\d+(\.\d+)?|\.\d+)$"; Regex regex = new Regex(pattern); return regex.IsMatch(text); } public async void CancelOnClick(Button button,GameObject my_gameObject = null)//取消按钮 { await ButtonClickAnimationAsync(button.gameObject); if (my_gameObject != null) { Destroy(my_gameObject); return; } Destroy(gameObject); } }