From e48e419c291ba022da3e48d3457bf2ed74dce4a5 Mon Sep 17 00:00:00 2001 From: JoshuaReason Date: Thu, 23 May 2019 16:18:06 +1000 Subject: [PATCH] fixed client inventory removing items + time is sent over by server --- Assets/Data/GameModes/ColorCollide.asset | 4 +- Assets/Scenes/Client Scenes/ClientScene.unity | 93 ++++++++++--------- Assets/Scripts/GameMode/GameMode.cs | 13 +++ Assets/Scripts/Managers/GameManager.cs | 3 + .../Core/Protocols/LogicProtocols.cs | 51 ++++++++++ Assets/Scripts/UI/NetworkedUIManager.cs | 24 ++++- 6 files changed, 139 insertions(+), 49 deletions(-) diff --git a/Assets/Data/GameModes/ColorCollide.asset b/Assets/Data/GameModes/ColorCollide.asset index ac156ab..3bd63a4 100644 --- a/Assets/Data/GameModes/ColorCollide.asset +++ b/Assets/Data/GameModes/ColorCollide.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e9ac3ad2b1266807e868377fa1c148c766f34904a0d06c0fcb93b523bb4e8298 -size 532 +oid sha256:25df2a78a63b91d5d6e0cd99283ff0e03bf82505fe6c3a31a840a43725e367e4 +size 582 diff --git a/Assets/Scenes/Client Scenes/ClientScene.unity b/Assets/Scenes/Client Scenes/ClientScene.unity index 85317c8..59bbb4b 100644 --- a/Assets/Scenes/Client Scenes/ClientScene.unity +++ b/Assets/Scenes/Client Scenes/ClientScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.44657868, g: 0.49641263, b: 0.57481706, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -221,6 +221,7 @@ MonoBehaviour: maxLength: 6 reader: LogicChain: [] + readerQueue: [] --- !u!114 &1324620582 stripped MonoBehaviour: m_CorrespondingSourceObject: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, @@ -683,41 +684,51 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: - - target: {fileID: 2584547907285081931, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + - target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} - propertyPath: m_isInputParsingRequired - value: 1 + propertyPath: m_Name + value: Player Canvas objectReference: {fileID: 0} - - target: {fileID: 4132265620032504676, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target - value: - objectReference: {fileID: 1324620581} - - target: {fileID: 4132265620032504676, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + - target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} - propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName - value: OnClick_Return + propertyPath: m_IsActive + value: 1 objectReference: {fileID: 0} - target: {fileID: 4080157917815310858, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_IsActive value: 0 objectReference: {fileID: 0} - - target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Name - value: Player Canvas - objectReference: {fileID: 0} - - target: {fileID: 5195354182462625300, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + - target: {fileID: 5195354183101525344, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} - - target: {fileID: 5195354183101525344, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} - propertyPath: m_IsActive + propertyPath: m_Color.r + value: 0.8862745 + objectReference: {fileID: 0} + - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_Color.g + value: 0.884576 + objectReference: {fileID: 0} + - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_Color.b + value: 0.88235295 + objectReference: {fileID: 0} + - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_Color.a value: 1 objectReference: {fileID: 0} + - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_Sprite + value: + objectReference: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0} - target: {fileID: 5195354181806561359, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AnchoredPosition.y @@ -733,6 +744,21 @@ PrefabInstance: propertyPath: m_AnchoredPosition.x value: -0.000015290107 objectReference: {fileID: 0} + - target: {fileID: 2584547907285081931, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_isInputParsingRequired + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4132265620032504676, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 1324620581} + - target: {fileID: 4132265620032504676, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, + type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: OnClick_Return + objectReference: {fileID: 0} - target: {fileID: 5195354182462625304, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_LocalPosition.x @@ -857,7 +883,7 @@ PrefabInstance: type: 3} propertyPath: inventory value: - objectReference: {fileID: 11400000, guid: eea1505cebc20b64b8c421ba71e10781, + objectReference: {fileID: 11400000, guid: 9f2bac6895147d444858493b9609d026, type: 2} - target: {fileID: 2665231842396078511, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} @@ -979,31 +1005,6 @@ PrefabInstance: propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName value: OnClick_Toggle objectReference: {fileID: 0} - - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Color.r - value: 0.8862745 - objectReference: {fileID: 0} - - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Color.g - value: 0.884576 - objectReference: {fileID: 0} - - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Color.b - value: 0.88235295 - objectReference: {fileID: 0} - - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Color.a - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 5195354183101525349, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, - type: 3} - propertyPath: m_Sprite - value: - objectReference: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0} - target: {fileID: 5195354183101525346, guid: 3fbc9b76d5c4f7348b60a029bc2ba63f, type: 3} propertyPath: m_AspectRatio diff --git a/Assets/Scripts/GameMode/GameMode.cs b/Assets/Scripts/GameMode/GameMode.cs index 70ac721..c7290f7 100644 --- a/Assets/Scripts/GameMode/GameMode.cs +++ b/Assets/Scripts/GameMode/GameMode.cs @@ -11,12 +11,17 @@ public abstract class GameMode : ScriptableObject [Tooltip("Scene to load which contains Gamemode UI")] private string GameModeScene; + [SerializeField] + [Tooltip("Round Times are acessed from the top down")] + private List RoundTimes; + public Action GameStartEvent; public Action RoundStartEvent; public Action AllPlayersMovedEvent; public Action RoundEndEvent; public Action OnGameOverEvent; + protected abstract void OnGameStart(PlayerData[] allPlayers); /// @@ -44,6 +49,14 @@ public abstract class GameMode : ScriptableObject protected abstract void OnGameOver(PlayerData[] allPlayers); + public float GetRoundTime() + { + float retVal = RoundTimes[0]; + + if (RoundTimes.Count > 1) + RoundTimes.RemoveAt(0); + return RoundTimes[0]; + } public void GameStart(PlayerData[] allPlayers) { diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs index b60d0c8..36d77e9 100644 --- a/Assets/Scripts/Managers/GameManager.cs +++ b/Assets/Scripts/Managers/GameManager.cs @@ -95,6 +95,9 @@ public class GameManager : MonoBehaviour private void StartRound() { gamemode.RoundStart(playerArray.ToArray()); + LogicProtocols.FloatMsg RoundTime = new LogicProtocols.FloatMsg( gamemode.GetRoundTime()); + + playerArray.ForEach(p => p.client.conn.Send(LogicProtocols.SendRoundTime, RoundTime)); } private IEnumerator RoundRoutine() diff --git a/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs b/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs index 0e6585a..a378c69 100644 --- a/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs +++ b/Assets/Scripts/Networking/Core/Protocols/LogicProtocols.cs @@ -10,6 +10,8 @@ namespace Networking { public const short SendLogicList = 200; public const short SendInventory = 201; + public const short SendRoundTime = 202; + public const short SendNotification = 203; public class LogicMsg : MessageBase @@ -103,5 +105,54 @@ namespace Networking } + public class FloatMsg : MessageBase + { + + public float Float; + + public FloatMsg() { } + public FloatMsg(float Float) + { + this.Float = Float; + } + + public override void Serialize(NetworkWriter writer) + { + base.Serialize(writer); + writer.Write(Float); + } + + public override void Deserialize(NetworkReader reader) + { + base.Deserialize(reader); + + Float = reader.ReadSingle(); + } + } + + public class StringMsg : MessageBase + { + + public float String; + + public StringMsg() { } + public StringMsg(float String) + { + this.String = String; + } + + public override void Serialize(NetworkWriter writer) + { + base.Serialize(writer); + writer.Write(String); + } + + public override void Deserialize(NetworkReader reader) + { + base.Deserialize(reader); + + String = reader.ReadSingle(); + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/NetworkedUIManager.cs b/Assets/Scripts/UI/NetworkedUIManager.cs index 209268f..40802de 100644 --- a/Assets/Scripts/UI/NetworkedUIManager.cs +++ b/Assets/Scripts/UI/NetworkedUIManager.cs @@ -35,6 +35,18 @@ public class NetworkedUIManager : PlayerUIManager OnClick_Show(); } + private void OnEnable() + { + if (Client.isConnected) + Client.client.RegisterHandler(LogicProtocols.SendRoundTime, UpdateTime); + } + + private void OnDisable() + { + if (Client.isConnected) + Client.client.UnregisterHandler(LogicProtocols.SendRoundTime); + } + private void Update() { if (!isTimePaused) @@ -65,5 +77,15 @@ public class NetworkedUIManager : PlayerUIManager else TimeText.color = Color.black; } - + + + public void UpdateTime(NetworkMessage msg) + { + LogicProtocols.FloatMsg floatMsg; + if (!msg.TryRead(out floatMsg)) + return; + + TotalTime = floatMsg.Float; + } + }