BasicNetManager.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. namespace Mirror.Examples.Basic
  3. {
  4. [AddComponentMenu("")]
  5. public class BasicNetManager : NetworkManager
  6. {
  7. public static new BasicNetManager singleton { get; private set; }
  8. /// <summary>
  9. /// Runs on both Server and Client
  10. /// Networking is NOT initialized when this fires
  11. /// </summary>
  12. public override void Awake()
  13. {
  14. base.Awake();
  15. singleton = this;
  16. }
  17. /// <summary>
  18. /// Called on the server when a client adds a new player with NetworkClient.AddPlayer.
  19. /// <para>The default implementation for this function creates a new player object from the playerPrefab.</para>
  20. /// </summary>
  21. /// <param name="conn">Connection from client.</param>
  22. public override void OnServerAddPlayer(NetworkConnectionToClient conn)
  23. {
  24. base.OnServerAddPlayer(conn);
  25. Player.ResetPlayerNumbers();
  26. }
  27. /// <summary>
  28. /// Called on the server when a client disconnects.
  29. /// <para>This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.</para>
  30. /// </summary>
  31. /// <param name="conn">Connection from client.</param>
  32. public override void OnServerDisconnect(NetworkConnectionToClient conn)
  33. {
  34. base.OnServerDisconnect(conn);
  35. Player.ResetPlayerNumbers();
  36. }
  37. }
  38. }