using ActionGameFramework.Health;
|
using Core.Utilities;
|
using DG.Tweening;
|
using TMPro.Examples;
|
using TowerDefense.Affectors;
|
using TowerDefense.Agents;
|
using TowerDefense.Towers.Projectiles;
|
using UnityEngine;
|
using UnityEngine.UIElements;
|
|
namespace TowerDefense.Towers.TowerLaunchers
|
{
|
/// <summary>
|
/// An implementation of the tower launcher for hitscan attacks
|
/// </summary>
|
public class HitscanLauncher : Launcher
|
{
|
/// <summary>
|
/// The particle system used for providing launch feedback
|
/// </summary>
|
public GameObject fireParticleObj;
|
public ParticleSystem fireParticleSystem1;
|
public ParticleSystem fireParticleSystem2;
|
|
protected Timer effectStopTimer;
|
protected bool bTimerStart = false;
|
|
|
void Awake()
|
{
|
effectStopTimer = new Timer(1.0f, stopParticle);
|
bTimerStart = false;
|
}
|
|
|
protected void stopParticle()
|
{
|
if (particleToPlay)
|
particleToPlay.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
|
}
|
|
void Update()
|
{
|
if (bTimerStart)
|
{
|
if (effectStopTimer.Tick(Time.deltaTime))
|
{
|
bTimerStart = false;
|
effectStopTimer.Reset();
|
}
|
}
|
|
}
|
|
|
protected int times = 0;
|
/// <summary>
|
/// Assigns the correct damage to the hitscan object and
|
/// attacks the enemy immediately.
|
/// Early return if there is not HitscanAttack.cs attached to the attact object
|
/// </summary>
|
/// <param name="enemy">
|
/// The enemy this tower is targeting
|
/// </param>
|
/// <param name="attack">
|
/// The attacking component used to damage the enemy
|
/// </param>
|
/// <param name="firingPoint"></param>
|
public override void Launch(Targetable enemy, GameObject attack, Transform firingPoint, int idx = 0)
|
{
|
var hitscanAttack = attack.GetComponent<HitscanAttack>();
|
if (hitscanAttack == null)
|
{
|
return;
|
}
|
|
/* if(times != 0)
|
{
|
times++;
|
if (times >= 5)
|
times = 0;
|
return;
|
}
|
else
|
{
|
times++;
|
}
|
*/
|
// 是否有AttackAffector,获取AttackRate,计算最终的伤害延迟
|
AttackAffector aaf = GetComponent<AttackAffector>();
|
float delayAttack = 0.0f;
|
if (aaf)
|
{
|
float attackRate = aaf.FireRate;
|
if (attackRate > 0)
|
delayAttack = 1.0f / attackRate;
|
}
|
TowerLevel tl = transform.parent.gameObject.GetComponent<TowerLevel>();
|
hitscanAttack.attackRise = 0.0f;
|
if (tl != null)
|
hitscanAttack.attackRise = tl.attackRise;
|
hitscanAttack.transform.position = firingPoint.position;
|
hitscanAttack.AttackEnemy(firingPoint.position, enemy, delayAttack);
|
|
if (idx == 0)
|
{
|
// GameObject obj = Poolable.TryGetPoolable(fireParticleObj);
|
// obj.transform.position = firingPoint.position;
|
// obj.transform.LookAt(enemy.position);
|
// ParticleSystem ps = obj.GetComponent<ParticleSystem>();
|
// ps = ps ?? obj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
// ps.Play();
|
GameObject obj = Instantiate(fireParticleObj, firingPoint.position, Quaternion.identity);
|
obj.transform.LookAt(enemy.position);
|
ParticleSystem ps = obj.GetComponent<ParticleSystem>();
|
if (ps == null)
|
ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>();
|
ps?.Play();
|
}
|
else if (idx == 1)
|
{
|
PlayParticles(fireParticleSystem1, firingPoint.position, enemy.position);
|
}
|
else
|
{
|
PlayParticles(fireParticleSystem2, firingPoint.position, enemy.position);
|
}
|
|
effectStopTimer.SetTime(delayAttack / 5.0f);
|
bTimerStart = true;
|
|
}
|
}
|
}
|