diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index c6c64a6..9455cd2 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -61,7 +61,12 @@ public class MatchMakingOptions private static Action OnDisconnectCallback = null; [DllImport("__Internal")] - private static extern void InsertCoinInternal(string options, Action onLaunchCallback, Action onQuitInternalCallback, Action onDisconnectCallback); + private static extern void InsertCoinInternal( + string options, + Action onLaunchCallback, + Action onQuitInternalCallback, + Action onDisconnectCallback, + Action onError); [MonoPInvokeCallback(typeof(Action))] private static void InvokeInsertCoin() @@ -73,7 +78,15 @@ private static void InvokeInsertCoin() } - // optional InitOptions + [MonoPInvokeCallback(typeof(Action))] + private static void InvokeOnErrorInsertCoin(string error) + { + onError?.Invoke(error); + Debug.LogException(new Exception(error)); + } + + private static Action onError; + public static void InsertCoin(InitOptions options = null, Action onLaunchCallBack = null, Action onDisconnectCallback = null) { if (IsRunningInBrowser()) @@ -95,7 +108,7 @@ public static void InsertCoin(InitOptions options = null, Action onLaunchCallBac #endif } - InsertCoinInternal(optionsJson, InvokeInsertCoin, __OnQuitInternalHandler, onDisconnectCallbackHandler); + InsertCoinInternal(optionsJson, InvokeInsertCoin, __OnQuitInternalHandler, onDisconnectCallbackHandler, InvokeOnErrorInsertCoin); } else { diff --git a/Assets/PlayroomKit/src/index.js b/Assets/PlayroomKit/src/index.js index 14e5498..6c01cbb 100644 --- a/Assets/PlayroomKit/src/index.js +++ b/Assets/PlayroomKit/src/index.js @@ -8,7 +8,8 @@ mergeInto(LibraryManager.library, { optionsJson, onLaunchCallBack, onQuitInternalCallback, - onDisconnectCallback + onDisconnectCallback, + onError ) { function OnLaunchCallBack() { @@ -19,7 +20,7 @@ mergeInto(LibraryManager.library, { dynCall("v", onDisconnectCallback, []); } - var options = optionsJson ? JSON.parse(UTF8ToString(optionsJson)) : {}; + var options = optionsJson ? JSON.parse(UTF8ToString(optionsJson)) : {}; if (!window.Playroom) { console.error( @@ -43,7 +44,11 @@ mergeInto(LibraryManager.library, { }) .catch((error) => { - console.error("Error inserting coin:", error); + var jsonString = JSON.stringify(error); + var bufferSize = lengthBytesUTF8(jsonString) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(jsonString, buffer, bufferSize); + dynCall("vi", onError, [buffer]); }); }, diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 419b050..8c98db9 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -29,6 +29,7 @@ public class GameManager : MonoBehaviour private void Awake() { + PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2,