From 5ce54b749f7233e8ce66abf791e2c3de4122820b Mon Sep 17 00:00:00 2001 From: shurongsen <1799096798@qq.com> Date: Wed, 4 Dec 2024 05:50:39 +0800 Subject: [PATCH] add --- test.meta => Role.meta | 2 +- Fun.cs => Role/Fun.cs | 8 +- Fun.cs.meta => Role/Fun.cs.meta | 0 Role/Role.cs | 176 ++++++++++++++++++ test/test1.cs.meta => Role/Role.cs.meta | 2 +- Role/move.meta | 8 + Role/move/2D.meta | 8 + Role/move/2D/SimplePathfindingDoTween.cs | 36 ++++ .../move/2D/SimplePathfindingDoTween.cs.meta | 2 +- Global.cs => base/Global.cs | 0 Global.cs.meta => base/Global.cs.meta | 0 base/base.cs | 16 +- test/test.cs | 18 -- test/test1.cs | 20 -- 14 files changed, 245 insertions(+), 51 deletions(-) rename test.meta => Role.meta (77%) rename Fun.cs => Role/Fun.cs (92%) rename Fun.cs.meta => Role/Fun.cs.meta (100%) create mode 100644 Role/Role.cs rename test/test1.cs.meta => Role/Role.cs.meta (83%) create mode 100644 Role/move.meta create mode 100644 Role/move/2D.meta create mode 100644 Role/move/2D/SimplePathfindingDoTween.cs rename test/test.cs.meta => Role/move/2D/SimplePathfindingDoTween.cs.meta (83%) rename Global.cs => base/Global.cs (100%) rename Global.cs.meta => base/Global.cs.meta (100%) delete mode 100644 test/test.cs delete mode 100644 test/test1.cs diff --git a/test.meta b/Role.meta similarity index 77% rename from test.meta rename to Role.meta index ed47454..7065e3f 100644 --- a/test.meta +++ b/Role.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8793aaca69ae59144b8d5ec239fdd04e +guid: 0b07641f067dea24bad40a2dae6ca16a folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Fun.cs b/Role/Fun.cs similarity index 92% rename from Fun.cs rename to Role/Fun.cs index 75117da..1e93fb1 100644 --- a/Fun.cs +++ b/Role/Fun.cs @@ -55,8 +55,8 @@ public class Fun : Base /// public void poisoning(object[] objects) { - Palye targetAudience = (Palye)objects[0]; - Palye myPalye = (Palye)objects[1]; + Role targetAudience = (Role)objects[0]; + Role myPalye = (Role)objects[1]; Debug.Log("触发中毒"); Debug.Log(myPalye.name); } @@ -66,10 +66,10 @@ public class Fun : Base /// public void bloodLoss(object[] objects)//目标,伤害值,攻击类型,使用者 { - Palye targetAudience = (Palye)objects[0]; + Role targetAudience = (Role)objects[0]; float harm = (float)objects[1]; DamageType damageType = (DamageType)objects[2]; - Palye UserObj = (Palye)objects[3]; + Role UserObj = (Role)objects[3]; float finalDamage = harm; diff --git a/Fun.cs.meta b/Role/Fun.cs.meta similarity index 100% rename from Fun.cs.meta rename to Role/Fun.cs.meta diff --git a/Role/Role.cs b/Role/Role.cs new file mode 100644 index 0000000..284907c --- /dev/null +++ b/Role/Role.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; +using UnityEngine.UI; +using Debug = UnityEngine.Debug; + +/// +/// 角色基类,玩家处理事件 +/// +[ExecuteInEditMode] +public class Role : Fun +{ + [Header("血量")] public float hp = 100f;//血量 + [Header("掉落")] public float gold = 10f; + public float Hp + { + get => hp; + set + { + hp = value; + if (hp <= 0) + { + die(); + //if (Progress_Display.Instance == null) return; + + //Progress_Display.Instance.huadongClick(gold); + + } + } + } + + [Header("物理护甲")] public int physicalArmor = 10;//物理护甲 + [Header("魔法护甲")] public int magicArmor = 5;//魔法护甲 + + public List buffList = new List(); + [Header("导航组件")] public SimplePathfindingDoTween Navigation; + + [System.Serializable ] + public class AnimationList//动画list + { + //[Header("动画是否循环")] public bool isloop = false; + [Header("动画图片")] public List value; // 字典的值 + [Header("角色动画帧数间隔(毫秒)")] public int CharacterAnimationFrameInterval = 50; + } + [Header("角色动画")] public List AnimationTree = new List(); + [Header("角色动画播放")] public int animationHighlight = 0; + [Header("角色精灵位置")] public SpriteRenderer spriteRenderer; + [Header("角色Image位置")] public Image image; + public delegate void AnimationItem(int AnimationItem); + public event AnimationItem OnAnimationStart; + public event AnimationItem OnAnimationIng; + public event AnimationItem OnAnimationEnd; + [Header("动画是否正常播放")] public bool isAnimationPlay = false;//动画是否正常播放 + + + async void Start() + { + if (Application.isPlaying) + { + UpdateBuff(); + } + updateAnimation(); + } + /// + /// 角色动画更新 + /// + public async void updateAnimation() + { + while (true) + { + //if (AnimationTree.Count == 0) + //{ + // isAnimationPlay = false; + // return; + //} + //isAnimationPlay = true; + if (animationHighlight > AnimationTree.Count) + { + animationHighlight = AnimationTree.Count - 1; + Debug.Log("=---"); + } + else if (animationHighlight < 0) { + animationHighlight = 0; + } + EditorUtility.SetDirty(this); + Debug.Log(animationHighlight > AnimationTree.Count); + Debug.Log(animationHighlight); + List LightSprite = AnimationTree[animationHighlight].value; + if (LightSprite == null ) + { + //isAnimationPlay = false; + return; + }; + OnAnimationStart?.Invoke(animationHighlight); + foreach (Sprite sprite in LightSprite) + { + if (image != null) + { + image.sprite = sprite; + } + else if (spriteRenderer != null) + { + spriteRenderer.sprite = sprite; + } + if (animationHighlight > 0 && animationHighlight < AnimationTree.Count) + { + OnAnimationIng?.Invoke(animationHighlight); + await Task.Delay(AnimationTree[animationHighlight].CharacterAnimationFrameInterval); + } + + } + OnAnimationEnd?.Invoke(animationHighlight); + } + } + /// + /// 角色死亡 + /// + public virtual void die() + { + if (Application.isPlaying) + { + Destroy(gameObject); + } + + } + + /// + /// 单位更新buff + /// + async void UpdateBuff()//单位buff更新 + { + while (true) + { + List deleteArr = new List(); + foreach (BUff buffItem in buffList) + { + if (buffItem.executionInterval <= 0) + { + buffItem.executionInterval = buffItem.executionInterval_max; + buffItem.Funaction.Invoke(buffItem.value); + } + + buffItem.executionInterval -= 0.1f; + buffItem.timeLeft -= 0.1f; + if (buffItem.timeLeft <= 0) + { + deleteArr.Add(buffItem); + + } + } + foreach (BUff item in deleteArr) + { + buffList.Remove(item); + } + await Task.Delay(100);//buff检测最小时间0.1秒执行一次 + } + + } + + // 如果启用 MonoBehaviour,则每个固定帧速率的帧都将调用此函数 + private void FixedUpdate() + { + //if (!isAnimationPlay) + //{ + // updateAnimation(); + //} + } + + +} diff --git a/test/test1.cs.meta b/Role/Role.cs.meta similarity index 83% rename from test/test1.cs.meta rename to Role/Role.cs.meta index db4f3df..5b491b7 100644 --- a/test/test1.cs.meta +++ b/Role/Role.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c02b3c0b40de2c84c8cd8d2edb52f70d +guid: c596dfec7e7bbd240b33b61a885ae327 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Role/move.meta b/Role/move.meta new file mode 100644 index 0000000..7354ae8 --- /dev/null +++ b/Role/move.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5a90bc70d7f021046bed1c96e97b8064 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Role/move/2D.meta b/Role/move/2D.meta new file mode 100644 index 0000000..3b08213 --- /dev/null +++ b/Role/move/2D.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 80ad65f0cc14aa046820d7cef0c0b529 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Role/move/2D/SimplePathfindingDoTween.cs b/Role/move/2D/SimplePathfindingDoTween.cs new file mode 100644 index 0000000..f3f3347 --- /dev/null +++ b/Role/move/2D/SimplePathfindingDoTween.cs @@ -0,0 +1,36 @@ + + using UnityEngine; + using DG.Tweening; // 引入DoTween命名空间 + + public class SimplePathfindingDoTween : Fun + { + public Transform[] waypoints; // 预设的路径点 + public float moveDuration = 1f; // 每个点之间的移动时长 + + private int currentWaypointIndex = 0; // 当前路径点的索引 + + //void Start() + //{ + // // 让角色开始移动到第一个路径点 + // MoveToNextWaypoint(); + //} + + void MoveToNextWaypoint(GameObject gameObject) + { + if (currentWaypointIndex < waypoints.Length) + { + // 获取下一个路径点 + Transform targetWaypoint = waypoints[currentWaypointIndex]; + + // 使用DoTween实现平滑移动到目标位置 + gameObject.transform.DOMove(targetWaypoint.position, moveDuration) + .OnComplete(() => MoveToNextWaypoint(gameObject)); // 移动完成后继续到下一个路径点 + + currentWaypointIndex++; // 更新路径点索引 + } + else + { + Debug.Log("到达终点!"); + } + } + } diff --git a/test/test.cs.meta b/Role/move/2D/SimplePathfindingDoTween.cs.meta similarity index 83% rename from test/test.cs.meta rename to Role/move/2D/SimplePathfindingDoTween.cs.meta index 6ad9631..763194f 100644 --- a/test/test.cs.meta +++ b/Role/move/2D/SimplePathfindingDoTween.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: cf7c464bd7bdfcc4db645246bf4529ec +guid: 28012bb73bbdd3a4f881dda28759bfa4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Global.cs b/base/Global.cs similarity index 100% rename from Global.cs rename to base/Global.cs diff --git a/Global.cs.meta b/base/Global.cs.meta similarity index 100% rename from Global.cs.meta rename to base/Global.cs.meta diff --git a/base/base.cs b/base/base.cs index 0439da4..9deddd2 100644 --- a/base/base.cs +++ b/base/base.cs @@ -11,20 +11,24 @@ using UnityEngine.UI; public class Base : MonoBehaviour { private List LoadClassName = new List() { "ImageLoader" , "Global" };//写入需要全局自动实例化的类 - public Button retbutton; - public GameObject ClosureObj; + [Header("关闭窗口的按钮")] public Button retbutton; + [Header("需要关闭的窗口")] public GameObject ClosureObj; public static GameObject GlobalObj; /// ///初始化 /// private void Awake() { - Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率 - initializeGlobal(); - if (retbutton != null) + if (Application.isPlaying) { - retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj)); + Application.targetFrameRate = Mathf.RoundToInt(55f); // 设置目标帧率 + initializeGlobal(); + if (retbutton != null) + { + retbutton.onClick.AddListener(() => CancelOnClick(retbutton, ClosureObj)); + } } + } /// diff --git a/test/test.cs b/test/test.cs deleted file mode 100644 index d68c146..0000000 --- a/test/test.cs +++ /dev/null @@ -1,18 +0,0 @@ -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/test1.cs b/test/test1.cs deleted file mode 100644 index 408daec..0000000 --- a/test/test1.cs +++ /dev/null @@ -1,20 +0,0 @@ -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() - { - - } -}