_TheStrongestSnail/TheStrongestSnail/Assets/common/base/base.cs

126 lines
3.9 KiB
C#
Raw Normal View History

2024-11-25 23:31:50 +08:00
using DG.Tweening;
2024-11-28 04:21:44 +08:00
using System;
2024-11-25 23:31:50 +08:00
using System.Collections.Generic;
2024-11-26 02:09:38 +08:00
using System.Text.RegularExpressions;
2024-11-25 23:31:50 +08:00
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
2024-11-28 08:35:07 +08:00
2024-11-25 23:31:50 +08:00
public class Base : MonoBehaviour
{
2024-11-28 04:25:21 +08:00
private List<string> LoadClassName = new List<string>() { "ImageLoader" , "Global" };//д<><D0B4><EFBFBD><EFBFBD>Ҫȫ<D2AA><C8AB><EFBFBD>Զ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-11-26 15:50:49 +08:00
public Button retbutton;
2024-11-26 16:40:57 +08:00
public GameObject ClosureObj;
2024-11-28 04:21:44 +08:00
public static GameObject GlobalObj;
2024-11-26 16:40:57 +08:00
private void Awake()
{
2024-11-28 08:35:07 +08:00
Application.targetFrameRate = Mathf.RoundToInt(100f); // <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>֡<EFBFBD><D6A1>
2024-11-28 04:21:44 +08:00
initializeGlobal();
2024-11-26 16:40:57 +08:00
if (retbutton != null)
{
retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj));
}
2024-11-28 04:21:44 +08:00
2024-11-26 16:40:57 +08:00
}
2024-11-28 04:21:44 +08:00
private void initializeGlobal()
{
if (GlobalObj == null)
{
GlobalObj = new GameObject("GlobalObj");
DontDestroyOnLoad(GlobalObj);
foreach (string className in LoadClassName) {
CallClassByString(className);
}
}
}
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>
public void CallClassByString(string className)
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> Type <20><><EFBFBD><EFBFBD>
Type type = Type.GetType(className);
if (type != null)
{
GlobalObj.AddComponent(type);
}
else
{
Console.WriteLine("Class not found.");
}
}
2024-11-26 18:14:09 +08:00
public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)//<2F><>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
2024-11-25 23:31:50 +08:00
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Sequence mySequence = DOTween.Sequence();
2024-11-26 18:14:09 +08:00
mySequence.Append(button.transform.DOScale(max, 0.1f* timemultiple)) // <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
.Append(button.transform.DOScale(1f, 0.2f* timemultiple)).OnComplete(() => {
2024-11-25 23:31:50 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD>ִ<EFBFBD>еĴ<D0B5><C4B4><EFBFBD>
tcs.SetResult(true);
}); // <20>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
await tcs.Task;
}
2024-11-26 18:19:49 +08:00
public void addEventPopUp(string Details,float time = 5f)//<2F><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>
2024-11-25 23:31:50 +08:00
{
GameObject prefab = Resources.Load<GameObject>("base/EventPopUp");
2024-11-26 18:19:49 +08:00
prefab.GetComponent<EventPopUp>().time = time;
2024-11-25 23:31:50 +08:00
Canvas canvas = GetComponentInParent<Canvas>();
prefab.GetComponent<EventPopUp>().text = Details;
Instantiate(prefab, canvas.transform);
}
2024-11-26 02:09:38 +08:00
logoPanel.ServerResponse TestserverResponse;
protected Dictionary<string, string> testhead;
2024-11-26 15:50:49 +08:00
public async void testLogo()//<2F><><EFBFBD>Ե<EFBFBD>¼
2024-11-26 02:09:38 +08:00
{
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<logoPanel.ServerResponse>(loginResponse);
if (response != null && response.code == 200 && response.data != null)
{
TestserverResponse = response;
addEventPopUp("<22><><EFBFBD>Ե<EFBFBD>¼<EFBFBD>ɹ<EFBFBD>");
2024-11-26 15:50:49 +08:00
testhead = new Dictionary<string, string>
2024-11-26 16:54:06 +08:00
{
{ "Authorization", TestserverResponse.data.token }
};
return;
2024-11-26 02:09:38 +08:00
}
2024-11-26 16:54:06 +08:00
addEventPopUp(response.message);
2024-11-26 15:50:49 +08:00
testhead = new Dictionary<string, string>();
2024-11-26 02:09:38 +08:00
}
2024-11-25 23:31:50 +08:00
2024-11-26 02:09:38 +08:00
public bool IsGreaterThanZeroDecimal(string text)//<2F>жϱ<D0B6><CFB1><EFBFBD>ΪС<CEAA><D0A1><EFBFBD><EFBFBD><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD>0
{
// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>С<EFBFBD><D0A1>
string pattern = @"^(?!0(\.0+)?$)(\d+(\.\d+)?|\.\d+)$";
Regex regex = new Regex(pattern);
return regex.IsMatch(text);
}
2024-11-26 16:40:57 +08:00
public async void CancelOnClick(Button button,GameObject my_gameObject = null)//ȡ<><C8A1><EFBFBD><EFBFBD>ť
2024-11-26 15:50:49 +08:00
{
await ButtonClickAnimationAsync(button.gameObject);
2024-11-26 16:40:57 +08:00
if (my_gameObject != null)
{
Destroy(my_gameObject);
return;
}
2024-11-26 15:50:49 +08:00
Destroy(gameObject);
}
2024-11-26 16:40:57 +08:00
2024-11-25 23:31:50 +08:00
}