River Jiang
2020-10-22 9ba26d8f5c0103d9f6bbc15ec76dde8ec935979b
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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)
            {
                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];
        }
    }
}