using System.Collections; using UnityEngine; namespace Mirror.Examples.MultipleMatch { [AddComponentMenu("")] public class MatchNetworkManager : NetworkManager { [Header("Match GUI")] public GameObject canvas; public CanvasController canvasController; /// /// Runs on both Server and Client /// Networking is NOT initialized when this fires /// public override void Awake() { base.Awake(); canvasController.InitializeData(); } #region Server System Callbacks /// /// 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(NetworkConnectionToClient conn) { base.OnServerReady(conn); canvasController.OnServerReady(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(NetworkConnectionToClient conn) { StartCoroutine(DoServerDisconnect(conn)); } IEnumerator DoServerDisconnect(NetworkConnectionToClient conn) { yield return canvasController.OnServerDisconnect(conn); base.OnServerDisconnect(conn); } #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. /// public override void OnClientConnect() { base.OnClientConnect(); canvasController.OnClientConnect(); } /// /// 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. /// public override void OnClientDisconnect() { canvasController.OnClientDisconnect(); base.OnClientDisconnect(); } #endregion #region Start & Stop Callbacks /// /// 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() { if (mode == NetworkManagerMode.ServerOnly) canvas.SetActive(true); canvasController.OnStartServer(); } /// /// This is invoked when the client is started. /// public override void OnStartClient() { canvas.SetActive(true); canvasController.OnStartClient(); } /// /// This is called when a server is stopped - including when a host is stopped. /// public override void OnStopServer() { canvasController.OnStopServer(); canvas.SetActive(false); } /// /// This is called when a client is stopped. /// public override void OnStopClient() { canvasController.OnStopClient(); } #endregion } }