From f79def6c9d4501172b8b0b18164c3ffa8224ed77 Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Sat, 26 Jan 2019 17:50:39 +1100 Subject: [PATCH] Got Lobby working hopefully --- Assets/Scenes/ClientScene.unity | 3 +- Assets/Scenes/LobbyScene.unity | 36 +++- Assets/Scenes/TestScene.unity | 175 +----------------- .../Multiplayer/Client/ClientLoginManager.cs | 15 +- .../Scipts/Multiplayer/Client/LobbyManager.cs | 8 - .../Scipts/Multiplayer/Server/LoginManager.cs | 18 ++ .../Multiplayer/Server/ServerManager.cs | 9 - Assets/Scipts/UI.meta | 8 + Assets/Scipts/UI/LobbyUIController.cs | 11 ++ .../LobbyUIController.cs.meta} | 2 +- ProjectSettings/EditorBuildSettings.asset | 4 +- 11 files changed, 88 insertions(+), 201 deletions(-) delete mode 100644 Assets/Scipts/Multiplayer/Client/LobbyManager.cs create mode 100644 Assets/Scipts/UI.meta create mode 100644 Assets/Scipts/UI/LobbyUIController.cs rename Assets/Scipts/{Multiplayer/Client/LobbyManager.cs.meta => UI/LobbyUIController.cs.meta} (83%) diff --git a/Assets/Scenes/ClientScene.unity b/Assets/Scenes/ClientScene.unity index 24da03b..119338c 100644 --- a/Assets/Scenes/ClientScene.unity +++ b/Assets/Scenes/ClientScene.unity @@ -145,7 +145,8 @@ MonoBehaviour: ServerAddress: 10.17.38.221 Port: 4444 ConnectOnStart: 0 - GameSceneName: MainScene + LobbyScene: LobbyScene + GameScene: TestScene Name: The most nardish of players IsConnected: 0 ID: 0 diff --git a/Assets/Scenes/LobbyScene.unity b/Assets/Scenes/LobbyScene.unity index 4ce15ea..315d188 100644 --- a/Assets/Scenes/LobbyScene.unity +++ b/Assets/Scenes/LobbyScene.unity @@ -124,6 +124,7 @@ GameObject: - component: {fileID: 919644062} - component: {fileID: 919644061} - component: {fileID: 919644060} + - component: {fileID: 919644064} m_Layer: 5 m_Name: Canvas m_TagString: Untagged @@ -208,6 +209,17 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!114 &919644064 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 919644059} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 405724f17a9fdf7498f87dfdb5dbcb9e, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1007511397 GameObject: m_ObjectHideFlags: 0 @@ -284,7 +296,18 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1007511400} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 919644064} + m_MethodName: OnClickStartGame + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &1007511400 @@ -333,7 +356,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_AspectMode: 0 - m_AspectRatio: 3.3936446 + m_AspectRatio: 4.5044775 --- !u!1 &1535509334 GameObject: m_ObjectHideFlags: 0 @@ -363,10 +386,11 @@ MonoBehaviour: m_EditorClassIdentifier: SetSingletonOnAwake: 1 isPersistant: 1 - LocalPlayerPrefab: {fileID: 1359508890942550, guid: 88f2120ea01cef248ba929e8eea4c759, + LocalPlayerPrefab: {fileID: 1067952265812482, guid: db2d9f4b5a72e5a47a7dd9f0d1fa1e43, type: 2} - RemotePlayerPrefab: {fileID: 1737980672629790, guid: bdf6a76720f2a98408b6639537d99358, + RemotePlayerPrefab: {fileID: 1899238032005644, guid: 35b69a93d1dd9c24fbf2ba57dfc4aafb, type: 2} + LocalPlayer: {fileID: 0} --- !u!4 &1535509336 Transform: m_ObjectHideFlags: 0 @@ -600,7 +624,7 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 22.55 + m_fontSize: 30.05 m_fontSizeBase: 24 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -708,7 +732,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 196.71722, y: 0} + m_SizeDelta: {x: 0, y: 4.710968} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1973300969 MonoBehaviour: diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index 9778a1f..65a04f8 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -113,91 +113,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &6342918 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 6342922} - - component: {fileID: 6342921} - - component: {fileID: 6342920} - - component: {fileID: 6342919} - m_Layer: 0 - m_Name: Sphere (1) - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!135 &6342919 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 6342918} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &6342920 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 6342918} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 4294967295 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &6342921 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 6342918} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &6342922 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 6342918} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 10, y: 0, z: 10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 5 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &695038879 GameObject: m_ObjectHideFlags: 0 @@ -279,7 +194,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 695038879} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: -1.95, z: 0} m_LocalScale: {x: 2, y: 2, z: 2} m_Children: [] m_Father: {fileID: 0} @@ -428,91 +343,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 39.144, y: 0, z: 0} ---- !u!1 &1713353743 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1713353747} - - component: {fileID: 1713353746} - - component: {fileID: 1713353745} - - component: {fileID: 1713353744} - m_Layer: 0 - m_Name: Sphere - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!135 &1713353744 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1713353743} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &1713353745 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1713353743} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 4294967295 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &1713353746 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1713353743} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &1713353747 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1713353743} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -10, y: 0.04, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 4 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &2130458414 GameObject: m_ObjectHideFlags: 0 @@ -546,8 +376,7 @@ MonoBehaviour: type: 2} RemotePlayerPrefab: {fileID: 1737980672629790, guid: bdf6a76720f2a98408b6639537d99358, type: 2} - mapTop: {x: 10, y: 1, z: 10} - mapBot: {x: -10, y: 1, z: -10} + LocalPlayer: {fileID: 0} --- !u!4 &2130458416 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs index 9956b94..884b8c2 100644 --- a/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs +++ b/Assets/Scipts/Multiplayer/Client/ClientLoginManager.cs @@ -22,6 +22,8 @@ namespace Multiplayer ClientManager.Client.RegisterHandler(MsgType.Connect, OnConnected); ClientManager.Client.RegisterHandler(MsgType.Disconnect, OnDisconnected); ClientManager.Client.RegisterHandler(LoginMsgID.QueryName, OnRecieveID); + ClientManager.Client.RegisterHandler(LoginMsgID.EnterLobby, StartLobby); + ClientManager.Client.RegisterHandler(PlayerMsgID.GameStart, StartGame); } private void OnConnected(NetworkMessage msg) @@ -46,12 +48,23 @@ namespace Multiplayer ClientManager.ID = playerMsg.ID; ClientManager.SendMessage(LoginMsgID.Name, new StringMsg(ClientManager.ID, ClientManager.Name)); + StartLobby(); } - private void GoToLobby() + private void StartLobby(NetworkMessage msg) + { + StartLobby(); + } + + private void StartLobby() { UnityEngine.SceneManagement.SceneManager.LoadScene(ClientManager.LobbyScene); } + + private void StartGame(NetworkMessage msg) + { + UnityEngine.SceneManagement.SceneManager.LoadScene(ClientManager.GameScene); + } } } \ No newline at end of file diff --git a/Assets/Scipts/Multiplayer/Client/LobbyManager.cs b/Assets/Scipts/Multiplayer/Client/LobbyManager.cs deleted file mode 100644 index aa04016..0000000 --- a/Assets/Scipts/Multiplayer/Client/LobbyManager.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class LobbyManager : MonoBehaviour { - - -} diff --git a/Assets/Scipts/Multiplayer/Server/LoginManager.cs b/Assets/Scipts/Multiplayer/Server/LoginManager.cs index 5c10f02..debd814 100644 --- a/Assets/Scipts/Multiplayer/Server/LoginManager.cs +++ b/Assets/Scipts/Multiplayer/Server/LoginManager.cs @@ -23,6 +23,7 @@ namespace Multiplayer ServerManager.Server.RegisterHandler(LoginMsgID.Name, OnPlayerLogin); ServerManager.Server.RegisterHandler(MsgType.Connect, OnConnect); ServerManager.Server.RegisterHandler(MsgType.Disconnect, OnDisconnect); + ServerManager.Server.RegisterHandler(PlayerMsgID.GameStart, ClientStartsGame); } @@ -62,6 +63,23 @@ namespace Multiplayer else Debug.Log("Unkown player has disconnected."); } + + private void ClientStartsGame(NetworkMessage msg) + { + StartGame(); + } + + private void StartGame() + { + foreach (Player player in ServerManager.AllPlayers.Values) + player.Connection.Send(PlayerMsgID.GameStart, new PlayerMsg(player.ID)); + } + + private void GoToLobby() + { + foreach(Player player in ServerManager.AllPlayers.Values) + player.Connection.Send(PlayerMsgID.Lobby, new PlayerMsg(player.ID)); + } } } \ No newline at end of file diff --git a/Assets/Scipts/Multiplayer/Server/ServerManager.cs b/Assets/Scipts/Multiplayer/Server/ServerManager.cs index fc9f2cc..d71b598 100644 --- a/Assets/Scipts/Multiplayer/Server/ServerManager.cs +++ b/Assets/Scipts/Multiplayer/Server/ServerManager.cs @@ -52,15 +52,6 @@ namespace Multiplayer Server.Listen(Port); } - [ContextMenu("Start Game")] - public void StartGame() - { - foreach (Player player in AllPlayers.Values) - { - player.Connection.Send(PlayerMsgID.Lobby, new PlayerMsg(player.ID)); - } - } - private void Update() { if (Server != null) diff --git a/Assets/Scipts/UI.meta b/Assets/Scipts/UI.meta new file mode 100644 index 0000000..2d5eec6 --- /dev/null +++ b/Assets/Scipts/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 42c6d1b4eef6f6a429557011ae10993b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scipts/UI/LobbyUIController.cs b/Assets/Scipts/UI/LobbyUIController.cs new file mode 100644 index 0000000..f2488f9 --- /dev/null +++ b/Assets/Scipts/UI/LobbyUIController.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class LobbyUIController : MonoBehaviour { + + public void OnClickStartGame() + { + Multiplayer.ClientManager.Instance.SendMessage(Multiplayer.PlayerMsgID.GameStart, new Multiplayer.PlayerMsg(Multiplayer.ClientManager.Instance.ID)); + } +} diff --git a/Assets/Scipts/Multiplayer/Client/LobbyManager.cs.meta b/Assets/Scipts/UI/LobbyUIController.cs.meta similarity index 83% rename from Assets/Scipts/Multiplayer/Client/LobbyManager.cs.meta rename to Assets/Scipts/UI/LobbyUIController.cs.meta index 7a4e138..297e649 100644 --- a/Assets/Scipts/Multiplayer/Client/LobbyManager.cs.meta +++ b/Assets/Scipts/UI/LobbyUIController.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ad5b0dc1c78c8064b95e9ba337a3c50d +guid: 405724f17a9fdf7498f87dfdb5dbcb9e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 9daddb8..4bf0906 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f182faa74c5ed42826273c1aa3fa86e317c6b7e71f9d22f4ea0a329d03f90c21 -size 355 +oid sha256:c64c0a8ab387e76ea0a66bea48669e6993ffdbbc6c34f74a7fabe55bd6e8ca93 +size 552