|
|
@ -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
|
|
|
|
|
|
|
|
} |