修改base

This commit is contained in:
wulongxiao 2025-01-08 13:03:55 +08:00
parent fc5f538527
commit 078d33a649
2 changed files with 33 additions and 31 deletions

View File

@ -3,7 +3,7 @@ using UnityEngine;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
public class JsonReadBase : MonoBehaviour public class JsonReadBase : Base
{ {
/// <summary> /// <summary>
/// 通用的JSON加载和解析方法 /// 通用的JSON加载和解析方法

View File

@ -10,29 +10,31 @@ using UnityEngine.UI;
public class Base : MonoBehaviour public class Base : MonoBehaviour
{ {
private List<string> LoadClassName = new List<string>() { "ImageLoader" , "Global", "gameGlobal" };//写入需要全局自动实例化的类 [HideInInspector]
[Header("关闭窗口的按钮")] public Button retbutton; public string description = "";
[Header("需要关闭的窗口")] public GameObject ClosureObj; private List<string> LoadClassName = new List<string>() { "gameGlobal", "Mengyao_Skill_Date" };//写入需要全局自动实例化的类
// [Header("关闭窗口的按钮")] public Button retbutton;
// [Header("需要关闭的窗口")] public GameObject ClosureObj;
public static GameObject GlobalObj; public static GameObject GlobalObj;
/// <summary> /// <summary>
///初始化 ///初始化
/// </summary> /// </summary>
private void Awake() private void Awake()
{ {
if (Application.isPlaying) if (Application.isPlaying)
{ {
Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率 Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率
initializeGlobal(); initializeGlobal();
if (retbutton != null) // if (retbutton != null)
{ // {
retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj)); // retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj));
} // }
} }
} }
/// <summary> /// <summary>
/// 初始化全局类 /// 初始化全局类
/// </summary> /// </summary>
private void initializeGlobal() private void initializeGlobal()
{ {
@ -46,12 +48,12 @@ public class Base : MonoBehaviour
} }
} }
/// <summary> /// <summary>
/// 用于通过类名字符串动态调用类和方法 /// 用于通过类名字符串动态调用类和方法
/// </summary> /// </summary>
/// <param name="className"></param> /// <param name="className"></param>
public void CallClassByString(string className) public void CallClassByString(string className)
{ {
// 获取类的 Type 对象 // 获取类的 Type 对象
Type type = Type.GetType(className); Type type = Type.GetType(className);
if (type != null) if (type != null)
@ -65,29 +67,29 @@ public class Base : MonoBehaviour
} }
/// <summary> /// <summary>
/// 按钮动画,点击后会放大缩小 /// 按钮动画,点击后会放大缩小
/// </summary> /// </summary>
/// <param name="button">实施目标对象</param> /// <param name="button">实施目标对象</param>
/// <param name="max">放大倍率</param> /// <param name="max">放大倍率</param>
/// <param name="timemultiple">动画持续时间倍率</param> /// <param name="timemultiple">动画持续时间倍率</param>
/// <returns></returns> /// <returns></returns>
public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)//按钮动画 public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)//按钮动画
{ {
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Sequence mySequence = DOTween.Sequence(); Sequence mySequence = DOTween.Sequence();
mySequence.Append(button.transform.DOScale(max, 0.1f* timemultiple)) // 第一个动画 mySequence.Append(button.transform.DOScale(max, 0.1f* timemultiple)) // 第一个动画
.Append(button.transform.DOScale(1f, 0.2f* timemultiple)).OnComplete(() => { .Append(button.transform.DOScale(1f, 0.2f* timemultiple)).OnComplete(() => {
// 动画播放完成后执行的代码 // 动画播放完成后执行的代码
tcs.SetResult(true); tcs.SetResult(true);
}); // 第二个动画 }); // 第二个动画
await tcs.Task; await tcs.Task;
} }
/// <summary> /// <summary>
/// 添加通用上移弹窗 /// 添加通用上移弹窗
/// </summary> /// </summary>
/// <param name="Details"></param> /// <param name="Details"></param>
/// <param name="time"></param> /// <param name="time"></param>
public void addEventPopUp(string Details,float time = 5f)//添加弹窗 public void addEventPopUp(string Details,float time = 5f)//添加弹窗
{ {
GameObject prefab = Resources.Load<GameObject>("base/EventPopUp"); GameObject prefab = Resources.Load<GameObject>("base/EventPopUp");
prefab.GetComponent<EventPopUp>().time = time; prefab.GetComponent<EventPopUp>().time = time;
@ -97,7 +99,7 @@ public class Base : MonoBehaviour
} }
//logoPanel.ServerResponse TestserverResponse; //logoPanel.ServerResponse TestserverResponse;
//protected Dictionary<string, string> testhead; //protected Dictionary<string, string> testhead;
//public async void testLogo()//测试登录 //public async void testLogo()//测试登录
//{ //{
// LoginAndGetToken.loginbody body = new LoginAndGetToken.loginbody // LoginAndGetToken.loginbody body = new LoginAndGetToken.loginbody
@ -111,7 +113,7 @@ public class Base : MonoBehaviour
// if (response != null && response.code == 200 && response.data != null) // if (response != null && response.code == 200 && response.data != null)
// { // {
// TestserverResponse = response; // TestserverResponse = response;
// addEventPopUp("测试登录成功"); // addEventPopUp("测试登录成功");
// testhead = new Dictionary<string, string> // testhead = new Dictionary<string, string>
// { // {
@ -123,24 +125,24 @@ public class Base : MonoBehaviour
// testhead = new Dictionary<string, string>(); // testhead = new Dictionary<string, string>();
//} //}
/// <summary> /// <summary>
/// 判读是否为小数,并且必须大于零 /// 判读是否为小数,并且必须大于零
/// </summary> /// </summary>
/// <param name="text">判断的字符串</param> /// <param name="text">判断的字符串</param>
/// <returns></returns> /// <returns></returns>
public bool IsGreaterThanZeroDecimal(string text)//判断必须为小数而且大于0 public bool IsGreaterThanZeroDecimal(string text)//判断必须为小数而且大于0
{ {
// 使用正则表达式匹配大于0的小数 // 使用正则表达式匹配大于0的小数
string pattern = @"^(?!0(\.0+)?$)(\d+(\.\d+)?|\.\d+)$"; string pattern = @"^(?!0(\.0+)?$)(\d+(\.\d+)?|\.\d+)$";
Regex regex = new Regex(pattern); Regex regex = new Regex(pattern);
return regex.IsMatch(text); return regex.IsMatch(text);
} }
/// <summary> /// <summary>
/// 点击后关闭界面 /// 点击后关闭界面
/// </summary> /// </summary>
/// <param name="button"></param> /// <param name="button"></param>
/// <param name="my_gameObject"></param> /// <param name="my_gameObject"></param>
public async void CancelOnClick(Button button,GameObject my_gameObject = null)//取消按钮 public async void CancelOnClick(Button button,GameObject my_gameObject = null)//取消按钮
{ {
await ButtonClickAnimationAsync(button.gameObject); await ButtonClickAnimationAsync(button.gameObject);
if (my_gameObject != null) if (my_gameObject != null)