```
feat(Enemy): 添加敌人攻击动画速度控制功能 - 新增attackDuration属性用于控制完整攻击动作时长 - 实现攻击动画速度动态调整,支持自定义攻击持续时间 - 添加健康条显示组件到敌人类 - 增加物理材质配置优化碰撞效果 - 添加微信小游戏平台支持和适配 - 集成自适应性能包和微信小游戏SDK - 配置项目构建设置支持多平台发布 - 更新质量设置以适配不同目标平台 - 调整场景中物体位置和旋转参数 - 修复角色控制器材质引用问题 - 优化敌人AI移动和攻击逻辑 ```
This commit is contained in:
1 parent
b807bb80ec
commit
48dfa0d95d
38 files changed
+2295
-36
No files matched your search
@@ -20,6 +20,10 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
//攻击范围
|
||||
public float attackRange = 5f;
|
||||
|
||||
//完整攻击动作时长,单位为秒;设置为0时使用动画真实时长
|
||||
[Min(0f)]
|
||||
public float attackDuration = 0f;
|
||||
|
||||
//角色状态
|
||||
private State state = State.Alert;
|
||||
|
||||
@@ -176,12 +180,74 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
return Vector3.Distance(transform.position, opponent.transform.position) <= reachDistance;
|
||||
}
|
||||
|
||||
//查找当前Animator中使用的攻击动画时长
|
||||
private float GetAttackAnimationDuration()
|
||||
{
|
||||
if (animator == null || animator.runtimeAnimatorController == null)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
var overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;
|
||||
if (overrideController != null)
|
||||
{
|
||||
var overrides = new List<KeyValuePair<AnimationClip, AnimationClip>>();
|
||||
overrideController.GetOverrides(overrides);
|
||||
|
||||
foreach (var pair in overrides)
|
||||
{
|
||||
if (IsAttackAnimation(pair.Key))
|
||||
{
|
||||
return pair.Value != null ? pair.Value.length : pair.Key.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var clip in animator.runtimeAnimatorController.animationClips)
|
||||
{
|
||||
if (IsAttackAnimation(clip))
|
||||
{
|
||||
return clip.length;
|
||||
}
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
//根据动画名称判断是否为攻击动画
|
||||
private bool IsAttackAnimation(AnimationClip clip)
|
||||
{
|
||||
if (clip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string clipName = clip.name.ToLowerInvariant();
|
||||
return clipName.Contains("attack")
|
||||
|| clipName.Contains("攻击")
|
||||
|| clipName.Contains("挥剑");
|
||||
}
|
||||
|
||||
//设置攻击动画播放速度
|
||||
private void SetAttackAnimationSpeed()
|
||||
{
|
||||
float animationDuration = GetAttackAnimationDuration();
|
||||
if (animationDuration <= 0f || attackDuration <= 0f)
|
||||
{
|
||||
animator.speed = 1f;
|
||||
return;
|
||||
}
|
||||
|
||||
animator.speed = animationDuration / attackDuration;
|
||||
}
|
||||
|
||||
//攻击
|
||||
private void attack(GameObject friend)
|
||||
{
|
||||
target = friend;
|
||||
|
||||
//攻击动画动作
|
||||
//根据目标攻击时长加速或减速完整攻击动画
|
||||
SetAttackAnimationSpeed();
|
||||
animator.SetInteger("speed", 0);
|
||||
animator.SetTrigger("attack");
|
||||
state = State.Attack;
|
||||
@@ -191,6 +257,9 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
// 在 Animator 的 Attack 动画结束时调用此方法
|
||||
public void OnAttackAnimationEnd()
|
||||
{
|
||||
//攻击动画结束后恢复Animator速度
|
||||
animator.speed = 1f;
|
||||
|
||||
//攻击动画结束后,目标仍在攻击范围内则立即进行下一次攻击
|
||||
target = FindNearestOpponent();
|
||||
if (target != null && IsWithinAttackReach(target))
|
||||
|
||||
Reference in new issue
Block a user