using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
public class BezierBulletCurve : BulletCurve
|
{
|
private Vector2 start;
|
private Vector2 end;
|
private Vector2 control;
|
|
public BezierBulletCurve(BattleObject caster, SkillConfig skillConfig, BattleEffectPlayer effectPlayer,
|
RectTransform target, HB427_tagSCUseSkill tagUseSkillAttack, int bulletIndex, Action<int, List<HB427_tagSCUseSkill.tagSCUseSkillHurt>> onHit)
|
: base(caster, skillConfig, effectPlayer, target, tagUseSkillAttack, bulletIndex, onHit) { }
|
|
public override void Reset()
|
{
|
base.Reset();
|
start = WorldToLocalAnchoredPosition(bulletTrans.position);
|
end = WorldToLocalAnchoredPosition(target.position);
|
duration = Vector2.Distance(start, end) / skillConfig.BulletFlySpeed;
|
control = (start + end) / 2 + Vector2.up * 100f;
|
}
|
|
public override void Run()
|
{
|
if (finished) return;
|
elapsed += Time.deltaTime;
|
float t = Mathf.Clamp01(elapsed / duration);
|
Vector2 pos = Mathf.Pow(1 - t, 2) * start + 2 * (1 - t) * t * control + Mathf.Pow(t, 2) * end;
|
bulletTrans.anchoredPosition = pos;
|
|
Vector2 tangent = 2 * (1 - t) * (control - start) + 2 * t * (end - control);
|
float angle = Mathf.Atan2(tangent.y, tangent.x) * Mathf.Rad2Deg - 90f;
|
bulletTrans.localRotation = Quaternion.Euler(0, 0, angle);
|
|
if (t >= 1f)
|
{
|
finished = true;
|
onHit?.Invoke(mBulletIndex, hurts);
|
}
|
}
|
}
|