using UnityEngine;
using UnityEngine.SceneManagement;
using Mirror;
/*
Documentation: https://mirror-networking.gitbook.io/docs/components/network-manager
API Reference: https://mirror-networking.com/docs/api/Mirror.NetworkManager.html
*/
public class #SCRIPTNAME# : NetworkManager
{
#region Unity Callbacks
public override void OnValidate()
{
base.OnValidate();
}
///
/// Runs on both Server and Client
/// Networking is NOT initialized when this fires
///
public override void Awake()
{
base.Awake();
}
///
/// Runs on both Server and Client
/// Networking is NOT initialized when this fires
///
public override void Start()
{
base.Start();
}
///
/// Runs on both Server and Client
///
public override void LateUpdate()
{
base.LateUpdate();
}
///
/// Runs on both Server and Client
///
public override void OnDestroy()
{
base.OnDestroy();
}
#endregion
#region Start & Stop
///
/// Set the frame rate for a headless server.
/// Override if you wish to disable the behavior or set your own tick rate.
///
public override void ConfigureServerFrameRate()
{
base.ConfigureServerFrameRate();
}
///
/// called when quitting the application by closing the window / pressing stop in the editor
///
public override void OnApplicationQuit()
{
base.OnApplicationQuit();
}
#endregion
#region Scene Management
///
/// This causes the server to switch scenes and sets the networkSceneName.
/// Clients that connect to this server will automatically switch to this scene. This is called automatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.
///
///
public override void ServerChangeScene(string newSceneName)
{
base.ServerChangeScene(newSceneName);
}
///
/// Called from ServerChangeScene immediately before SceneManager.LoadSceneAsync is executed
/// This allows server to do work / cleanup / prep before the scene changes.
///
/// Name of the scene that's about to be loaded
public override void OnServerChangeScene(string newSceneName) { }
///
/// Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene().
///
/// The name of the new scene.
public override void OnServerSceneChanged(string sceneName) { }
///
/// Called from ClientChangeScene immediately before SceneManager.LoadSceneAsync is executed
/// This allows client to do work / cleanup / prep before the scene changes.
///
/// Name of the scene that's about to be loaded
/// Scene operation that's about to happen
/// true to indicate that scene loading will be handled through overrides
public override void OnClientChangeScene(string newSceneName, SceneOperation sceneOperation, bool customHandling) { }
///
/// Called on clients when a scene has completed loaded, when the scene load was initiated by the server.
/// Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.
///
/// The network connection that the scene change message arrived on.
public override void OnClientSceneChanged(NetworkConnection conn)
{
base.OnClientSceneChanged(conn);
}
#endregion
#region Server System Callbacks
///
/// Called on the server when a new client connects.
/// Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.
///
/// Connection from client.
public override void OnServerConnect(NetworkConnection conn) { }
///
/// Called on the server when a client is ready.
/// The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.
///
/// Connection from client.
public override void OnServerReady(NetworkConnection conn)
{
base.OnServerReady(conn);
}
///
/// Called on the server when a client adds a new player with ClientScene.AddPlayer.
/// The default implementation for this function creates a new player object from the playerPrefab.
///
/// Connection from client.
public override void OnServerAddPlayer(NetworkConnection conn)
{
base.OnServerAddPlayer(conn);
}
///
/// Called on the server when a client disconnects.
/// 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.
///
/// Connection from client.
public override void OnServerDisconnect(NetworkConnection conn)
{
base.OnServerDisconnect(conn);
}
///
/// Called on server when transport raises an exception.
/// NetworkConnection may be null.
///
/// Connection of the client...may be null
/// Exception thrown from the Transport.
public override void OnServerError(NetworkConnection conn, Exception exception) { }
#endregion
#region Client System Callbacks
///
/// Called on the client when connected to a server.
/// The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.
///
/// Connection to the server.
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
}
///
/// Called on clients when disconnected from a server.
/// This is called on the client when it disconnects from the server. Override this function to decide what happens when the client disconnects.
///
/// Connection to the server.
public override void OnClientDisconnect(NetworkConnection conn)
{
base.OnClientDisconnect(conn);
}
///
/// Called on clients when a servers tells the client it is no longer ready.
/// This is commonly used when switching scenes.
///
/// Connection to the server.
public override void OnClientNotReady(NetworkConnection conn) { }
///
/// Called on client when transport raises an exception.
///
/// Exception thrown from the Transport.
public override void OnClientError(Exception exception) { }
#endregion
#region Start & Stop Callbacks
// Since there are multiple versions of StartServer, StartClient and StartHost, to reliably customize
// their functionality, users would need override all the versions. Instead these callbacks are invoked
// from all versions, so users only need to implement this one case.
///
/// This is invoked when a host is started.
/// StartHost has multiple signatures, but they all cause this hook to be called.
///
public override void OnStartHost() { }
///
/// This is invoked when a server is started - including when a host is started.
/// StartServer has multiple signatures, but they all cause this hook to be called.
///
public override void OnStartServer() { }
///
/// This is invoked when the client is started.
///
public override void OnStartClient() { }
///
/// This is called when a host is stopped.
///
public override void OnStopHost() { }
///
/// This is called when a server is stopped - including when a host is stopped.
///
public override void OnStopServer() { }
///
/// This is called when a client is stopped.
///
public override void OnStopClient() { }
#endregion
}