From 80722657971b16779ac8124105b6c35283cbf802 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Wed, 15 Dec 2021 00:18:24 +0100 Subject: [PATCH] Ready Up and Clean Up --- Assets/Scenes/HomeScene.unity | 12 +- Assets/Scenes/Lobby.unity | 28 ++++ Assets/Scripts/HomeMenu/Lobby/Lobby.cs | 85 +++++++++-- Assets/Scripts/HomeMenu/Lobby/LobbyPlayer.cs | 150 ++++++++++++++----- Assets/{UI.meta => Scripts/Lobby.meta} | 2 +- Assets/Scripts/Lobby/LobbyStartGame.cs | 18 +++ Assets/Scripts/Lobby/LobbyStartGame.cs.meta | 11 ++ Assets/UI/Home.meta | 8 - UserSettings/Layouts/default-2021.dwlt | 130 ++++++++-------- 9 files changed, 317 insertions(+), 127 deletions(-) rename Assets/{UI.meta => Scripts/Lobby.meta} (77%) create mode 100644 Assets/Scripts/Lobby/LobbyStartGame.cs create mode 100644 Assets/Scripts/Lobby/LobbyStartGame.cs.meta delete mode 100644 Assets/UI/Home.meta diff --git a/Assets/Scenes/HomeScene.unity b/Assets/Scenes/HomeScene.unity index 47b84c0..ed562ce 100644 --- a/Assets/Scenes/HomeScene.unity +++ b/Assets/Scenes/HomeScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -1100,7 +1100,7 @@ Camera: m_GameObject: {fileID: 958699927} m_Enabled: 1 serializedVersion: 2 - m_ClearFlags: 1 + m_ClearFlags: 3 m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} m_projectionMatrixMode: 1 m_GateFitMode: 2 @@ -1122,7 +1122,7 @@ Camera: m_Depth: -1 m_CullingMask: serializedVersion: 2 - m_Bits: 4294967295 + m_Bits: 32 m_RenderingPath: -1 m_TargetTexture: {fileID: 0} m_TargetDisplay: 0 @@ -1604,7 +1604,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &1223089884 RectTransform: m_ObjectHideFlags: 0 @@ -2094,7 +2094,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.17254902, g: 0.18431373, b: 0.2, a: 1} + m_Color: {r: 0.13314347, g: 0.13314347, b: 0.1509434, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 @@ -2203,7 +2203,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1813956224 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index b8c17cd..081389a 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -993,6 +993,10 @@ PrefabInstance: propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState value: 2 objectReference: {fileID: 0} + - target: {fileID: 8076035533974620946, guid: a973691757099224ca132b32daabf67c, type: 3} + propertyPath: m_Name + value: RdyBtnText + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: a973691757099224ca132b32daabf67c, type: 3} --- !u!224 &594583494 stripped @@ -1000,6 +1004,17 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 2454942472495841689, guid: a973691757099224ca132b32daabf67c, type: 3} m_PrefabInstance: {fileID: 594583493} m_PrefabAsset: {fileID: 0} +--- !u!114 &594583495 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1513820883277351791, guid: a973691757099224ca132b32daabf67c, type: 3} + m_PrefabInstance: {fileID: 594583493} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &949082596 GameObject: m_ObjectHideFlags: 0 @@ -1238,6 +1253,11 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1185775522} m_CullTransparentMesh: 1 +--- !u!1 &1197550804 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 759482234963316101, guid: a973691757099224ca132b32daabf67c, type: 3} + m_PrefabInstance: {fileID: 594583493} + m_PrefabAsset: {fileID: 0} --- !u!1 &1234182190 GameObject: m_ObjectHideFlags: 0 @@ -2330,6 +2350,14 @@ PrefabInstance: propertyPath: sceneId value: 2342159728 objectReference: {fileID: 0} + - target: {fileID: 7129514368576730103, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3} + propertyPath: rdyButton + value: + objectReference: {fileID: 1197550804} + - target: {fileID: 7129514368576730103, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3} + propertyPath: rdyButtonText + value: + objectReference: {fileID: 594583495} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: af2b86e6ca1c8404a857e6bfa4294f3c, type: 3} --- !u!1001 &7946605864942981377 diff --git a/Assets/Scripts/HomeMenu/Lobby/Lobby.cs b/Assets/Scripts/HomeMenu/Lobby/Lobby.cs index 83235a9..fa9b0ef 100644 --- a/Assets/Scripts/HomeMenu/Lobby/Lobby.cs +++ b/Assets/Scripts/HomeMenu/Lobby/Lobby.cs @@ -1,26 +1,62 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; using Mirror; using TMPro; + + +/* TODO: + * - Changing Lobby Title Objects causes bugs on client + */ + + +/* + * The Lobby Class is used to give all LobbyPlayer an instance above them for managing purposes. + * You could write this into a NetworkManager, but I thought it would be nicer in a seperate script. + */ + public class Lobby : NetworkBehaviour { - [SerializeField] - public List LobbyPlayers = new List(); + // Sync Vars + [SyncVar] //A list of all connected player + public List LobbyPlayers = new List(); // All player a register themselves when they join (LobbyPlayer.cs) [SyncVar(hook = "ChangeTitle")] - [SerializeField] private string lobbyTitle; + [SerializeField] string lobbyTitle; // Title/Name of the Lobby; Can only be changed by the host, because of "AuthHost" - public bool AuthHost(LobbyPlayer player) + [SyncVar] + public bool allReady = false; // All players are ready? + + + void Update() { - if(LobbyPlayers.IndexOf(player) == 0) + CheckLobbyPlayers(); // Checking the LobbyPlayer List + allReady = CheckAllReady(); // Continous checking if all player are ready + } + + public void StartGame() // initializes the In-Game Scene and converts LobbyPlayers to GamePlayers + { + Debug.Log("START"); + /* https://youtu.be/HZIzGLe-2f4?t=586 + * Start Loading Panel + * Destroy LobbyPlayer + * Instatiate Player Objects and connect them to "conn" + * Switch Scene + */ + } + + #region LobbyPlayer Interaction (Public) + /* Public (Where the LobbyPlayer interacts with) */ + public bool AuthHost(LobbyPlayer player) // Checks if player is the host + { + // In theory the host should always be the first connected player, which means he is index 0 in the LobbyPlayers-List + if (LobbyPlayers.IndexOf(player) == 0) { return true; } return false; } - public void SetTitle(LobbyPlayer player, string text) + public void SetTitle(LobbyPlayer player, string text) // the host can set the LobbyTitle { if (AuthHost(player)) { @@ -28,13 +64,44 @@ public class Lobby : NetworkBehaviour } } - public void RegisterPlayer(LobbyPlayer player) + public void RegisterPlayer(LobbyPlayer player) // Where a Player can register himself { LobbyPlayers.Add(player); } + #endregion - public void ChangeTitle(string oldTitle, string newTitle) + #region checks + /* Checks */ + bool CheckAllReady() // Checks if all players are ready + { + // Check if all players are ready (if a player is not ready) + foreach (LobbyPlayer player in LobbyPlayers) + { + if (!player.ready) + { + return false; + } + } + return true; + } + + void CheckLobbyPlayers() // Checks if all LobbyPlayers in the list are still connected (having a GameObject) -> Clears missing players + { + foreach(LobbyPlayer player in LobbyPlayers) + { + if (player == null) + { + LobbyPlayers.Remove(player); + } + } + } + #endregion + + #region hooks + /* HOOKS */ + void ChangeTitle(string oldTitle, string newTitle) // Changes the Title Object { GameObject.Find("title").GetComponent().text = newTitle; } + #endregion } diff --git a/Assets/Scripts/HomeMenu/Lobby/LobbyPlayer.cs b/Assets/Scripts/HomeMenu/Lobby/LobbyPlayer.cs index 795957d..111b212 100644 --- a/Assets/Scripts/HomeMenu/Lobby/LobbyPlayer.cs +++ b/Assets/Scripts/HomeMenu/Lobby/LobbyPlayer.cs @@ -1,74 +1,116 @@ -using Mirror; using UnityEngine; +using UnityEngine.UI; // For