diff --git a/Assets/Data/Networking/Client/Realtime/ConnectClients.asset b/Assets/Data/Networking/Client/Realtime/ConnectClients.asset
new file mode 100644
index 0000000..48be882
--- /dev/null
+++ b/Assets/Data/Networking/Client/Realtime/ConnectClients.asset
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4d22d2621c905effb48e71fa0091fb0f569b358a644fc77182dbd6dd0776af75
+size 478
diff --git a/Assets/Data/Networking/Client/Realtime/ConnectClients.asset.meta b/Assets/Data/Networking/Client/Realtime/ConnectClients.asset.meta
new file mode 100644
index 0000000..30cc3ef
--- /dev/null
+++ b/Assets/Data/Networking/Client/Realtime/ConnectClients.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 78d89605739516c4f9c66fb270137102
+NativeFormatImporter:
+ externalObjects: {}
+ mainObjectFileID: 11400000
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Data/Networking/Client/Realtime/LocalClient.asset b/Assets/Data/Networking/Client/Realtime/LocalClient.asset
index f55f8ae..9c64c8c 100644
--- a/Assets/Data/Networking/Client/Realtime/LocalClient.asset
+++ b/Assets/Data/Networking/Client/Realtime/LocalClient.asset
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:9e95c47ee245273f574075cf296e80d083a1401111c78ecb2025c2ebb78c6f49
-size 607
+oid sha256:cdf01e4c58d4afd9740fc7252436c4a0c7383081d565b0dc65378000fce8c4bb
+size 743
diff --git a/Assets/Data/Networking/Server/Realtime/ClientList.asset b/Assets/Data/Networking/Server/Realtime/ClientList.asset
index 4dc7715..b985f26 100644
--- a/Assets/Data/Networking/Server/Realtime/ClientList.asset
+++ b/Assets/Data/Networking/Server/Realtime/ClientList.asset
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:ad3462c6f94c1dd783ef1b25cdb98524845edaa36a879324db1ff597811de687
-size 776
+oid sha256:e3ee5388094941012a17d8eac09e9009610e3bcbcb69a307ce928fbc133b6d3c
+size 834
diff --git a/Assets/Scenes/Client Scenes/LoginScreen.unity b/Assets/Scenes/Client Scenes/LoginScreen.unity
index ecf8ab2..71765f3 100644
--- a/Assets/Scenes/Client Scenes/LoginScreen.unity
+++ b/Assets/Scenes/Client Scenes/LoginScreen.unity
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:921c3031e05c70f24f9c7d294a58f76e4b8ebb7405d1cc6ab4c2bfd9684d79ea
-size 259080
+oid sha256:b7d072ed5fffb0afdf3ee9090c2b01468dba1779c7c97d3a8d961897c5b8f1f1
+size 259079
diff --git a/Assets/Scenes/RaceTrack 4-player alpha.unity b/Assets/Scenes/RaceTrack 4-player alpha.unity
new file mode 100644
index 0000000..24d3617
--- /dev/null
+++ b/Assets/Scenes/RaceTrack 4-player alpha.unity
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:44b4324088c8dade10402a7c0554434853b15ee4d88936e007a70499bd05f4d3
+size 2604605
diff --git a/Assets/Scenes/RaceTrack 4-player alpha.unity.meta b/Assets/Scenes/RaceTrack 4-player alpha.unity.meta
new file mode 100644
index 0000000..3eb5465
--- /dev/null
+++ b/Assets/Scenes/RaceTrack 4-player alpha.unity.meta
@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 9dc1300c8b04e8a4b89eebfa931c970a
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Block.cs b/Assets/Scripts/Block.cs
index cc309fd..cad973c 100644
--- a/Assets/Scripts/Block.cs
+++ b/Assets/Scripts/Block.cs
@@ -50,8 +50,42 @@ public class Block : MonoBehaviour
//checks if there is no block above this one and that this is tagged as walkable
return (is_Walkable && !isBlockAtPosition(position + Vector3.up, 1, layerMask));
}
+
+
+ ///
+ /// Is called after all players have taken one move
+ ///
+ /// Should be implemented by a derived class
+ ///
+ public virtual void OnPlayersMoved()
+ {
+
+ }
+
+ ///
+ /// Is called when a player moves onto this block
+ ///
+ /// Should be implemented by a derived class
+ ///
+ /// Player which moved on to block
+ public virtual void OnWalkedOnByPlayer(PlayerData player)
+ {
+
+ }
+
+ ///
+ /// Called after all players have finished all their moves
+ ///
+ /// Should be implemented by a derived class
+ ///
+ public virtual void OnRoundEnd()
+ {
+
+ }
+
#endregion Public Functions
+ #region Editor Functions
private void OnDrawGizmos()
{
if (!isSpawnable)
@@ -74,6 +108,7 @@ public class Block : MonoBehaviour
DebugExtensions.DrawCube(earPosition - Perp * 0.3f, earScale, Color.magenta, 0);
}
+ #endregion Editor Functions
#region Static Functions
diff --git a/Assets/Scripts/Character.meta b/Assets/Scripts/Character.meta
new file mode 100644
index 0000000..1b14f03
--- /dev/null
+++ b/Assets/Scripts/Character.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 5497ad1d7b329a54386c4438a6e220fc
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Character/CharacterData.cs b/Assets/Scripts/Character/CharacterData.cs
new file mode 100644
index 0000000..fae02bb
--- /dev/null
+++ b/Assets/Scripts/Character/CharacterData.cs
@@ -0,0 +1,10 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using Networking.Server;
+
+public class CharacterData
+{
+ public Character Character;
+ public ClientData Client;
+}
diff --git a/Assets/Scripts/Character/CharacterData.cs.meta b/Assets/Scripts/Character/CharacterData.cs.meta
new file mode 100644
index 0000000..d09c139
--- /dev/null
+++ b/Assets/Scripts/Character/CharacterData.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: f3798d0274105f74b9d15daeb9deafa9
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Components.meta b/Assets/Scripts/Components.meta
new file mode 100644
index 0000000..5a95b09
--- /dev/null
+++ b/Assets/Scripts/Components.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 8d7394d70ec233849a60a26da5f23b75
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Managers/GameManager.cs b/Assets/Scripts/Managers/GameManager.cs
index 8aa546b..ee215ab 100644
--- a/Assets/Scripts/Managers/GameManager.cs
+++ b/Assets/Scripts/Managers/GameManager.cs
@@ -110,10 +110,15 @@ public class GameManager : MonoBehaviour
{
//Debug.Log("One Move");
foreach (PlayerData player in playerArray)
- RunOnce(player);
+ {
+ Debug.Log(player.client.Name);
+ StartCoroutine(RunOnce(player));
+ yield return new WaitUntil(() => player.waiting);
+ }
+
//wait until all players have finished
- yield return new WaitUntil(() => playerArray.All(p => p.waiting));
+ //yield return new WaitUntil(() => playerArray.All(p => p.waiting));
gamemode.FinishedMove(playerArray.ToArray());
playerArray.ForEach(p => p.client.SendScore());
diff --git a/Assets/Scripts/Networking/Client/ClientObject.cs b/Assets/Scripts/Networking/Client/ClientObject.cs
index f6be1fd..1e43a07 100644
--- a/Assets/Scripts/Networking/Client/ClientObject.cs
+++ b/Assets/Scripts/Networking/Client/ClientObject.cs
@@ -49,6 +49,10 @@ namespace Networking.Client
[Tooltip("Current Score in Round")]
public float RoundScore;
+ [SerializeField]
+ [Tooltip("A list of all connected clients")]
+ public ConnectedClients ConnectedClients;
+
#endregion Inspector Fields
@@ -66,6 +70,8 @@ namespace Networking.Client
client = new NetworkClient();
client.Configure(TransportConfigure.CreateConfigure(), 1);
+ ConnectedClients.SetUp(this);
+
client.Connect(serverAddress, port);
Inventory.Reset();
diff --git a/Assets/Scripts/Networking/Client/ConnectedClients.cs b/Assets/Scripts/Networking/Client/ConnectedClients.cs
new file mode 100644
index 0000000..9c7e062
--- /dev/null
+++ b/Assets/Scripts/Networking/Client/ConnectedClients.cs
@@ -0,0 +1,102 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine;
+using UnityEngine.Networking;
+using Networking;
+
+namespace Networking.Client
+{
+
+ [CreateAssetMenu(menuName = "Major Project/Networking/Client/OtherClientsList", order = 150)]
+ public class ConnectedClients : ScriptableObject
+ {
+
+#if UNITY_EDITOR
+
+ [SerializeField]
+ [Multiline]
+ private string DevNotes;
+
+#endif
+
+ ///
+ /// All Clients which are Currently Connected;
+ ///
+ [SerializeField]
+ public List AllClients;
+
+ ///
+ /// Called when a client connects or disconnet
+ ///
+ public System.Action> OnClientsChange;
+
+ public void SetUp(ClientObject client)
+ {
+ Reset();
+ client.client.RegisterHandler(LoginProtocols.OtherClientConnected, OnClientConnect);
+ client.client.RegisterHandler(LoginProtocols.OtherClientDisconnected, OnClientDisconnect);
+ }
+
+
+ public void Reset()
+ {
+ AllClients = new List();
+
+ OnClientsChange?.Invoke(AllClients);
+ }
+
+
+ public void OnClientConnect(NetworkMessage msg)
+ {
+ LoginProtocols.LoginMsg loginMsg;
+ if (!msg.TryRead(out loginMsg))
+ return;
+
+
+ AllClients.Add(new ClientData(loginMsg));
+ OnClientsChange?.Invoke(AllClients);
+ }
+
+ public void OnClientDisconnect(NetworkMessage msg)
+ {
+ LoginProtocols.LoginMsg loginMsg;
+ if (!msg.TryRead(out loginMsg))
+ return;
+
+ AllClients.RemoveAll(p => (p.Name == loginMsg.Name) && (p.Color == loginMsg.Color) && (p.characterAnimal == loginMsg.Animal));
+ OnClientsChange?.Invoke(AllClients);
+ }
+
+
+ }
+
+
+ [System.Serializable]
+ public class ClientData
+ {
+
+ ///
+ /// Client Name
+ ///
+ public string Name;
+
+ ///
+ /// Color which represents player, picked by player
+ ///
+ public Color Color;
+
+ ///
+ /// Clients character animal - needed for instantiation
+ ///
+ public string characterAnimal = "Bear";
+
+ public ClientData(LoginProtocols.LoginMsg msg)
+ {
+ this.Name = msg.Name;
+ this.Color = msg.Color;
+ this.characterAnimal = msg.Animal;
+ }
+ }
+
+}
diff --git a/Assets/Scripts/Networking/Client/ConnectedClients.cs.meta b/Assets/Scripts/Networking/Client/ConnectedClients.cs.meta
new file mode 100644
index 0000000..7275283
--- /dev/null
+++ b/Assets/Scripts/Networking/Client/ConnectedClients.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b1e3fec824e729b40a8f6d25c846813f
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Networking/Core/Protocols/LoginProtocols.cs b/Assets/Scripts/Networking/Core/Protocols/LoginProtocols.cs
index 93ee97a..9c13e8f 100644
--- a/Assets/Scripts/Networking/Core/Protocols/LoginProtocols.cs
+++ b/Assets/Scripts/Networking/Core/Protocols/LoginProtocols.cs
@@ -11,6 +11,8 @@ public class LoginProtocols
public const short DetailSucess = 105;
public const short LoginFail = 103;
public const short SceneChange = 104;
+ public const short OtherClientConnected = 105;
+ public const short OtherClientDisconnected = 106;
public class EmptyMsg : MessageBase { }
diff --git a/Assets/Scripts/Networking/Server/ClientList.cs b/Assets/Scripts/Networking/Server/ClientList.cs
index a1c3f81..6ef4ebc 100644
--- a/Assets/Scripts/Networking/Server/ClientList.cs
+++ b/Assets/Scripts/Networking/Server/ClientList.cs
@@ -11,6 +11,14 @@ namespace Networking.Server
public class ClientList : ScriptableObject, IEnumerable
{
+#if UNITY_EDITOR
+
+ [SerializeField]
+ [Multiline]
+ private string DevNotes;
+
+#endif
+
[SerializeField]
private Inventory StartInventory;
@@ -28,6 +36,8 @@ namespace Networking.Server
public List DisconnectedClients;
+ private List PotentialClients = new List();
+
///
/// Called when a client connects or disconnet
///
@@ -48,6 +58,7 @@ namespace Networking.Server
{
ConnectedClients = new List();
DisconnectedClients = new List();
+ PotentialClients = new List();
}
///
@@ -73,11 +84,18 @@ namespace Networking.Server
return;
}
+ if (!PotentialClients.Contains(msg.conn))
+ PotentialClients.Add(msg.conn);
+
msg.conn.Send(LoginProtocols.RequestLoginDetails, new LoginProtocols.EmptyMsg());
+ ConnectedClients.ForEach(p => msg.conn.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(p.Name, p.Color, p.characterAnimal)));
}
public void OnClientDisconnect(NetworkMessage msg)
{
+
+ PotentialClients.RemoveAll(p => p == msg.conn);
+
if (!ConnectedClients.Any(p => p.ID == msg.conn.connectionId))
{
Debug.LogError("Unknown client disconnect [" + msg.conn.connectionId + "]");
@@ -88,6 +106,9 @@ namespace Networking.Server
ConnectedClients.Remove(client);
DisconnectedClients.Add(client);
+
+ ConnectedClients.ForEach(p => p.conn.Send(LoginProtocols.OtherClientDisconnected, new LoginProtocols.LoginMsg(client.Name, client.Color, client.characterAnimal)));
+ PotentialClients.ForEach(p => p.Send(LoginProtocols.OtherClientDisconnected, new LoginProtocols.LoginMsg(client.Name, client.Color, client.characterAnimal)));
Debug.Log("Disconnected: " + client.Name);
OnClientsChange.Invoke(ConnectedClients);
}
@@ -127,13 +148,21 @@ namespace Networking.Server
newClient.Name = loginMsg.Name;
newClient.conn = msg.conn;
+ ConnectedClients.ForEach(p => p.conn.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal)));
+
ConnectedClients.Add(newClient);
+ PotentialClients.RemoveAll(p => p == newClient.conn);
+ PotentialClients.ForEach(p => p.Send(LoginProtocols.OtherClientConnected, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal)));
newClient.conn.Send(LoginProtocols.LoginSuccess, new LoginProtocols.LoginMsg(newClient.Name, newClient.Color, newClient.characterAnimal));
OnClientsChange.Invoke(ConnectedClients);
newClient.SendInventory();
newClient.SendScore();
newClient.ChangeScene("WaitScene");
+
+
+
+
}
#region IEnumerable Implementation
diff --git a/Assets/Scripts/UI/Client/LoginUIManager.cs b/Assets/Scripts/UI/Client/LoginUIManager.cs
index e8e61ee..16f8701 100644
--- a/Assets/Scripts/UI/Client/LoginUIManager.cs
+++ b/Assets/Scripts/UI/Client/LoginUIManager.cs
@@ -41,8 +41,8 @@ public class LoginUIManager : MonoBehaviour
private string playerAnimal;
private Color playerColor;
- bool animalSelected = true;
- bool colorSelected = true;
+ bool animalSelected = false;
+ bool colorSelected = false;
#region Unity Functions
@@ -130,22 +130,6 @@ public class LoginUIManager : MonoBehaviour
}
}
- public void OnClick_Color(Color playerColor)
- {
- this.playerColor = playerColor;
- }
-
- public void OnClick_Colour(string hex)
- {
- Color newColor = new Color();
- if (ColorUtility.TryParseHtmlString(hex, out newColor)){
- this.playerColor = newColor;
- colorSelected = true;
- }
-
- clientManager.SendPlayerCDetails(playerColor);
- }
-
public void OnClick_Animal(string playerAnimal)
{
this.playerAnimal = playerAnimal;
diff --git a/Assets/Scripts/animalSelection.cs b/Assets/Scripts/animalSelection.cs
index e558b6a..efa01b9 100644
--- a/Assets/Scripts/animalSelection.cs
+++ b/Assets/Scripts/animalSelection.cs
@@ -1,24 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
-using Networking.Server;
+using Networking.Client;
using UnityEngine.UI;
public class animalSelection : MonoBehaviour
{
- public ClientList Clients;
+ public ConnectedClients Clients;
public List Animals;
- void Update()
- //change function to react on push from the server
+ //private void OnEnable()
+ //{
+ // Clients.OnClientsChange += UpdateAnimals;
+ //}
+ //
+ //private void OnDisable()
+ //{
+ // Clients.OnClientsChange -= UpdateAnimals;
+ //}
+
+
+ public void Update()
{
- if (Clients.ConnectedClients.Count > 0)
+
+ if (Clients.AllClients.Count > 0)
{
- for (int i = 0; i < Clients.ConnectedClients.Count; i++)
+ for (int i = 0; i < Clients.AllClients.Count; i++)
{
for (int j = 0; j < Animals.Count; j++)
{
- if (Clients.ConnectedClients[i].characterAnimal == Animals[j].name)
+ if (Clients.AllClients[i].characterAnimal == Animals[j].name)
{
Animals[j].GetComponent().color = Color.black;
Animals[j].enabled = false;