From 5a778abdbc07bcac0d2382db6ef0eef9a8842836 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Thu, 19 Dec 2024 19:01:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Bullet.cs | 3 +- Role/Fun.cs | 1 + Role/Role.cs | 39 ++++++++++++++++++++---- Role/move/2D/SimplePathfindingDoTween.cs | 18 +++++++++-- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 9466a73..feeef26 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -109,7 +109,7 @@ public class Bullet : MonoBehaviour { direction = 1; } - + Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role },direction); attackObj.bulltes.Remove(this.gameObject); @@ -143,6 +143,7 @@ public class Bullet : MonoBehaviour if (Time.time - lastDamageTime > 1f) // 每秒扣一次血 { + Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role }); lastDamageTime = Time.time; } diff --git a/Role/Fun.cs b/Role/Fun.cs index 0eca5d1..bfeb3b1 100644 --- a/Role/Fun.cs +++ b/Role/Fun.cs @@ -58,6 +58,7 @@ public class Fun : Base DamageType damageType = (DamageType)objects[2]; Role UserObj = (Role)objects[3]; + float finalDamage = harm; switch (damageType) diff --git a/Role/Role.cs b/Role/Role.cs index f7ec191..1263401 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -69,12 +69,15 @@ public class Role : Fun // 更新血量文本效果 if (HpTextPrefab != null && hp < maxHp) { + hit(); + Navigation.StopPathDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值 GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); go.GetComponent().direction = HurtDirectin; go.GetComponent().CreateText(); go.GetComponent().text = (temp - hp).ToString(); // 显示伤害值 FlashRedEffect(); // 血量减少时的红色闪烁效果 - StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值 + + } // 判断角色是否死亡 if (hp <= 0) @@ -128,6 +131,9 @@ public class Role : Fun [Header("攻击脚本")] public Attack attackClass; [Header("当前播放图片序列")] public int CurrentIndex; + public int hitIndex = 2;//受击动画索引 + public int normalIndex = 0;//移动动画索引 + public bool isHit=false;// public virtual async void Start() { @@ -165,12 +171,13 @@ public class Role : Fun { animationHighlight = AnimationTree.Count - 1; } - else if (animationHighlight < 0) { + else if (animationHighlight < 0) + { animationHighlight = 0; } //EditorUtility.SetDirty(this); List LightSprite = AnimationTree[animationHighlight].value; - if (LightSprite == null ) + if (LightSprite == null) { isAnimationPlay = false; return; @@ -207,16 +214,23 @@ public class Role : Fun if (lsanimationHighlight == dieIndex) { - SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中 - ResetAllStatus(); + SpawnPool.intance.ReturnEnemyToPool(this.gameObject); // 回收当前敌人到池中 + ResetAllStatus(); + } + + if (lsanimationHighlight == hitIndex) + { + + animationHighlight = normalIndex; } } } + /// /// 角色死亡 /// - public virtual void die() + public virtual void die() { if (Application.isPlaying) { @@ -227,6 +241,19 @@ public class Role : Fun } + /// + /// 角色受到攻击 + /// + public virtual void hit() + { + if (Application.isPlaying) + { + animationHighlight = hitIndex; + + } + + } + /// /// 单位更新buff /// diff --git a/Role/move/2D/SimplePathfindingDoTween.cs b/Role/move/2D/SimplePathfindingDoTween.cs index 605b1a0..b46ad73 100644 --- a/Role/move/2D/SimplePathfindingDoTween.cs +++ b/Role/move/2D/SimplePathfindingDoTween.cs @@ -19,7 +19,7 @@ public class SimplePathfindingDoTween : Fun private int currentWaypointIndex = 0; // 当前路径点的索引 Vector3 Vector3 = new Vector3(); - + public Tween pathTween; [Header("旋转的动画")]public GameObject obj; public void MoveToNextWaypoint(GameObject gameObject, float moveSpeed) @@ -49,7 +49,7 @@ public class SimplePathfindingDoTween : Fun } // 使用DoTween的DOPath来平滑地移动 - gameObject.transform.DOPath(path, timeToReach, PathType.Linear) + pathTween=gameObject.transform.DOPath(path, timeToReach, PathType.Linear) .SetEase(Ease.Linear) .OnUpdate(() => RotateTowardsTarget()); // 每次更新时调整旋转 @@ -64,6 +64,20 @@ public class SimplePathfindingDoTween : Fun // 暂停动画 transform.DOPause(); } + + + public void StopPathDoTween(float stopTime)//暂停移动 + { + // 暂停当前的动画 + pathTween.Pause(); + + // 插入一个自定义的延迟(僵直时间) + DOTween.To(() => 0f, x => { }, 0f, stopTime).OnKill(() => + { + // 在延迟结束后恢复动画 + pathTween.Play(); + }); + } void RotateTowardsTarget() { Vector3 _vector3 = Vector3 - gameObject.transform.position;