add
This commit is contained in:
parent
3a6e7aae2b
commit
4ce38f4a0b
99
Fun.cs
Normal file
99
Fun.cs
Normal file
@ -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<object[]> 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);
|
||||
// }
|
||||
//}
|
||||
/// <summary>
|
||||
/// 中毒 //目标 // 自己
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
public void poisoning(object[] objects)
|
||||
{
|
||||
Palye targetAudience = (Palye)objects[0];
|
||||
Palye myPalye = (Palye)objects[1];
|
||||
Debug.Log("触发中毒");
|
||||
Debug.Log(myPalye.name);
|
||||
}
|
||||
/// <summary>
|
||||
/// 扣血 传入参数 目标,伤害值,攻击类型,使用者
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
Fun.cs.meta
Normal file
11
Fun.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63e22c15b0e938545a31b8e15f5a906c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Global.cs
Normal file
25
Global.cs
Normal file
@ -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<string> Value;
|
||||
|
||||
// public FuncClass(string _Name, List<string> _Value)
|
||||
// {
|
||||
// Name = _Name;
|
||||
// Value = _Value;
|
||||
// }
|
||||
// }
|
||||
|
||||
//public Dictionary<string, List<FuncClass>> funcClasses = new List<FuncClass>
|
||||
//{
|
||||
// new FuncClass("poisoning",new List<string>{
|
||||
|
||||
// })
|
||||
//};
|
||||
}
|
11
Global.cs.meta
Normal file
11
Global.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e7bc39fa4e69394c97a30e1538ace03
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
base.meta
Normal file
8
base.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7ecaeb120769bd4c98162eaf5a5c215
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
base/EventPopUp.cs
Normal file
34
base/EventPopUp.cs
Normal file
@ -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<Canvas>();
|
||||
float canvasHeight = canvas.GetComponent<RectTransform>().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;
|
||||
}
|
||||
}
|
||||
}
|
11
base/EventPopUp.cs.meta
Normal file
11
base/EventPopUp.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58e836951d7e1724db6a078984a9b193
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
base/ImageLoader.cs
Normal file
66
base/ImageLoader.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
public class ImageLoader : MonoBehaviour
|
||||
{
|
||||
// 缓存字典
|
||||
private Dictionary<string, Sprite> imageCache = new Dictionary<string, Sprite>();
|
||||
//private async void Start()
|
||||
//{
|
||||
// GetComponent<Image>().sprite = await LoadImageAsync("https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/goods/mall/c7860d8909194d479b6f27ccb922e863.png");
|
||||
//}
|
||||
// 异步加载图片
|
||||
public async Task<Sprite> 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;
|
||||
// }
|
||||
//}
|
||||
}
|
11
base/ImageLoader.cs.meta
Normal file
11
base/ImageLoader.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a6867b83e3950542877ec6fb010c5d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
139
base/base.cs
Normal file
139
base/base.cs
Normal file
@ -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<string> LoadClassName = new List<string>() { "ImageLoader" , "Global" };//写入需要全局自动实例化的类
|
||||
public Button retbutton;
|
||||
public GameObject ClosureObj;
|
||||
public static GameObject GlobalObj;
|
||||
/// <summary>
|
||||
//初始化
|
||||
/// </summary>
|
||||
private void Awake()
|
||||
{
|
||||
Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率
|
||||
initializeGlobal();
|
||||
if (retbutton != null)
|
||||
{
|
||||
retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj));
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化全局类
|
||||
/// </summary>
|
||||
private void initializeGlobal()
|
||||
{
|
||||
if (GlobalObj == null)
|
||||
{
|
||||
GlobalObj = new GameObject("GlobalObj");
|
||||
DontDestroyOnLoad(GlobalObj);
|
||||
foreach (string className in LoadClassName) {
|
||||
CallClassByString(className);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 用于通过类名字符串动态调用类和方法
|
||||
/// </summary>
|
||||
/// <param name="className"></param>
|
||||
public void CallClassByString(string className)
|
||||
{
|
||||
// 获取类的 Type 对象
|
||||
Type type = Type.GetType(className);
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
GlobalObj.AddComponent(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Class not found.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按钮动画,点击后会放大缩小
|
||||
/// </summary>
|
||||
/// <param name="button">实施目标对象</param>
|
||||
/// <param name="max">放大倍率</param>
|
||||
/// <param name="timemultiple">动画持续时间倍率</param>
|
||||
/// <returns></returns>
|
||||
public async Task ButtonClickAnimationAsync(GameObject button,float max=1.25f,float timemultiple = 1)//按钮动画
|
||||
{
|
||||
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
|
||||
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<GameObject>("base/EventPopUp");
|
||||
prefab.GetComponent<EventPopUp>().time = time;
|
||||
Canvas canvas = GetComponentInParent<Canvas>();
|
||||
prefab.GetComponent<EventPopUp>().text = Details;
|
||||
Instantiate(prefab, canvas.transform);
|
||||
}
|
||||
//logoPanel.ServerResponse TestserverResponse;
|
||||
//protected Dictionary<string, string> 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<logoPanel.ServerResponse>(loginResponse);
|
||||
// if (response != null && response.code == 200 && response.data != null)
|
||||
// {
|
||||
// TestserverResponse = response;
|
||||
// addEventPopUp("测试登录成功");
|
||||
|
||||
// testhead = new Dictionary<string, string>
|
||||
// {
|
||||
// { "Authorization", TestserverResponse.data.token }
|
||||
// };
|
||||
// return;
|
||||
// }
|
||||
// addEventPopUp(response.message);
|
||||
// testhead = new Dictionary<string, string>();
|
||||
//}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
base/base.cs.meta
Normal file
11
base/base.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00712f61a0d6af941877575b41fae4cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
test.meta
Normal file
8
test.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8793aaca69ae59144b8d5ec239fdd04e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
18
test/test.cs
Normal file
18
test/test.cs
Normal file
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
test/test.cs.meta
Normal file
11
test/test.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf7c464bd7bdfcc4db645246bf4529ec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
test/test1.cs
Normal file
20
test/test1.cs
Normal file
@ -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<Image>().sprite = await GlobalObj.GetComponent<ImageLoader>().LoadImageAsync("https://fantasymonster-app.oss-cn-hangzhou.aliyuncs.com/goods/mall/c7860d8909194d479b6f27ccb922e863.png");
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
test/test1.cs.meta
Normal file
11
test/test1.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c02b3c0b40de2c84c8cd8d2edb52f70d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user