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
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMode : MonoBehaviour
{
public List<EnemyWave> wavesToSpawn = new List<EnemyWave>();
public static GameMode instance;
private int currentWave;
public List<EnemyAI> enemies = new List<EnemyAI>();
public Transform spawnPointParent;
private List<Transform> spawnPoints = new List<Transform>();
public LayerMask mask;
public GameObject enemy_Default;
public GameObject enemy_Fast;
private IEnumerator Start()
{
Screen.fullScreen = false;
Screen.SetResolution(1800, 1000, false);
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Invoke("DebugGame", 1);
Init();
while (true)
{
yield return new WaitForSeconds(3f);
//SpawnWave();
yield return WaitForWaveToEnd();
}
}
// ²âÊÔ
private void DebugGame()
{
REPL.StartREPL();
}
private IEnumerator WaitForWaveToEnd()
{
while (enemies.Count > 0)
{
yield return null;
}
}
private void Update()
{
for (int num = enemies.Count - 1; num >= 0; num--)
{
if (enemies[num] == null)
{
enemies.RemoveAt(num);
}
else if (enemies[num].IsDead())
{
enemies.RemoveAt(num);
}
}
}
private void Init()
{
mask = LayerMask.GetMask("Map");
for (int i = 0; i < spawnPointParent.childCount; i++)
{
spawnPoints.Add(spawnPointParent.GetChild(i));
}
}
private void SpawnWave()
{
for (int i = 0; i < wavesToSpawn[currentWave].groups.Count; i++)
{
for (int j = 0; (float)j < wavesToSpawn[currentWave].groups[i].number; j++)
{
SpawnEnemy(wavesToSpawn[currentWave].groups[i].enemyType);
}
}
currentWave++;
if (currentWave >= wavesToSpawn.Count)
{
currentWave = wavesToSpawn.Count - 1;
}
}
private void SpawnEnemy(EnemyGroup.EnemyType enemyType)
{
GameObject gameObject = Object.Instantiate(GetEnemyFromType(enemyType), GetSpawnPos(), Quaternion.identity);
gameObject.GetComponent<EnemyAI>().target = Player.localPlayer.torso;
enemies.Add(gameObject.GetComponent<EnemyAI>());
}
private Vector3 GetSpawnPos()
{
bool flag = false;
int num = 100000;
while (true && num > 0)
{
num--;
Vector3 vector = spawnPoints[Random.Range(0, spawnPoints.Count)].position + Vector3.up * 0.3f;
RaycastHit hitInfo = default(RaycastHit);
Ray ray = new Ray(vector, vector - Player.localPlayer.transform.position);
Physics.Raycast(ray, out hitInfo, Vector3.Distance(vector, Player.localPlayer.transform.position), mask);
if (hitInfo.collider == null)
{
return vector;
}
}
return spawnPoints[Random.Range(0, spawnPoints.Count)].position + Vector3.up * 0.3f;
}
private GameObject GetEnemyFromType(EnemyGroup.EnemyType enemyType)
{
if (enemyType == EnemyGroup.EnemyType.Fast)
{
return enemy_Fast;
}
return enemy_Default;
}
}
|