AuthorityNetworkManager.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Linq;
  2. namespace Mirror.Examples.TanksCoop
  3. {
  4. public class AuthorityNetworkManager : NetworkManager
  5. {
  6. public static new AuthorityNetworkManager singleton { get; private set; }
  7. /// <summary>
  8. /// Runs on both Server and Client
  9. /// Networking is NOT initialized when this fires
  10. /// </summary>
  11. public override void Awake()
  12. {
  13. base.Awake();
  14. singleton = this;
  15. }
  16. /// <summary>
  17. /// Called on the server when a client disconnects.
  18. /// <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>
  19. /// </summary>
  20. /// <param name="conn">Connection from client.</param>
  21. public override void OnServerDisconnect(NetworkConnectionToClient conn)
  22. {
  23. // this code is to reset any objects belonging to disconnected clients
  24. // make a copy because the original collection will change in the loop
  25. NetworkIdentity[] copyOfOwnedObjects = conn.owned.ToArray();
  26. // Loop the copy, skipping the player object.
  27. // RemoveClientAuthority on everything else
  28. foreach (NetworkIdentity identity in copyOfOwnedObjects)
  29. {
  30. if (identity != conn.identity)
  31. identity.RemoveClientAuthority();
  32. }
  33. base.OnServerDisconnect(conn);
  34. }
  35. }
  36. }