using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; namespace Multiplayer { public class ClientLoginManager { private ClientManager ClientManager; public ClientLoginManager(ClientManager ClientManager) { this.ClientManager = ClientManager; RegisterHandlers(); } private void RegisterHandlers() { ClientManager.Client.RegisterHandler(MsgType.Connect, OnConnected); ClientManager.Client.RegisterHandler(MsgType.Disconnect, OnDisconnected); ClientManager.Client.RegisterHandler(LoginMsgID.QueryName, OnRecieveID); } private void OnConnected(NetworkMessage msg) { ClientManager.IsConnected = true; Debug.Log("Successfully connected to server"); } private void OnDisconnected(NetworkMessage msg) { ClientManager.IsConnected = false; Debug.Log("Disconnected from Server"); } private void OnRecieveID(NetworkMessage msg) { PlayerMsg playerMsg; if (!Utility.ReadMessage(msg, out playerMsg)) return; Debug.Log("Recieved ID from server: " + playerMsg.ID); ClientManager.ID = playerMsg.ID; ClientManager.SendMessage(LoginMsgID.Name, new StringMsg(ClientManager.ID, ClientManager.Name)); } private void GoToLobby() { UnityEngine.SceneManagement.SceneManager.LoadScene(ClientManager.LobbyScene); } } }