mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 04:42:13 +01:00
fixed inputfields
This commit is contained in:
@@ -34,6 +34,7 @@ public class InputValidator : MonoBehaviour
|
|||||||
|
|
||||||
private void ValueChangeCheck()
|
private void ValueChangeCheck()
|
||||||
{
|
{
|
||||||
|
//IP
|
||||||
if(InputType == TypeOfInput.IP)
|
if(InputType == TypeOfInput.IP)
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
@@ -98,6 +99,7 @@ public class InputValidator : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// USERNAME
|
||||||
if (InputType == TypeOfInput.Username)
|
if (InputType == TypeOfInput.Username)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ public class MenuStartClient : MonoBehaviour
|
|||||||
[SerializeField] private TMP_InputField UsernameInput;
|
[SerializeField] private TMP_InputField UsernameInput;
|
||||||
public void StartClient()
|
public void StartClient()
|
||||||
{
|
{
|
||||||
if(UsernameInput.text != null)
|
if(UsernameInput.text != "")
|
||||||
{
|
{
|
||||||
Debug.Log("[MENU] Starting client...");
|
Debug.Log("[MENU] Starting client...");
|
||||||
|
|
||||||
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.text;
|
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.text;
|
||||||
|
|
||||||
NetworkManager.singleton.networkAddress = IpInput.text;
|
NetworkManager.singleton.networkAddress = IpInput.text;
|
||||||
NetworkManager.singleton.StartClient();
|
if(IpInput.text != "")
|
||||||
|
{
|
||||||
|
NetworkManager.singleton.StartClient();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class MenuStartHost : MonoBehaviour
|
|||||||
[SerializeField] private TMP_InputField UsernameInput;
|
[SerializeField] private TMP_InputField UsernameInput;
|
||||||
public void StartHost()
|
public void StartHost()
|
||||||
{
|
{
|
||||||
if (UsernameInput.text != null)
|
if (UsernameInput.text != "")
|
||||||
{
|
{
|
||||||
Debug.Log("[MENU] Starting host...");
|
Debug.Log("[MENU] Starting host...");
|
||||||
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.text;
|
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.text;
|
||||||
|
|||||||
@@ -19,22 +19,25 @@ using TMPro;
|
|||||||
public class Lobby : NetworkBehaviour
|
public class Lobby : NetworkBehaviour
|
||||||
{
|
{
|
||||||
NetManagerScript networkManager;
|
NetManagerScript networkManager;
|
||||||
List<Player> Players = new List<Player>();
|
public bool isLobbyScene;
|
||||||
|
|
||||||
|
//Player Lists
|
||||||
|
[SyncVar]
|
||||||
|
public List<Player> Players = new List<Player>();
|
||||||
|
[SyncVar]
|
||||||
|
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>(); // All player a register themselves when they join (LobbyPlayer.cs)
|
||||||
|
|
||||||
|
//Scene switch to in-game
|
||||||
[SerializeField] GameObject GamePlayerPrefab;
|
[SerializeField] GameObject GamePlayerPrefab;
|
||||||
[SerializeField] [Scene] string gameScene;
|
[SerializeField] [Scene] string gameScene;
|
||||||
|
|
||||||
// Sync Vars
|
//Lobby Scene
|
||||||
[SyncVar] //A list of all connected player
|
|
||||||
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>(); // All player a register themselves when they join (LobbyPlayer.cs)
|
|
||||||
|
|
||||||
[SyncVar(hook = "ChangeTitle")]
|
[SyncVar(hook = "ChangeTitle")]
|
||||||
[SerializeField] string lobbyTitle; // Title/Name of the Lobby; Can only be changed by the host, because of "AuthHost"
|
[SerializeField] string lobbyTitle; // Title/Name of the Lobby; Can only be changed by the host, because of "AuthHost"
|
||||||
|
|
||||||
[SyncVar]
|
[SyncVar]
|
||||||
public bool allReady = false; // All players are ready?
|
public bool allReady = false; // All players are ready?
|
||||||
|
|
||||||
public bool isLobbyScene;
|
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
DontDestroyOnLoad(this);
|
DontDestroyOnLoad(this);
|
||||||
@@ -55,12 +58,12 @@ public class Lobby : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CheckPlayers();
|
CheckPlayers();// Checking the Player List
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ChangeToPlayer(LobbyPlayer lobbyPlayer)
|
public void ChangeToPlayer(LobbyPlayer lobbyPlayer) //Convert/Change the LobbyPlayer to a Player
|
||||||
{
|
{
|
||||||
Debug.Log("Change");
|
Debug.Log("Change");
|
||||||
var conn = lobbyPlayer.connectionToClient;
|
var conn = lobbyPlayer.connectionToClient;
|
||||||
@@ -73,14 +76,24 @@ public class Lobby : NetworkBehaviour
|
|||||||
NetworkServer.ReplacePlayerForConnection(conn, newPlayerInstance.gameObject);
|
NetworkServer.ReplacePlayerForConnection(conn, newPlayerInstance.gameObject);
|
||||||
LobbyPlayers.Remove(lobbyPlayer);
|
LobbyPlayers.Remove(lobbyPlayer);
|
||||||
Players.Add(newPlayerInstance.gameObject.GetComponent<Player>());
|
Players.Add(newPlayerInstance.gameObject.GetComponent<Player>());
|
||||||
//NetworkServer.Spawn(newPlayerInstance.gameObject, conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartGame() // initializes the In-Game Scene and converts LobbyPlayers to GamePlayers
|
|
||||||
{
|
|
||||||
Debug.Log("START");
|
|
||||||
// https://youtu.be/HZIzGLe-2f4?t=586
|
|
||||||
|
|
||||||
|
void CheckPlayers()
|
||||||
|
{
|
||||||
|
foreach (Player player in Players)
|
||||||
|
{
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
Players.Remove(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region InLobbyScene
|
||||||
|
public void StartGame() // initializes the In-Game Scene
|
||||||
|
{
|
||||||
networkManager.ServerChangeScene(gameScene);
|
networkManager.ServerChangeScene(gameScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,19 +115,15 @@ public class Lobby : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterLobbyPlayer(LobbyPlayer player) // Where a Player can register himself
|
public void RegisterLobbyPlayer(LobbyPlayer player) // Where a LobbyPlayer can register himself
|
||||||
{
|
{
|
||||||
LobbyPlayers.Add(player);
|
LobbyPlayers.Add(player);
|
||||||
}
|
}
|
||||||
|
public void UnregisterLobbyPlayer(LobbyPlayer player) // Where a LobbyPlayer can unregister himself
|
||||||
public void RegisterPlayer(Player player) // Where a Player can register himself
|
|
||||||
{
|
{
|
||||||
Players.Add(player);
|
LobbyPlayers.Remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region checks
|
|
||||||
/* Checks */
|
/* Checks */
|
||||||
bool CheckAllReady() // Checks if all players are ready
|
bool CheckAllReady() // Checks if all players are ready
|
||||||
{
|
{
|
||||||
@@ -140,19 +149,6 @@ public class Lobby : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckPlayers()
|
|
||||||
{
|
|
||||||
foreach (Player player in Players)
|
|
||||||
{
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
Players.Remove(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region hooks
|
|
||||||
/* HOOKS */
|
/* HOOKS */
|
||||||
void ChangeTitle(string oldTitle, string newTitle) // Changes the Title Object
|
void ChangeTitle(string oldTitle, string newTitle) // Changes the Title Object
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class LobbyPlayer : NetworkBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
if (isLocalPlayer && SceneManager.GetActiveScene().name == "Lobby") // Needs to check Scene for itself -> it starts faster than the lobby
|
if (isLocalPlayer && SceneManager.GetActiveScene().name == "Lobby") // Needs to check Scene for itself -> it starts faster than the lobby
|
||||||
{
|
{
|
||||||
@@ -78,7 +78,6 @@ public class LobbyPlayer : NetworkBehaviour
|
|||||||
lobby.SetTitle(this, "Game Of\n" + username);
|
lobby.SetTitle(this, "Game Of\n" + username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if (isLocalPlayer && lobby.isLobbyScene)
|
if (isLocalPlayer && lobby.isLobbyScene)
|
||||||
@@ -108,7 +107,7 @@ public class LobbyPlayer : NetworkBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region hooks
|
#region hooks
|
||||||
/* HOOKS */
|
/* HOOKS */
|
||||||
public void DisplayPlayerName(string oldName, string newName) // Changes the text value of the Player-Username-GameObject
|
public void DisplayPlayerName(string oldName, string newName) // Changes the text value of the Player-Username-GameObject
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class Player : NetworkBehaviour
|
|||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
|
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
|
||||||
lobby.RegisterPlayer(this);
|
|
||||||
|
|
||||||
/*GameManager = GameObject.Find("MatchController");
|
/*GameManager = GameObject.Find("MatchController");
|
||||||
gameMaster = GameManager.GetComponent<GameMaster>();
|
gameMaster = GameManager.GetComponent<GameMaster>();
|
||||||
|
|||||||
Reference in New Issue
Block a user