diff --git a/Fun.cs b/Fun.cs new file mode 100644 index 0000000..75117da --- /dev/null +++ b/Fun.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + +public enum DamageType +{ + physicalDamage,//物理伤害 + magicDamage,//魔法伤害 + noAttributeDamage,//无属性伤害 + +} +//public class prefabObjects +//{ +// public string targetAudience = "targetAudience"; +// public string myPalye = "myPalye"; + +//} + +public class BUff +{ + public float timeLeft = 0;//剩余时间 + public float executionInterval = 0;//buff执行间隔 + public float executionInterval_max = 100;//buff执行间隔 + public Action Funaction;//调用的函数 + public object[] value;//调用函数的值 + +} + +public class Fun : Base +{ + //// 通过方法名调用对应的方法 + //public void CallMethodByName(string methodName) + //{ + // // 获取当前类的Type + // Type type = this.GetType(); + + // // 获取方法信息 + // MethodInfo methodInfo = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + + // if (methodInfo != null) + // { + // // 调用该方法 + // methodInfo.Invoke(this,null ); // null代表无参数 + // } + // else + // { + // Debug.LogError("方法未找到: " + methodName); + // } + //} + /// + /// 中毒 //目标 // 自己 + /// + /// + public void poisoning(object[] objects) + { + Palye targetAudience = (Palye)objects[0]; + Palye myPalye = (Palye)objects[1]; + Debug.Log("触发中毒"); + Debug.Log(myPalye.name); + } + /// + /// 扣血 传入参数 目标,伤害值,攻击类型,使用者 + /// + /// + public void bloodLoss(object[] objects)//目标,伤害值,攻击类型,使用者 + { + Palye targetAudience = (Palye)objects[0]; + float harm = (float)objects[1]; + DamageType damageType = (DamageType)objects[2]; + Palye UserObj = (Palye)objects[3]; + + + float finalDamage = harm; + switch (damageType) + { + case DamageType.physicalDamage://物理伤害 + finalDamage -= targetAudience.physicalArmor; + break; + case DamageType.magicDamage://魔法伤害 + finalDamage -= targetAudience.magicArmor; + break; + case DamageType.noAttributeDamage://无属性伤害 + finalDamage -= 0; + break; + } + if (finalDamage < 0) + { + finalDamage = 0; + + } + + targetAudience.Hp -= finalDamage; + } + + + +} diff --git a/Fun.cs.meta b/Fun.cs.meta new file mode 100644 index 0000000..20932c7 --- /dev/null +++ b/Fun.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63e22c15b0e938545a31b8e15f5a906c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Global.cs b/Global.cs new file mode 100644 index 0000000..7c87028 --- /dev/null +++ b/Global.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Global : MonoBehaviour +{ + //public class FuncClass + // { + // public string Name; + // public List Value; + + // public FuncClass(string _Name, List _Value) + // { + // Name = _Name; + // Value = _Value; + // } + // } + + //public Dictionary> funcClasses = new List + //{ + // new FuncClass("poisoning",new List{ + + // }) + //}; +} diff --git a/Global.cs.meta b/Global.cs.meta new file mode 100644 index 0000000..2ccf035 --- /dev/null +++ b/Global.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e7bc39fa4e69394c97a30e1538ace03 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/base.meta b/base.meta new file mode 100644 index 0000000..a32d5f7 --- /dev/null +++ b/base.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a7ecaeb120769bd4c98162eaf5a5c215 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/base/EventPopUp.cs b/base/EventPopUp.cs new file mode 100644 index 0000000..3c6f8a5 --- /dev/null +++ b/base/EventPopUp.cs @@ -0,0 +1,34 @@ +using DG.Tweening; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.UI; + +public class EventPopUp : MonoBehaviour +{ + public string text = ""; + public Image Image; + public Text textobg; + public float time = 5f; + async void Start() + { + Canvas canvas = GetComponentInParent(); + float canvasHeight = canvas.GetComponent().rect.height; + transform.DOMoveY(canvasHeight - (canvasHeight*0.3f), 1.5f); + await Task.Delay(500); + Image.DOColor(new Color(1f, 1f, 1f, 0f), time); + textobg.DOColor(new Color(1f, 1f, 1f, 0f), time); + await Task.Delay(5100); + Destroy(gameObject); + } + + // Update is called once per frame + void Update() + { + if (textobg != null) + { + textobg.text = text; + } + } +} diff --git a/base/EventPopUp.cs.meta b/base/EventPopUp.cs.meta new file mode 100644 index 0000000..fd8aa14 --- /dev/null +++ b/base/EventPopUp.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58e836951d7e1724db6a078984a9b193 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/base/ImageLoader.cs b/base/ImageLoader.cs new file mode 100644 index 0000000..a2dcfe3 --- /dev/null +++ b/base/ImageLoader.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Networking; +using System.Threading.Tasks; + + +public class ImageLoader : MonoBehaviour +{ + // 缓存字典 + private Dictionary imageCache = new Dictionary(); + //private async void Start() + //{ + // GetComponent().sprite = await LoadImageAsync("https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/goods/mall/c7860d8909194d479b6f27ccb922e863.png"); + //} + // 异步加载图片 + public async Task LoadImageAsync(string url) + { + // 如果缓存中已经有图片,则直接返回缓存的图片 + if (imageCache.ContainsKey(url)) + { + Debug.Log("Image found in cache."); + return imageCache[url]; + } + + // 如果缓存中没有图片,则异步加载 + using (UnityWebRequest webRequest = UnityWebRequestTexture.GetTexture(url)) + { + // 等待请求完成 + //await webRequest.SendWebRequest().ToTask(); + // 发送请求并等待响应 + var operation = webRequest.SendWebRequest(); + while (!operation.isDone) + await Task.Yield(); // 等待请求完成,使用await以非阻塞的方式处理 + // 检查请求是否成功 + if (webRequest.result == UnityWebRequest.Result.Success) + { + // 获取下载的纹理 + Texture2D texture = ((DownloadHandlerTexture)webRequest.downloadHandler).texture; + + // 将纹理缓存 + imageCache[url] = TextureToSprite(texture); + return imageCache[url]; + } + else + { + Debug.LogError("Failed to load image: " + webRequest.error); + return null; + } + } + } + // 将Texture2D转换为Sprite + Sprite TextureToSprite(Texture2D texture) + { + // 使用纹理的尺寸创建一个Sprite + return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); + } + // 加载并显示图片 + //public async void LoadAndDisplayImage(string url, Renderer renderer) + //{ + // Texture2D texture = await LoadImageAsync(url); + // if (texture != null) + // { + // renderer.material.mainTexture = texture; + // } + //} +} diff --git a/base/ImageLoader.cs.meta b/base/ImageLoader.cs.meta new file mode 100644 index 0000000..8a3d470 --- /dev/null +++ b/base/ImageLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1a6867b83e3950542877ec6fb010c5d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/base/base.cs b/base/base.cs new file mode 100644 index 0000000..5c713d9 --- /dev/null +++ b/base/base.cs @@ -0,0 +1,139 @@ +using DG.Tweening; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.UI; + + + +public class Base : MonoBehaviour +{ + private List LoadClassName = new List() { "ImageLoader" , "Global" };//写入需要全局自动实例化的类 + public Button retbutton; + public GameObject ClosureObj; + public static GameObject GlobalObj; + /// + //初始化 + /// + private void Awake() + { + Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率 + initializeGlobal(); + if (retbutton != null) + { + retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj)); + } + + } + /// + /// 初始化全局类 + /// + private void initializeGlobal() + { + if (GlobalObj == null) + { + GlobalObj = new GameObject("GlobalObj"); + DontDestroyOnLoad(GlobalObj); + foreach (string className in LoadClassName) { + CallClassByString(className); + } + } + } + /// + /// 用于通过类名字符串动态调用类和方法 + /// + /// + public void CallClassByString(string className) + { + // 获取类的 Type 对象 + Type type = Type.GetType(className); + + if (type != null) + { + GlobalObj.AddComponent(type); + } + else + { + Console.WriteLine("Class not found."); + } + } + + /// + /// 按钮动画,点击后会放大缩小 + /// + /// 实施目标对象 + /// 放大倍率 + /// 动画持续时间倍率 + /// + public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)//按钮动画 + { + TaskCompletionSource tcs = new TaskCompletionSource(); + Sequence mySequence = DOTween.Sequence(); + mySequence.Append(button.transform.DOScale(max, 0.1f* timemultiple)) // 第一个动画 + .Append(button.transform.DOScale(1f, 0.2f* timemultiple)).OnComplete(() => { + // 动画播放完成后执行的代码 + tcs.SetResult(true); + }); // 第二个动画 + await tcs.Task; + } + + public void addEventPopUp(string Details,float time = 5f)//添加弹窗 + { + GameObject prefab = Resources.Load("base/EventPopUp"); + prefab.GetComponent().time = time; + 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 } + // }; + // return; + // } + // addEventPopUp(response.message); + // 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); + } + + + +} diff --git a/base/base.cs.meta b/base/base.cs.meta new file mode 100644 index 0000000..ddf28e4 --- /dev/null +++ b/base/base.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 00712f61a0d6af941877575b41fae4cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/test.meta b/test.meta new file mode 100644 index 0000000..ed47454 --- /dev/null +++ b/test.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8793aaca69ae59144b8d5ec239fdd04e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/test/test.cs b/test/test.cs new file mode 100644 index 0000000..d68c146 --- /dev/null +++ b/test/test.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class test : Base +{ + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/test/test.cs.meta b/test/test.cs.meta new file mode 100644 index 0000000..6ad9631 --- /dev/null +++ b/test/test.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf7c464bd7bdfcc4db645246bf4529ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/test/test1.cs b/test/test1.cs new file mode 100644 index 0000000..408daec --- /dev/null +++ b/test/test1.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class test1 : Base +{ + // Start is called before the first frame update + async void Start() + { + GetComponent().sprite = await GlobalObj.GetComponent().LoadImageAsync("https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/goods/mall/c7860d8909194d479b6f27ccb922e863.png"); + + } + + // Update is called once per frame + void Update() + { + + } +} diff --git a/test/test1.cs.meta b/test/test1.cs.meta new file mode 100644 index 0000000..db4f3df --- /dev/null +++ b/test/test1.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c02b3c0b40de2c84c8cd8d2edb52f70d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: