From 2bfc3f61a894bb79580bccb22df528441ef88499 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Tue, 21 May 2019 10:54:49 -0300 Subject: [PATCH] add GetRoomsAvailable button on example. workaround #66 --- Assets/ColyseusClient.cs | 18 +++++++++++++++++- Assets/ExampleScene.unity | Bin 60237 -> 62333 bytes Assets/Plugins/Colyseus/Room.cs | 2 -- .../Colyseus/Utils/ObjectExtensions.cs | 12 +++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Assets/ColyseusClient.cs b/Assets/ColyseusClient.cs index 047a95ea..58cb940f 100644 --- a/Assets/ColyseusClient.cs +++ b/Assets/ColyseusClient.cs @@ -12,7 +12,7 @@ public class ColyseusClient : MonoBehaviour { // UI Buttons are attached through Unity Inspector - public Button m_ConnectButton, m_JoinButton, m_ReJoinButton, m_SendMessageButton, m_LeaveButton; + public Button m_ConnectButton, m_JoinButton, m_ReJoinButton, m_SendMessageButton, m_LeaveButton, m_GetAvailableRoomsButton; public InputField m_EndpointField; public Text m_IdText, m_SessionIdText; @@ -32,6 +32,7 @@ public class ColyseusClient : MonoBehaviour { m_ReJoinButton.onClick.AddListener(ReJoinRoom); m_SendMessageButton.onClick.AddListener(SendMessage); m_LeaveButton.onClick.AddListener(LeaveRoom); + m_GetAvailableRoomsButton.onClick.AddListener(GetAvailableRooms); /* Always call Recv if Colyseus connection is open */ while (true) @@ -139,6 +140,21 @@ void LeaveRoom() entities.Clear(); } + void GetAvailableRooms() + { + client.GetAvailableRooms(roomName, (RoomAvailable[] roomsAvailable) => + { + Debug.Log("Available rooms (" + roomsAvailable.Length + ")"); + for (var i=0; i< roomsAvailable.Length;i++) + { + Debug.Log("roomId: " + roomsAvailable[i].roomId); + Debug.Log("maxClients: " + roomsAvailable[i].maxClients); + Debug.Log("clients: " + roomsAvailable[i].clients); + Debug.Log("metadata: " + roomsAvailable[i].metadata); + } + }); + } + void SendMessage() { if (room != null) diff --git a/Assets/ExampleScene.unity b/Assets/ExampleSc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G~IGt-USj3ex_3^Ph7av8e zqBPttr)p#2{)8<329eJ7TSAWIEh64K=`+b|M|e)O}40L(M@^i z3R0xR!XWGIgHqPg5BZ^JmWEK)B8YV%t>{x&{oi$7p0UGup5J+%|2fa?9sZc~>{Zev zqVRm8FRO@X0@|hUG}rEM6&4jb?@Yen%RS!oAnV+vhX?jG-fJvK^)eI_UK;BrccV$i|6#hT4Ydmlx@|SE`zne#=!E$nu!*1%Q;F6muDv52YDhURV+8D zttgMNC&nDD$T4}7C>R6%i(ipw$gt>~;>-$*u2?)qd!Fc6u~MAfxL*0Q@vXybHp|gipZzd5b9l(PokCQMz7aP1MrZ~cg~Smk7^liLn>f-6 z=HfMvWfr$eg+&d%IjVwH^fZ|R*QQAYH%GkFiAq>uF|!cXqSfFpsP(A|5wJRVb!FAe zJULRYhFKg;)2n4>%S-455{nw_9KAsmtOPv5fdNjCywdUV9S0qDFUDs{h66} z9#K7FcrNsXSwGlT^zl&WD>DziC)&}OKePu9Ax05E?TMs*XiqSo3y%Xawdyox#s%`h zq%&(t7^`{`SpLqvjZ2B6AEf3zr0Bk|BmZw@mV#nQ@6s@`IVpBa;mLK2WPB zsRYwr#9L-DFztT4V-{M<_rruqF^1jClqq4aPT6uZJyjg*C>8ZBMiJ|HD%SO7E6*S1 o8gwb*S7(_h?+PlhuKE-uBU+Ly>ihGQn!Y@}h}|~ceN$)o2j|c+O8@`> diff --git a/Assets/Plugins/Colyseus/Room.cs b/Assets/Plugins/Colyseus/Room.cs index 4aecca20..ea02089f 100644 --- a/Assets/Plugins/Colyseus/Room.cs +++ b/Assets/Plugins/Colyseus/Room.cs @@ -2,8 +2,6 @@ using System.IO; using System.Collections; using System.Collections.Generic; - -using UnityEngine; using GameDevWare.Serialization; namespace Colyseus diff --git a/Assets/Plugins/Colyseus/Utils/ObjectExtensions.cs b/Assets/Plugins/Colyseus/Utils/ObjectExtensions.cs index 6a599e6b..11967335 100644 --- a/Assets/Plugins/Colyseus/Utils/ObjectExtensions.cs +++ b/Assets/Plugins/Colyseus/Utils/ObjectExtensions.cs @@ -14,9 +14,15 @@ public static T ToObject(object source) where T : class, new() var someObjectType = someObject.GetType(); foreach (var item in (IDictionary)source) { - someObjectType - .GetProperty(item.Key) - .SetValue(someObject, item.Value, null); + var prop = someObjectType.GetProperty(item.Key); + try + { + prop.SetValue(someObject, Convert.ChangeType(item.Value, prop.PropertyType), null); + + } catch (OverflowException e) { + // workaround for parsing Infinity on RoomAvailable.maxClients + prop.SetValue(someObject, uint.MaxValue, null); + } } return someObject;