using System; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
  
 | 
/// <summary> 
 | 
/// 弹射型子弹曲线:依次弹射到 HurtList 的每个目标,每次弹射飞行时间固定为0.2秒 
 | 
/// </summary> 
 | 
public class BounceBulletCurve : BulletCurve 
 | 
{ 
 | 
    private List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hurtList; 
 | 
    private int curIndex = 0; 
 | 
    private Vector2 start; 
 | 
    private Vector2 end; 
 | 
    private float bounceTime = 0.2f; // 每次弹射时间 
 | 
    private float bounceElapsed = 0f; 
 | 
  
 | 
    public BounceBulletCurve(BattleObject caster, SkillConfig skillConfig, BattleEffectPlayer effectPlayer, 
 | 
        RectTransform target, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hurtList, int bulletIndex, Action<int, List<HB427_tagSCUseSkill.tagSCUseSkillHurt>> onHit) 
 | 
        : base(caster, skillConfig, effectPlayer, target, hurtList, bulletIndex, onHit) 
 | 
    { 
 | 
        this.hurtList = hurtList; 
 | 
    } 
 | 
  
 | 
    public override void Reset() 
 | 
    { 
 | 
        base.Reset(); 
 | 
        curIndex = 0; 
 | 
        bounceElapsed = 0f; 
 | 
        if (hurtList.Count > 0) 
 | 
        { 
 | 
            start = WorldToLocalAnchoredPosition(bulletTrans.position) + bulletOffset; 
 | 
            end = WorldToLocalAnchoredPosition(target.position); 
 | 
            duration = Vector2.Distance(start, end) / skillConfig.BulletFlySpeed; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public override void Run() 
 | 
    { 
 | 
        if (finished || hurtList.Count == 0) return; 
 | 
  
 | 
        bounceElapsed += Time.deltaTime; 
 | 
        float t = Mathf.Clamp01(bounceElapsed / bounceTime); 
 | 
  
 | 
        Vector2 pos = Vector2.Lerp(start, end, t) + Vector2.up * Mathf.Sin(t * Mathf.PI) * 50f; 
 | 
        bulletTrans.anchoredPosition = pos; 
 | 
  
 | 
        Vector2 dir = end - start; 
 | 
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 90f; 
 | 
        bulletTrans.localRotation = Quaternion.Euler(0, 0, angle); 
 | 
  
 | 
        if (t >= 1f) 
 | 
        { 
 | 
            // 命中当前目标 
 | 
            onHit?.Invoke(mBulletIndex, hurtList); 
 | 
  
 | 
            curIndex++; 
 | 
            if (curIndex >= hurtList.Count) 
 | 
            { 
 | 
                finished = true; 
 | 
                return; 
 | 
            } 
 | 
            // 下一段弹射 
 | 
            start = end; 
 | 
            var nextTargetObj = caster.battleField.battleObjMgr.GetBattleObject((int)hurtList[curIndex].ObjID); 
 | 
            if (nextTargetObj != null) 
 | 
            { 
 | 
                end = WorldToLocalAnchoredPosition(nextTargetObj.heroGo.transform.position); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                Debug.LogError("弹射找不到下一个目标"); 
 | 
                // 如果目标丢失,直接用上一个end 
 | 
                end = start; 
 | 
            } 
 | 
            bounceElapsed = 0f; 
 | 
        } 
 | 
    } 
 | 
} 
 |