From 38e1945237368e8b71fdac2a9ae78ee820714e76 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:07:44 +0500 Subject: [PATCH 1/7] fix: passing error to unity. Need to figure out a proper way to return the error to the dev but we are now printing error in the unity side. --- Assets/PlayroomKit/PlayroomKit.cs | 21 ++++++++++++++++++--- Assets/Plugins/PlayroomPlugin.jslib | 24 ++++++++++++++++-------- Assets/Scripts/GameManager.cs | 4 +++- Packages/manifest.json | 2 +- Packages/packages-lock.json | 22 +++++++++++----------- ProjectSettings/ProjectVersion.txt | 4 ++-- 6 files changed, 51 insertions(+), 26 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index f8cb8d0..f315cd2 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -60,7 +60,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() @@ -72,7 +77,17 @@ private static void InvokeInsertCoin() } - // optional InitOptions + + + + private static Action onError; + public static string error; + [MonoPInvokeCallback(typeof(Action))] + private static void InvokeOnErrorInsertCoin(string errror) + { + onError?.Invoke(errror); + Debug.LogError(error); + } public static void InsertCoin(InitOptions options = null, Action onLaunchCallBack = null, Action onDisconnectCallback = null) { if (IsRunningInBrowser()) @@ -94,7 +109,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/Plugins/PlayroomPlugin.jslib b/Assets/Plugins/PlayroomPlugin.jslib index 0ba0d86..af34f4b 100644 --- a/Assets/Plugins/PlayroomPlugin.jslib +++ b/Assets/Plugins/PlayroomPlugin.jslib @@ -8,7 +8,8 @@ mergeInto(LibraryManager.library, { optionsJson, onLaunchCallBack, onQuitInternalCallback, - onDisconnectCallback + onDisconnectCallback, + onError ) { function embedScript(src) { return new Promise((resolve, reject) => { @@ -30,12 +31,8 @@ mergeInto(LibraryManager.library, { dynCall("v", onDisconnectCallback, []); } - - - var options = optionsJson ? JSON.parse(UTF8ToString(optionsJson)) : {}; - Promise.all([ embedScript("https://unpkg.com/react@18.2.0/umd/react.development.js"), embedScript( @@ -54,7 +51,6 @@ mergeInto(LibraryManager.library, { Playroom.insertCoin(options, OnLaunchCallBack, OnDisconnectCallback) .then(() => { - Playroom.onPlayerJoin((player) => { var id = player.id; var bufferSize = lengthBytesUTF8(id) + 1; @@ -68,11 +64,23 @@ mergeInto(LibraryManager.library, { }) .catch((error) => { - console.error("Error inserting coin:", error); + // console.error("Error loading Playroom:", error); + + var bufferSize = lengthBytesUTF8(error) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(error, buffer, bufferSize); + + dynCall("vi", onError, [buffer]); }); }) .catch((error) => { - console.error("Error loading Playroom:", error); + // console.error("Error loading Playroom:", error); + + var bufferSize = lengthBytesUTF8(error) + 1; + var buffer = _malloc(bufferSize); + stringToUTF8(error, buffer, bufferSize); + + dynCall("vi", onError, [buffer]); }); }, diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 3d6b35b..4d4e333 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -28,11 +28,13 @@ public class GameManager : MonoBehaviour private void Awake() { // PlayroomKit.OnPlayerJoin(AddPlayer); - + PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2, matchmaking = true, + // gameId = "123", + discord = true, defaultPlayerStates = new() { {"score", -500}, }, diff --git a/Packages/manifest.json b/Packages/manifest.json index ef5f969..264fefb 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -2,7 +2,7 @@ "dependencies": { "com.unity.collab-proxy": "2.2.0", "com.unity.feature.2d": "2.0.0", - "com.unity.ide.rider": "3.0.26", + "com.unity.ide.rider": "3.0.27", "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", "com.unity.test-framework": "1.1.33", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 6ba175b..2e11dab 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,11 +1,11 @@ { "dependencies": { "com.unity.2d.animation": { - "version": "7.0.12", + "version": "7.0.13", "depth": 1, "source": "registry", "dependencies": { - "com.unity.2d.common": "6.0.6", + "com.unity.2d.common": "6.0.7", "com.unity.2d.sprite": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.uielements": "1.0.0" @@ -13,7 +13,7 @@ "url": "https://packages.unity.com" }, "com.unity.2d.aseprite": { - "version": "1.0.1", + "version": "1.1.0", "depth": 1, "source": "registry", "dependencies": { @@ -25,7 +25,7 @@ "url": "https://packages.unity.com" }, "com.unity.2d.common": { - "version": "6.0.6", + "version": "6.0.7", "depth": 2, "source": "registry", "dependencies": { @@ -51,12 +51,12 @@ "url": "https://packages.unity.com" }, "com.unity.2d.psdimporter": { - "version": "6.0.7", + "version": "6.0.8", "depth": 1, "source": "registry", "dependencies": { - "com.unity.2d.animation": "7.0.9", - "com.unity.2d.common": "6.0.6", + "com.unity.2d.animation": "7.0.13", + "com.unity.2d.common": "6.0.7", "com.unity.2d.sprite": "1.0.0" }, "url": "https://packages.unity.com" @@ -125,18 +125,18 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.2d.animation": "7.0.12", + "com.unity.2d.animation": "7.0.13", "com.unity.2d.pixel-perfect": "5.0.3", - "com.unity.2d.psdimporter": "6.0.7", + "com.unity.2d.psdimporter": "6.0.8", "com.unity.2d.sprite": "1.0.0", "com.unity.2d.spriteshape": "7.0.7", "com.unity.2d.tilemap": "1.0.0", "com.unity.2d.tilemap.extras": "2.2.7", - "com.unity.2d.aseprite": "1.0.1" + "com.unity.2d.aseprite": "1.1.0" } }, "com.unity.ide.rider": { - "version": "3.0.26", + "version": "3.0.27", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index d60336d..03cda39 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.33f1 -m_EditorVersionWithRevision: 2021.3.33f1 (ee5a2aa03ab2) +m_EditorVersion: 2021.3.34f1 +m_EditorVersionWithRevision: 2021.3.34f1 (25266724e7bd) From 79deea9116f0a07c68ad295dc9815d030d4b0043 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:13:55 +0500 Subject: [PATCH 2/7] chore: typo --- Assets/PlayroomKit/PlayroomKit.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index f315cd2..fc482b1 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -77,17 +77,15 @@ private static void InvokeInsertCoin() } - - - - private static Action onError; - public static string error; [MonoPInvokeCallback(typeof(Action))] - private static void InvokeOnErrorInsertCoin(string errror) + private static void InvokeOnErrorInsertCoin(string error) { - onError?.Invoke(errror); + onError?.Invoke(error); Debug.LogError(error); } + + private static Action onError; + public static void InsertCoin(InitOptions options = null, Action onLaunchCallBack = null, Action onDisconnectCallback = null) { if (IsRunningInBrowser()) From f9fce3dfadd8b99c14c229651bebd2d112f6b9f6 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:05:38 +0500 Subject: [PATCH 3/7] fix: throwing exception --- Assets/PlayroomKit/PlayroomKit.cs | 3 ++- Assets/Plugins/PlayroomPlugin.jslib | 6 +----- Assets/Scripts/GameManager.cs | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index fc482b1..ecf2a83 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -81,7 +81,8 @@ private static void InvokeInsertCoin() private static void InvokeOnErrorInsertCoin(string error) { onError?.Invoke(error); - Debug.LogError(error); + if (error != "") + throw new Exception(error); } private static Action onError; diff --git a/Assets/Plugins/PlayroomPlugin.jslib b/Assets/Plugins/PlayroomPlugin.jslib index af34f4b..ed9d43c 100644 --- a/Assets/Plugins/PlayroomPlugin.jslib +++ b/Assets/Plugins/PlayroomPlugin.jslib @@ -64,18 +64,14 @@ mergeInto(LibraryManager.library, { }) .catch((error) => { - // console.error("Error loading Playroom:", error); - var bufferSize = lengthBytesUTF8(error) + 1; var buffer = _malloc(bufferSize); stringToUTF8(error, buffer, bufferSize); - + dynCall("vi", onError, [buffer]); }); }) .catch((error) => { - // console.error("Error loading Playroom:", error); - var bufferSize = lengthBytesUTF8(error) + 1; var buffer = _malloc(bufferSize); stringToUTF8(error, buffer, bufferSize); diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 4d4e333..d16adc1 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -33,7 +33,6 @@ private void Awake() { maxPlayersPerRoom = 2, matchmaking = true, - // gameId = "123", discord = true, defaultPlayerStates = new() { {"score", -500}, From c1893e89f42af26aeec2a01ff64e00733b06c239 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Sun, 14 Apr 2024 21:45:05 +0500 Subject: [PATCH 4/7] fix: sending JSON instead of raw error object --- Assets/PlayroomKit/PlayroomKit.cs | 6 +++++- Assets/PlayroomKit/src/index.js | 9 ++++++++- Assets/Scripts/GameManager.cs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index ecf2a83..93b1ba5 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -81,8 +81,12 @@ private static void InvokeInsertCoin() private static void InvokeOnErrorInsertCoin(string error) { onError?.Invoke(error); + var errorString = JsonUtility.FromJson(error); if (error != "") - throw new Exception(error); + { + Debug.Log(errorString); + throw new Exception(errorString); + } } private static Action onError; diff --git a/Assets/PlayroomKit/src/index.js b/Assets/PlayroomKit/src/index.js index 136ec3f..1944129 100644 --- a/Assets/PlayroomKit/src/index.js +++ b/Assets/PlayroomKit/src/index.js @@ -44,7 +44,14 @@ mergeInto(LibraryManager.library, { }) .catch((error) => { - console.error("Error inserting coin:", error); + + console.error(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 d16adc1..64b2401 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -32,7 +32,7 @@ private void Awake() PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2, - matchmaking = true, + // matchmaking = true, discord = true, defaultPlayerStates = new() { {"score", -500}, From dd2bb8bb27932ac7c348be181cebfd14f5eb0231 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:05:22 +0500 Subject: [PATCH 5/7] chore: version updated --- Assets/PlayroomKit/PlayroomKit.cs | 1 - Assets/PlayroomKit/src/index.js | 3 --- Packages/manifest.json | 9 +++++---- Packages/packages-lock.json | 17 +++++++++++++---- ProjectSettings/ProjectVersion.txt | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 93b1ba5..006a195 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -84,7 +84,6 @@ private static void InvokeOnErrorInsertCoin(string error) var errorString = JsonUtility.FromJson(error); if (error != "") { - Debug.Log(errorString); throw new Exception(errorString); } } diff --git a/Assets/PlayroomKit/src/index.js b/Assets/PlayroomKit/src/index.js index 1944129..815e73e 100644 --- a/Assets/PlayroomKit/src/index.js +++ b/Assets/PlayroomKit/src/index.js @@ -44,9 +44,6 @@ mergeInto(LibraryManager.library, { }) .catch((error) => { - - console.error(error) - var jsonString = JSON.stringify(error); var bufferSize = lengthBytesUTF8(jsonString) + 1; var buffer = _malloc(bufferSize); diff --git a/Packages/manifest.json b/Packages/manifest.json index 264fefb..36c9f96 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,15 +1,16 @@ { "dependencies": { - "com.unity.collab-proxy": "2.2.0", + "com.unity.ai.navigation": "1.1.5", + "com.unity.collab-proxy": "2.3.1", "com.unity.feature.2d": "2.0.0", - "com.unity.ide.rider": "3.0.27", + "com.unity.ide.rider": "3.0.28", "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.6.5", + "com.unity.timeline": "1.7.6", "com.unity.ugui": "1.0.0", - "com.unity.visualscripting": "1.9.1", + "com.unity.visualscripting": "1.9.2", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 367302d..acc71dd 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -94,6 +94,15 @@ }, "url": "https://packages.unity.com" }, + "com.unity.ai.navigation": { + "version": "1.1.5", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.ai": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.burst": { "version": "1.8.13", "depth": 3, @@ -105,7 +114,7 @@ "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "2.2.0", + "version": "2.3.1", "depth": 0, "source": "registry", "dependencies": {}, @@ -144,7 +153,7 @@ } }, "com.unity.ide.rider": { - "version": "3.0.27", + "version": "3.0.28", "depth": 0, "source": "registry", "dependencies": { @@ -196,7 +205,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.6.5", + "version": "1.7.6", "depth": 0, "source": "registry", "dependencies": { @@ -217,7 +226,7 @@ } }, "com.unity.visualscripting": { - "version": "1.9.1", + "version": "1.9.2", "depth": 0, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 03cda39..759df3a 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.34f1 -m_EditorVersionWithRevision: 2021.3.34f1 (25266724e7bd) +m_EditorVersion: 2022.3.23f1 +m_EditorVersionWithRevision: 2022.3.23f1 (dbb3f7c5b5c6) From 7b7707a2224e4f051d260c252f2c5382d96f6995 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:32:59 +0500 Subject: [PATCH 6/7] Fix: temp fix ## Need to pass the complete Error object --- Assets/PlayroomKit/PlayroomKit.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 006a195..6b19f87 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -81,11 +81,8 @@ private static void InvokeInsertCoin() private static void InvokeOnErrorInsertCoin(string error) { onError?.Invoke(error); - var errorString = JsonUtility.FromJson(error); - if (error != "") - { - throw new Exception(errorString); - } + // var errorString = JsonUtility.FromJson(error); + Debug.LogException(new Exception(error)); } private static Action onError; From ae869f7d7024915b112c4ab01a9ca73adc0d604c Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:41:08 +0500 Subject: [PATCH 7/7] chore: cleanup --- Assets/PlayroomKit/PlayroomKit.cs | 1 - Assets/PlayroomKit/src/index.js | 2 +- ProjectSettings/EditorBuildSettings.asset | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 6b19f87..cd88454 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -81,7 +81,6 @@ private static void InvokeInsertCoin() private static void InvokeOnErrorInsertCoin(string error) { onError?.Invoke(error); - // var errorString = JsonUtility.FromJson(error); Debug.LogException(new Exception(error)); } diff --git a/Assets/PlayroomKit/src/index.js b/Assets/PlayroomKit/src/index.js index 815e73e..6c01cbb 100644 --- a/Assets/PlayroomKit/src/index.js +++ b/Assets/PlayroomKit/src/index.js @@ -20,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( diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 02ee147..2f44dd1 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -5,9 +5,6 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: - - enabled: 0 - path: Assets/Scenes/Menu.unity - guid: 27215d4ccddeb6d49af03911dd97f9b1 - enabled: 1 path: Assets/Scenes/Game.unity guid: cf82eec4c654cf44b89cec2a91afebd5