ChatNetworkManager.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. namespace Mirror.Examples.Chat
  3. {
  4. [AddComponentMenu("")]
  5. public class ChatNetworkManager : NetworkManager
  6. {
  7. public static new ChatNetworkManager 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. // Called by UI element NetworkAddressInput.OnValueChanged
  18. public void SetHostname(string hostname)
  19. {
  20. networkAddress = hostname;
  21. }
  22. public override void OnServerDisconnect(NetworkConnectionToClient conn)
  23. {
  24. // remove player name from the HashSet
  25. if (conn.authenticationData != null)
  26. ChatAuthenticator.playerNames.Remove((string)conn.authenticationData);
  27. // remove connection from Dictionary of conn > names
  28. ChatUI.connNames.Remove(conn);
  29. base.OnServerDisconnect(conn);
  30. }
  31. public override void OnClientDisconnect()
  32. {
  33. base.OnClientDisconnect();
  34. LoginUI.instance.gameObject.SetActive(true);
  35. LoginUI.instance.usernameInput.text = "";
  36. LoginUI.instance.usernameInput.ActivateInputField();
  37. }
  38. }
  39. }