mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
fixed inputfields
This commit is contained in:
@@ -34,6 +34,7 @@ public class InputValidator : MonoBehaviour
|
||||
|
||||
private void ValueChangeCheck()
|
||||
{
|
||||
//IP
|
||||
if(InputType == TypeOfInput.IP)
|
||||
{
|
||||
int counter = 0;
|
||||
@@ -98,6 +99,7 @@ public class InputValidator : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
// USERNAME
|
||||
if (InputType == TypeOfInput.Username)
|
||||
{
|
||||
|
||||
|
||||
@@ -8,14 +8,17 @@ public class MenuStartClient : MonoBehaviour
|
||||
[SerializeField] private TMP_InputField UsernameInput;
|
||||
public void StartClient()
|
||||
{
|
||||
if(UsernameInput.text != null)
|
||||
if(UsernameInput.text != "")
|
||||
{
|
||||
Debug.Log("[MENU] Starting client...");
|
||||
|
||||
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.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;
|
||||
public void StartHost()
|
||||
{
|
||||
if (UsernameInput.text != null)
|
||||
if (UsernameInput.text != "")
|
||||
{
|
||||
Debug.Log("[MENU] Starting host...");
|
||||
GameObject.FindGameObjectWithTag("VariableSaver").GetComponent<VariableSaver>().username = UsernameInput.text;
|
||||
|
||||
@@ -19,22 +19,25 @@ using TMPro;
|
||||
public class Lobby : NetworkBehaviour
|
||||
{
|
||||
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] [Scene] string gameScene;
|
||||
|
||||
// Sync Vars
|
||||
[SyncVar] //A list of all connected player
|
||||
public List<LobbyPlayer> LobbyPlayers = new List<LobbyPlayer>(); // All player a register themselves when they join (LobbyPlayer.cs)
|
||||
|
||||
//Lobby Scene
|
||||
[SyncVar(hook = "ChangeTitle")]
|
||||
[SerializeField] string lobbyTitle; // Title/Name of the Lobby; Can only be changed by the host, because of "AuthHost"
|
||||
|
||||
[SyncVar]
|
||||
public bool allReady = false; // All players are ready?
|
||||
|
||||
public bool isLobbyScene;
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
@@ -55,12 +58,12 @@ public class Lobby : NetworkBehaviour
|
||||
}
|
||||
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");
|
||||
var conn = lobbyPlayer.connectionToClient;
|
||||
@@ -73,14 +76,24 @@ public class Lobby : NetworkBehaviour
|
||||
NetworkServer.ReplacePlayerForConnection(conn, newPlayerInstance.gameObject);
|
||||
LobbyPlayers.Remove(lobbyPlayer);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
public void RegisterPlayer(Player player) // Where a Player can register himself
|
||||
public void UnregisterLobbyPlayer(LobbyPlayer player) // Where a LobbyPlayer can unregister himself
|
||||
{
|
||||
Players.Add(player);
|
||||
LobbyPlayers.Remove(player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region checks
|
||||
/* Checks */
|
||||
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 */
|
||||
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
|
||||
{
|
||||
@@ -78,7 +78,6 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
lobby.SetTitle(this, "Game Of\n" + username);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isLocalPlayer && lobby.isLobbyScene)
|
||||
@@ -108,7 +107,7 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region hooks
|
||||
/* HOOKS */
|
||||
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()
|
||||
{
|
||||
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
|
||||
lobby.RegisterPlayer(this);
|
||||
|
||||
/*GameManager = GameObject.Find("MatchController");
|
||||
gameMaster = GameManager.GetComponent<GameMaster>();
|
||||
|
||||
Reference in New Issue
Block a user