Browse Source

push from home

Josh_Dev_branch
Joshua Reason 5 years ago
parent
commit
9209d5aef5
4 changed files with 2766 additions and 798 deletions
  1. +2637
    -791
      Assets/Scenes/Client Scenes/LoginScreen.unity
  2. +35
    -6
      Assets/Scripts/Networking/Client/ClientLoginManager.cs
  3. +93
    -1
      Assets/Scripts/UI/Client/LoginUIManager.cs
  4. +1
    -0
      Assets/Scripts/UI/Lobby/LobbyUIController.cs

+ 2637
- 791
Assets/Scenes/Client Scenes/LoginScreen.unity
File diff suppressed because it is too large
View File


+ 35
- 6
Assets/Scripts/Networking/Client/ClientLoginManager.cs View File

@ -38,8 +38,21 @@ namespace Networking.Client
[Tooltip("Reference to actual Client")]
protected ClientObject Client;
[Header("Debug")]
[SerializeField]
[Tooltip("Send prefilled Player settings after connecting")]
private bool IdentifyOnConnect = false;
#endregion Inspector Fields
#region Events
public System.Action OnConnectedToServer;
public System.Action OnLoginSucess;
public System.Action OnLoginFail;
#endregion Events
#region Private variables
#endregion Private variables
@ -72,27 +85,43 @@ namespace Networking.Client
public void RegisterHandlers()
{
Client.client.RegisterHandler(LoginProtocols.RequestLoginDetails, LoginRecieved);
Client.client.RegisterHandler(LoginProtocols.RequestLoginDetails, ConnectedToServer);
Client.client.RegisterHandler(LoginProtocols.LoginSuccess, LoginSucess);
Client.client.RegisterHandler(LoginProtocols.LoginFail, LoginFail);
}
public void LoginRecieved(NetworkMessage msg)
public void ConnectedToServer(NetworkMessage msg)
{
Debug.Log("Connected to Server. Sending login details");
Debug.Log("Connected to Server.");
OnConnectedToServer.Invoke();
if (IdentifyOnConnect)
SendPlayerDetails(DisplayName,PlayerColor);
}
public void SendPlayerDetails(string name, Color color)
{
Debug.Log("Sending player Details.");
DisplayName = name;
PlayerColor = color;
Client.client.Send(LoginProtocols.SendingLoginDetails, new LoginProtocols.LoginMsg(DisplayName, PlayerColor));
}
public void LoginSucess(NetworkMessage msg)
{
Debug.Log("Log in successful");
Debug.Log("Log in successful!");
OnLoginSucess.Invoke();
Client.UpdatePlayerDetails(DisplayName, PlayerColor);
//UnityEngine.SceneManagement.SceneManager.LoadScene(LevelToLoad);
}
public void LoginFail(NetworkMessage msg)
{
Debug.Log("Log in failed");
Debug.Log("Log in failed!");
OnLoginFail.Invoke();
Client.Stop();
}

+ 93
- 1
Assets/Scripts/UI/Client/LoginUIManager.cs View File

@ -6,20 +6,86 @@ using TMPro;
public class LoginUIManager : MonoBehaviour
{
[Header("References")]
[SerializeField]
private ClientLoginManager clientManager;
[SerializeField]
private TextMeshProUGUI Title;
[SerializeField]
private GameObject Content;
[Header("Connection")]
[SerializeField]
private string ConnectionTitle = "Connect to Server";
[SerializeField]
private GameObject ConnectionObject;
[Header("PlayerDetails")]
[SerializeField]
private string DetailsTitle = "Player Details";
[SerializeField]
private GameObject DetailsObject;
[Header("WaitForPlayers")]
[SerializeField]
private string WaitTitle = "Wait for Players";
private string serverAddress;
private int serverPort;
private string playerName;
private Color playerColor;
#region Unity Functions
private void OnEnable()
{
clientManager.OnConnectedToServer += OnConnect;
clientManager.OnLoginSucess += OnLogin;
clientManager.OnLoginFail += OnLoginFail;
}
private void OnDisable()
{
clientManager.OnConnectedToServer -= OnConnect;
clientManager.OnLoginSucess -= OnLogin;
clientManager.OnLoginFail -= OnLoginFail;
}
private void Start()
{
serverAddress = PlayerPrefs.GetString("LastUsedAddress", "");
serverPort = PlayerPrefs.GetInt("LastUsedPort", 2222);
playerName = PlayerPrefs.GetString("LastUsedName");
}
#endregion Unity Functions
#region Event Functions
public void OnConnect()
{
Title.text = DetailsTitle;
CloseAll();
DetailsObject.SetActive(true);
}
public void OnLogin()
{
Title.text = WaitTitle;
CloseAll();
}
public void OnLoginFail()
{
Title.text = ConnectionTitle;
CloseAll();
ConnectionObject.SetActive(true);
}
#endregion Event Functions
#region UI Functionality
public void OnChange_ServerAddress(string serverAddress)
{
this.serverAddress = serverAddress;
@ -30,7 +96,7 @@ public class LoginUIManager : MonoBehaviour
this.serverPort = int.Parse(serverPort);
}
public void OnClickConnect()
public void OnClick_Connect()
{
clientManager.StartClient(serverAddress, serverPort);
PlayerPrefs.SetString("LastUsedAddress", serverAddress);
@ -38,5 +104,31 @@ public class LoginUIManager : MonoBehaviour
PlayerPrefs.Save();
}
public void OnClick_Done()
{
clientManager.SendPlayerDetails(playerName, playerColor);
PlayerPrefs.SetString("LastUsedName", playerName);
}
public void OnClick_Color(Color playerColor)
{
this.playerColor = playerColor;
}
public void OnChange_Name(string playerName)
{
this.playerName = playerName;
}
#endregion UI Functionality
#region Helper Functions
private void CloseAll()
{
foreach (Transform child in Content.transform)
child.gameObject.SetActive(false);
}
#endregion Helper Functions
}

+ 1
- 0
Assets/Scripts/UI/Lobby/LobbyUIController.cs View File

@ -26,6 +26,7 @@ public class LobbyUIController : MonoBehaviour
[SerializeField]
private GameObject ClientTag;
// Start is called before the first frame update
void Start()
{

Loading…
Cancel
Save