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; /// /// 派生类,只需要真正实现这一个函数就可以了,其它的函数都是通过这一个函数来实现的。 /// /// /// /// public abstract void Launch(Targetable enemy, GameObject attack, Transform firingPoint, int idx = 0); /// /// Gets an instance of the attack object from the Pool and Launches it /// /// /// The list of enemies to sample from /// /// /// The object used to attack /// /// public virtual void Launch(List 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(attack); if (poolable == null) { return; } // // 此处设置局内升级数据对应的攻击数据: Damager tm = poolable.gameObject.GetComponent(); if (tm) { Damager srctm = attack.GetComponent(); tm.inSceneUpGradeDamage = srctm.inSceneUpGradeDamage; tm.doubleHit = srctm.doubleHit; //Debug.Log("源始局内升级数据是:" + srctm.inSceneUpGradeDamage); } Launch(enemy, poolable.gameObject, firingPoint, i); } } /// /// Gets a instance of attack from the Pool and Launches it /// /// /// The enemy launcher is attacking /// /// /// The object used to attack the enemy /// /// public virtual void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints) { var poolable = Poolable.TryGetPoolable(attack); if (poolable == null) { return; } // // 此处设置局内升级数据对应的攻击数据: Damager tm = poolable.gameObject.GetComponent(); if (tm) { Damager srctm = attack.GetComponent(); 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)); } /// /// Sets up a particle system to provide aiming feedback /// /// /// The Particle system to fire /// /// /// The position of the particle system /// /// /// The direction the particle system is looking /// 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); } /// /// Gets a random transform from a list /// /// /// The list of transforms to use /// public Transform GetRandomTransform(Transform[] launchPoints) { int index = Random.Range(0, launchPoints.Length); return launchPoints[index]; } } }