From fad50818bfa09cab161eed69ed51bcf29fc6120a Mon Sep 17 00:00:00 2001 From: Chris Langsenkamp Date: Sun, 24 Nov 2019 14:35:19 -0500 Subject: [PATCH] Added AddComponentMenu empties and namespace --- .../Scripts/AdditiveNetworkManager.cs | 1 + .../Pong/Scripts/NetworkManagerPong.cs | 58 ++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs index 14f061d3d..fef51e17b 100644 --- a/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs +++ b/Assets/Mirror/Examples/AdditiveScenes/Scripts/AdditiveNetworkManager.cs @@ -4,6 +4,7 @@ namespace Mirror.Examples.Additive { + [AddComponentMenu("")] public class AdditiveNetworkManager : NetworkManager { [Scene] diff --git a/Assets/Mirror/Examples/Pong/Scripts/NetworkManagerPong.cs b/Assets/Mirror/Examples/Pong/Scripts/NetworkManagerPong.cs index a8869ff5d..793934752 100644 --- a/Assets/Mirror/Examples/Pong/Scripts/NetworkManagerPong.cs +++ b/Assets/Mirror/Examples/Pong/Scripts/NetworkManagerPong.cs @@ -1,37 +1,41 @@ using UnityEngine; using Mirror; -// Custom NetworkManager that simply assigns the correct racket positions when -// spawning players. The built in RoundRobin spawn method wouldn't work after -// someone reconnects (both players would be on the same side). -public class NetworkManagerPong : NetworkManager +namespace Mirror.Examples.Pong { - public Transform leftRacketSpawn; - public Transform rightRacketSpawn; - GameObject ball; - - public override void OnServerAddPlayer(NetworkConnection conn) + // Custom NetworkManager that simply assigns the correct racket positions when + // spawning players. The built in RoundRobin spawn method wouldn't work after + // someone reconnects (both players would be on the same side). + [AddComponentMenu("")] + public class NetworkManagerPong : NetworkManager { - // add player at correct spawn position - Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; - GameObject player = Instantiate(playerPrefab, start.position, start.rotation); - NetworkServer.AddPlayerForConnection(conn, player); + public Transform leftRacketSpawn; + public Transform rightRacketSpawn; + GameObject ball; - // spawn ball if two players - if (numPlayers == 2) + public override void OnServerAddPlayer(NetworkConnection conn) { - ball = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "Ball")); - NetworkServer.Spawn(ball); + // add player at correct spawn position + Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn; + GameObject player = Instantiate(playerPrefab, start.position, start.rotation); + NetworkServer.AddPlayerForConnection(conn, player); + + // spawn ball if two players + if (numPlayers == 2) + { + ball = Instantiate(spawnPrefabs.Find(prefab => prefab.name == "Ball")); + NetworkServer.Spawn(ball); + } + } + + public override void OnServerDisconnect(NetworkConnection conn) + { + // destroy ball + if (ball != null) + NetworkServer.Destroy(ball); + + // call base functionality (actually destroys the player) + base.OnServerDisconnect(conn); } } - - public override void OnServerDisconnect(NetworkConnection conn) - { - // destroy ball - if (ball != null) - NetworkServer.Destroy(ball); - - // call base functionality (actually destroys the player) - base.OnServerDisconnect(conn); - } }