hch
2025-07-30 bae41593e19d32046f77ed1f036089e015380b99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using UnityEngine;
 
/// <summary>
/// 弹射型子弹曲线:依次弹射到 HurtList 的每个目标,每次弹射飞行时间固定为0.2秒
/// </summary>
public class BounceBulletCurve : BulletCurve
{
    private List<H0604_tagUseSkillAttack.tagSkillHurtObj> 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, EffectPlayer effectPlayer,
        RectTransform target, H0604_tagUseSkillAttack tagUseSkillAttack, Action<int, List<H0604_tagUseSkillAttack.tagSkillHurtObj>> onHit)
        : base(caster, skillConfig, effectPlayer, target, onHit)
    {
        this.hurtList = new List<H0604_tagUseSkillAttack.tagSkillHurtObj>(tagUseSkillAttack.HurtList);
    }
 
    public override void Reset()
    {
        base.Reset();
        curIndex = 0;
        bounceElapsed = 0f;
        if (hurtList.Count > 0)
        {
            start = WorldToLocalAnchoredPosition(bulletTrans.position);
            end = WorldToLocalAnchoredPosition(target.position);
        }
    }
 
    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(curIndex, 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;
        }
    }
}