Unity チュートリアルのタワーディフェンステンプレートを触ってみる(20)

Unity チュートリアルのタワーディフェンステンプレートを触ってみる(19)では LaserTower_0 に追加した AttackAffector の解説を行った。今回は LaserTower_0 に追加した HitscanLauncher のインタフェースである ILauncher の解説を行っていく。
1.標的設定と砲撃編 – ILauncher.cs
ILauncher.cs について稚拙ながら解説
「ILauncher.cs」は「Assets/Scripts/TowerDefense/Towers/ILauncher.cs」の指しておりスクリプトについては以下の通り。内容としては砲撃処理の関数定を行っている。
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 using System.Collections.Generic;
using ActionGameFramework.Health;
using UnityEngine;
namespace TowerDefense.Towers
{
/// <summary>
/// A class that allows the TowerConfiguration to delegate
/// different firing logic this component
/// </summary>
public interface ILauncher
{
/// <summary>
/// The method for crafting the firing logic for the tower
/// </summary>
/// <param name="enemy">
/// The enemy that the tower is targeting
/// </param>
/// <param name="attack">
/// The projectile component used to attack the enemy
/// </param>
/// <param name="firingPoint"></param>
void Launch(Targetable enemy, GameObject attack, Transform firingPoint);
/// <summary>
/// The method for crafting the firing logic for the tower
/// </summary>
/// <param name="enemy">
/// The enemy that the tower is targeting
/// </param>
/// <param name="attack">
/// The projectile component used to attack the enemy
/// </param>
/// <param name="firingPoints">
/// A list of firing points to fire from
/// </param>
void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints);
/// <summary>
/// The method for crafting firing logic at multiple enemies
/// </summary>
/// <param name="enemies">
/// The collection of enemies to attack
/// </param>
/// <param name="attack">
/// The projectile component used to attack the enemy
/// </param>
/// <param name="firingPoints"></param>
void Launch(List<Targetable> enemies, GameObject attack, Transform[] firingPoints);
}
}
23行目 : 「void Launch(Targetable enemy, GameObject attack, Transform firingPoint);」は砲撃処理を作成する関数の定義を行っている。
37行目 : 「void Launch(Targetable enemy, GameObject attack, Transform[] firingPoints);」も23行目と同様に砲撃処理を作成する関数の定義を行っている。ここでは複数の発射地点を想定している
49行目 : 「void Launch(List<Targetable> enemies, GameObject attack, Transform[] firingPoints);」も23行目と同様に砲撃処理を作成する関数の定義を行っている。ここでは複数の発射地点かつ複数の的に砲撃することを想定している