diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 0de8492..974bfb3 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -45,6 +45,13 @@ public class InitOptions public Dictionary defaultStates = null; public Dictionary defaultPlayerStates = null; + public bool matchmaking = false; + + } + + public class MatchMakingOptions + { + public int waitBeforeCreatingNewRoom = 5000; } private static Action InsertCoinCallback = null; @@ -123,6 +130,8 @@ private static string SerializeInitOptions(InitOptions options) node["skipLobby"] = options.skipLobby; node["reconnectGracePeriod"] = options.reconnectGracePeriod; + node["matchmaking"] = options.matchmaking; + if (options.maxPlayersPerRoom.HasValue) { node["maxPlayersPerRoom"] = options.maxPlayersPerRoom.Value; @@ -1136,6 +1145,8 @@ private static string ConvertComplexToJson(object data) } } + [DllImport("__Internal")] + public static extern void StartMatchMaking(); // Player class public class Player diff --git a/Assets/Plugins/PlayroomPlugin.jslib b/Assets/Plugins/PlayroomPlugin.jslib index ec4ee9a..5f4a9d9 100644 --- a/Assets/Plugins/PlayroomPlugin.jslib +++ b/Assets/Plugins/PlayroomPlugin.jslib @@ -849,7 +849,18 @@ mergeInto(LibraryManager.library, { }, + StartMatchMaking: function () { + if (!window.Playroom) { + console.error("Playroom library is not loaded. Please make sure to call InsertCoin first."); + return; + } - + Playroom.startMatchmaking().then(() => { + console.log(`Player has joined a public room`); + }).catch(error => { + console.error( + `JS: Error starting match making ${error}`) + }); + }, }); diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index e99634c..3d6b35b 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -32,6 +32,7 @@ private void Awake() PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2, + matchmaking = true, defaultPlayerStates = new() { {"score", -500}, }, @@ -41,6 +42,7 @@ private void Awake() PlayroomKit.OnPlayerJoin(AddPlayer); }); + } void Start()