-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmitter.cs
91 lines (76 loc) · 2.2 KB
/
Emitter.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Emitter.
/// waveを排出するクラス
/// n個のwaveを持つ
/// </summary>
public class Emitter : MonoBehaviour {
public int waveLoopCount = 1;
/// <summary>
/// Waves.
/// </summary>
[System.Serializable]
public struct Waves{
public GameObject wave;
public Vector3 position;
public float switchInterval;
public bool isSimultaneous; // 同時に
public int howMany;
}
public List<Waves> waves = new List<Waves> ();
// 現在のウェーブ
private int currentWave;
private void CreateWave(int c){
// Waveを作成する
GameObject wave = (GameObject)Instantiate(waves[c].wave,
waves[c].position,
transform.rotation);
// WaveをEmitterの子要素にする
wave.transform.SetParent(transform);
}
protected IEnumerator SwitchWaves(int current){
while (true) {
float duration = 0; // 時間を計測
var w = waves[current]; // 毎回書くと長いからwと表す
if (w.isSimultaneous) { // 今装備されているwaveが同時の場合
for (int i = current; i < w.howMany + 1; i++) { // 同時に何個waveを使いたいか
current = AdjustmentCurrentShooters (i); // 配列の長さを超えていたら0に
CreateWave (i);
}
} else {
CreateWave (current);
}
while(transform.childCount != 0 && duration <= w.switchInterval){ // 子要素のwaveがなくなるまで待つ か 時間がくるまで待つ
duration += Time.deltaTime;
yield return new WaitForEndOfFrame ();
}
current = AdjustmentCurrentShooters (++current);
}
}
/// <summary>
/// Waves配列の長さをcurrentが超えたらcurrentを0にする
/// </summary>
/// <returns>The current shooters.</returns>
/// <param name="current">Current.</param>
protected int AdjustmentCurrentShooters(int current){
if (current >= waves.Count) {
return 0;
} else {
return current;
}
}
private void OmitNullFromWaves(){
waves.RemoveAll (w => w.wave == null);
}
void Start(){
waveLoopCount = 1;
currentWave = 0;
OmitNullFromWaves ();
StartCoroutine (SwitchWaves (currentWave));
}
void Update(){
OmitNullFromWaves (); // nullを除外
}
}