Skip to content

Commit 28fe8f7

Browse files
authored
(Cleanup) Isolate testing commands (#272)
* Removes the testing commands that were hacked into ServerBossRoomState Moves the testing commands into a separate component (on the same prefab). * #if DEBUG the testing hotkeys * use more specific #if
1 parent ad79aff commit 28fe8f7

File tree

4 files changed

+98
-35
lines changed

4 files changed

+98
-35
lines changed

Assets/BossRoom/Prefabs/State/BossRoomState.prefab

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GameObject:
1212
- component: {fileID: -1764033382396218637}
1313
- component: {fileID: 3608714310874968837}
1414
- component: {fileID: 5762482089640033414}
15+
- component: {fileID: 2113376856512980659}
1516
m_Layer: 0
1617
m_Name: BossRoomState
1718
m_TagString: Untagged
@@ -83,8 +84,6 @@ MonoBehaviour:
8384
m_Name:
8485
m_EditorClassIdentifier:
8586
m_PlayerPrefab: {fileID: 6009713983291384767, guid: 8237adf32a9b6de4892e6febe6b4bdef, type: 3}
86-
m_EnemyPrefab: {fileID: 3713729372785093435, guid: 6cdd52f1fa2ed34469a487ae6477eded, type: 3}
87-
m_BossPrefab: {fileID: 3688950541947916326, guid: 365e94337fd10fe4ebde1906df413ac7, type: 3}
8887
m_PlayerSpawnPoints:
8988
- {fileID: 6319832178442273571}
9089
- {fileID: 374135395555381814}
@@ -94,6 +93,23 @@ MonoBehaviour:
9493
- {fileID: 6314369147267609336}
9594
- {fileID: 8725901042666772653}
9695
- {fileID: 7239491272522478247}
96+
--- !u!114 &2113376856512980659
97+
MonoBehaviour:
98+
m_ObjectHideFlags: 0
99+
m_CorrespondingSourceObject: {fileID: 0}
100+
m_PrefabInstance: {fileID: 0}
101+
m_PrefabAsset: {fileID: 0}
102+
m_GameObject: {fileID: 297185343939699586}
103+
m_Enabled: 1
104+
m_EditorHideFlags: 0
105+
m_Script: {fileID: 11500000, guid: ab1e76745edfc434ab8154ad27efc5fd, type: 3}
106+
m_Name:
107+
m_EditorClassIdentifier:
108+
m_EnemyPrefab: {fileID: 3713729372785093435, guid: 6cdd52f1fa2ed34469a487ae6477eded, type: 3}
109+
m_BossPrefab: {fileID: 3688950541947916326, guid: 365e94337fd10fe4ebde1906df413ac7, type: 3}
110+
m_SpawnEnemyKeyCode: 101
111+
m_SpawnBossKeyCode: 98
112+
m_InstantQuitKeyCode: 113
97113
--- !u!1 &1088799320945899822
98114
GameObject:
99115
m_ObjectHideFlags: 0

Assets/BossRoom/Scripts/Server/Game/State/ServerBossRoomState.cs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,11 @@ public class ServerBossRoomState : GameStateBehaviour
1515
[Tooltip("Make sure this is included in the NetworkManager's list of prefabs!")]
1616
private NetworkObject m_PlayerPrefab;
1717

18-
// note: this is temporary, for testing!
19-
[SerializeField]
20-
[Tooltip("Make sure this is included in the NetworkManager's list of prefabs!")]
21-
private NetworkObject m_EnemyPrefab;
22-
23-
// note: this is temporary, for testing!
24-
[SerializeField]
25-
[Tooltip("Make sure this is included in the NetworkManager's list of prefabs!")]
26-
private NetworkObject m_BossPrefab;
27-
2818
[SerializeField] [Tooltip("A collection of locations for spawning players")]
2919
private Transform[] m_PlayerSpawnPoints;
20+
3021
private List<Transform> m_PlayerSpawnPointsList = null;
3122

32-
// note: this is temporary, for testing!
3323
public override GameState ActiveState { get { return GameState.BossRoom; } }
3424

3525
/// <summary>
@@ -216,27 +206,5 @@ private IEnumerator CoroGameOver(float wait, bool gameWon)
216206
GameStateRelay.SetRelayObject(gameWon);
217207
MLAPI.SceneManagement.NetworkSceneManager.SwitchScene("PostGame");
218208
}
219-
220-
/// <summary>
221-
/// Temp code to spawn an enemy
222-
/// </summary>
223-
private void Update()
224-
{
225-
if (Input.GetKeyDown(KeyCode.E))
226-
{
227-
var newEnemy = Instantiate(m_EnemyPrefab);
228-
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
229-
}
230-
if (Input.GetKeyDown(KeyCode.B))
231-
{
232-
var newEnemy = Instantiate(m_BossPrefab);
233-
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
234-
}
235-
if (Input.GetKeyDown(KeyCode.Q))
236-
{
237-
GameStateRelay.SetRelayObject(false);
238-
MLAPI.SceneManagement.NetworkSceneManager.SwitchScene("PostGame");
239-
}
240-
}
241209
}
242210
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using MLAPI;
2+
using UnityEngine;
3+
4+
namespace BossRoom.Server
5+
{
6+
/// <summary>
7+
/// Provides various special commands that the Host can use while developing and
8+
/// debugging the game. These are not compiled into release builds. (If you want
9+
/// to disable them for debug builds, disable or remove this component from the
10+
/// BossRoomState prefab.)
11+
/// </summary>
12+
public class ServerTestingHotkeys : NetworkBehaviour
13+
{
14+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
15+
[SerializeField]
16+
[Tooltip("Enemy to spawn. Make sure this is included in the NetworkManager's list of prefabs!")]
17+
private NetworkObject m_EnemyPrefab;
18+
19+
[SerializeField]
20+
[Tooltip("Boss to spawn. Make sure this is included in the NetworkManager's list of prefabs!")]
21+
private NetworkObject m_BossPrefab;
22+
23+
[SerializeField]
24+
[Tooltip("Key that the Host can press to spawn an extra enemy")]
25+
KeyCode m_SpawnEnemyKeyCode = KeyCode.E;
26+
27+
[SerializeField]
28+
[Tooltip("Key that the Host can press to spawn an extra boss")]
29+
KeyCode m_SpawnBossKeyCode = KeyCode.B;
30+
31+
[SerializeField]
32+
[Tooltip("Key that the Host can press to quit the game")]
33+
KeyCode m_InstantQuitKeyCode = KeyCode.Q;
34+
35+
public override void NetworkStart()
36+
{
37+
base.NetworkStart();
38+
39+
if (!IsServer)
40+
{
41+
// these commands don't work on the client
42+
enabled = false;
43+
}
44+
}
45+
46+
private void Update()
47+
{
48+
if (!IsServer) { return; } // not initialized yet
49+
50+
if (m_SpawnEnemyKeyCode != KeyCode.None && Input.GetKeyDown(m_SpawnEnemyKeyCode))
51+
{
52+
var newEnemy = Instantiate(m_EnemyPrefab);
53+
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
54+
}
55+
if (m_SpawnBossKeyCode != KeyCode.None && Input.GetKeyDown(m_SpawnBossKeyCode))
56+
{
57+
var newEnemy = Instantiate(m_BossPrefab);
58+
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId);
59+
}
60+
if (m_InstantQuitKeyCode != KeyCode.None && Input.GetKeyDown(m_InstantQuitKeyCode))
61+
{
62+
GameStateRelay.SetRelayObject(false); // indicate to the post-game screen that the game was lost
63+
MLAPI.SceneManagement.NetworkSceneManager.SwitchScene("PostGame");
64+
}
65+
}
66+
#endif
67+
}
68+
}

Assets/BossRoom/Scripts/Server/ServerTestingHotkeys.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)