using System.Collections.Generic;
|
using ActionGameFramework.Health;
|
using Core.Utilities;
|
using UnityEngine;
|
|
namespace TowerDefense.Towers.TowerLaunchers
|
{
|
public abstract class Launcher : MonoBehaviour, ILauncher
|
{
|
protected ParticleSystem particleToPlay;
|
/// <summary>
|
/// 派生类,只需要真正实现这一个函数就可以了,其它的函数都是通过这一个函数来实现的。
|
/// </summary>
|
/// <param name="enemy"></param>
|
/// <param name="attack"></param>
|
/// <param name="firingPoint"></param>
|
public abstract void Launch(Targetable enemy, GameObject attack, Transform firingPoint, int idx = 0);
|
|
/// <summary>
|
/// Gets an instance of the attack object from the Pool and Launches it
|
/// </summary>
|
/// <param name="enemies">
|
/// The list of enemies to sample from
|
/// </param>
|
/// <param name="attack">
|
/// The object used to attack
|
/// </param>
|
/// <param name="firingPoints"></param>
|
public virtual void Launch(List<Targetable> enemies, GameObject attack, Transform[] firingPoints, int maxAttack = 1)
|
{
|
int count = enemies.Count;
|
int currentFiringPointIndex = 0;
|
int firingPointLength = firingPoints.Length;
|
count = count > maxAttack ? maxAttack : count;
|
for (int i = 0; i < count; i++)
|
{
|
Targetable enemy = enemies[i];
|
Transform firingPoint = firingPoints[currentFiringPointIndex];
|
currentFiringPointIndex = (currentFiringPointIndex + 1) % firingPointLength;
|
var poolable = Poolable.TryGetPoolable<Poolable>(attack);
|
if (poolable == null)
|
{
|
return;
|
}
|
//
|
// 此处设置局内升级数据对应的攻击数据:
|
Damager tm = poolable.gameObject.GetComponent<Damager>();
|
if (tm)
|
{
|
Damager srctm = attack.GetComponent<Damager>();
|
tm.inSceneUpGradeDamage = srctm.inSceneUpGradeDamage;
|
tm.doubleHit = srctm.doubleHit;
|
//Debug.Log("源始局内升级数据是:" + srctm.inSceneUpGradeDamage);
|
}
|
|
Launch(enemy, poolable.gameObject, firingPoint, i);
|
}
|
}
|
|
/// <summary>
|
/// Gets a instance of attack from the Pool and Launches it
|
/// </summary>
|
/// <param name="enemy">
|
/// The enemy launcher is attacking
|
/// </param>
|
/// <param name="attack">
|
/// The object used to attack the enemy
|
/// </param>
|
/// <param name="firingPoints"></param>
|
public virtual void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints)
|
{
|
var poolable = Poolable.TryGetPoolable<Poolable>(attack);
|
if (poolable == null)
|
{
|
return;
|
}
|
|
//
|
// 此处设置局内升级数据对应的攻击数据:
|
Damager tm = poolable.gameObject.GetComponent<Damager>();
|
if (tm)
|
{
|
tm.IsEnhancedBullet = attack.GetComponent<Damager>().IsEnhancedBullet;
|
Damager srctm = attack.GetComponent<Damager>();
|
tm.inSceneUpGradeDamage = srctm.inSceneUpGradeDamage;
|
tm.doubleHit = srctm.doubleHit;
|
|
//
|
// 最后一颗子弹的多倍伤害.
|
tm.damageMulti = srctm.damageMulti;
|
srctm.damageMulti = 1.0f;
|
//Debug.Log("源始局内升级数据是:" + srctm.inSceneUpGradeDamage);
|
}
|
// WORK START: 从 Pool 内获取数据的时候,就把原来的数据清除掉了.
|
Launch(enemy, poolable.gameObject, firingPoints[0]); //GetRandomTransform(firingPoints));
|
}
|
|
/// <summary>
|
/// Sets up a particle system to provide aiming feedback
|
/// </summary>
|
/// <param name="particleSystemToPlay">
|
/// The Particle system to fire
|
/// </param>
|
/// <param name="origin">
|
/// The position of the particle system
|
/// </param>
|
/// <param name="lookPosition">
|
/// The direction the particle system is looking
|
/// </param>
|
public void PlayParticles(ParticleSystem particleSystemToPlay, Vector3 origin, Vector3 lookPosition)
|
{
|
|
if (particleSystemToPlay == null)
|
{
|
return;
|
}
|
|
particleSystemToPlay.transform.position = origin;
|
particleSystemToPlay.transform.LookAt(lookPosition);
|
particleSystemToPlay.Play();
|
|
|
// if( !particleToPlay )
|
// particleToPlay = Instantiate(particleSystemToPlay);
|
// particleToPlay.transform.position = origin;
|
// particleToPlay.transform.LookAt(lookPosition);
|
// particleToPlay.Play();
|
|
//Debug.Log("播放粒子系统:" + particleSystemToPlay.name);
|
}
|
|
/// <summary>
|
/// Gets a random transform from a list
|
/// </summary>
|
/// <param name="launchPoints">
|
/// The list of transforms to use
|
/// </param>
|
public Transform GetRandomTransform(Transform[] launchPoints)
|
{
|
int index = Random.Range(0, launchPoints.Length);
|
return launchPoints[index];
|
}
|
}
|
}
|