Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpccall invoking even before registering in build. #118

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Assets/PlayroomKit/Examples/package-showcase/showcase.unity
Original file line number Diff line number Diff line change
Expand Up @@ -7771,6 +7771,10 @@ PrefabInstance:
propertyPath: webDriverDirectory
value: Assets\
objectReference: {fileID: 0}
- target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: mockMode
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3}
propertyPath: insertCoinCaller
value:
Expand Down
6 changes: 6 additions & 0 deletions Assets/PlayroomKit/modules/Helpers/CallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public static void InvokeCallback(string key, params string[] args)
$"Callback with key {key} not found!, maybe register the callback or call the correct playroom function?");
}
}

public static bool CheckCallback(string key)
{
return callbacks.TryGetValue(key, out Delegate callback);
}


private static string GenerateKey()
{
Expand Down
45 changes: 26 additions & 19 deletions Assets/PlayroomKit/modules/RPC/RPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,43 @@ public void RpcRegister(string name, Action<string, string> rpcRegisterCallback,

public void RpcCall(string name, object data, RpcMode mode, Action callbackOnResponse = null)
{
string jsonData = ConvertToJson(data);

if (OnResponseCallbacks.ContainsKey(name))
if (CallbackManager.CheckCallback(name))
{
OnResponseCallbacks[name].Add(callbackOnResponse);
}
else
{
OnResponseCallbacks.Add(name, new List<Action> { callbackOnResponse });
if (!RpcCalledEvents.Contains(name))
string jsonData = ConvertToJson(data);

if (OnResponseCallbacks.ContainsKey(name))
{
RpcCalledEvents.Add(name);
OnResponseCallbacks[name].Add(callbackOnResponse);
}
else
{
OnResponseCallbacks.Add(name, new List<Action> { callbackOnResponse });
if (!RpcCalledEvents.Contains(name))
{
RpcCalledEvents.Add(name);
}
}
}

JSONArray jsonArray = new JSONArray();
foreach (string item in RpcCalledEvents)
{
jsonArray.Add(item);
}
JSONArray jsonArray = new JSONArray();
foreach (string item in RpcCalledEvents)
{
jsonArray.Add(item);
}

string jsonString = jsonArray.ToString();
string jsonString = jsonArray.ToString();

/*
This is required to sync the rpc events between all players, without this players won't know which event has been called.
Update: This fix works fine for now, but there might be a better way.
this is a temporary fix, RPCs need to be handled within JSLIB for better control.
*/
_playroomKit.SetState("rpcCalledEventName", jsonString, reliable: true);
_interop.RpcCallWrapper(name, jsonData, mode, InvokeOnResponseCallback);
_playroomKit.SetState("rpcCalledEventName", jsonString, reliable: true);
_interop.RpcCallWrapper(name, jsonData, mode, InvokeOnResponseCallback);
}
else
{
Debug.LogError("RPC is not registered!, register RPC first.");
}
}

public void RpcCall(string name, object data, Action callbackOnResponse = null)
Expand Down
4 changes: 2 additions & 2 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"com.unity.cinemachine": "2.9.7",
"com.unity.collab-proxy": "2.3.1",
"com.unity.feature.2d": "2.0.0",
"com.unity.ide.rider": "3.0.28",
"com.unity.ide.rider": "3.0.34",
"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.9",
"com.unity.timeline": "1.7.6",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.9.2",
"com.unity.visualscripting": "1.9.5",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
22 changes: 11 additions & 11 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.common": "6.0.6",
"com.unity.2d.sprite": "1.0.0",
"com.unity.mathematics": "1.2.6",
"com.unity.modules.animation": "1.0.0"
},
Expand All @@ -30,11 +30,11 @@
"depth": 2,
"source": "registry",
"dependencies": {
"com.unity.burst": "1.7.3",
"com.unity.2d.sprite": "1.0.0",
"com.unity.mathematics": "1.1.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.burst": "1.7.3"
"com.unity.modules.uielements": "1.0.0"
},
"url": "https://packages.unity.com"
},
Expand All @@ -50,9 +50,9 @@
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.2d.animation": "9.1.0",
"com.unity.2d.common": "8.0.2",
"com.unity.2d.sprite": "1.0.0"
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.animation": "9.1.0"
},
"url": "https://packages.unity.com"
},
Expand All @@ -67,8 +67,8 @@
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.mathematics": "1.1.0",
"com.unity.2d.common": "8.0.1",
"com.unity.mathematics": "1.1.0",
"com.unity.modules.physics2d": "1.0.0"
},
"url": "https://packages.unity.com"
Expand All @@ -87,9 +87,9 @@
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.modules.tilemap": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ugui": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
Expand Down Expand Up @@ -162,7 +162,7 @@
}
},
"com.unity.ide.rider": {
"version": "3.0.28",
"version": "3.0.34",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down Expand Up @@ -218,9 +218,9 @@
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0"
},
"url": "https://packages.unity.com"
Expand All @@ -235,7 +235,7 @@
}
},
"com.unity.visualscripting": {
"version": "1.9.2",
"version": "1.9.5",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ EditorBuildSettings:
- enabled: 0
path: Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity
guid: cf82eec4c654cf44b89cec2a91afebd5
- enabled: 1
- enabled: 0
path: Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity
guid: bb7ef8e4a67f3fb46b78e5d95a6858a7
- enabled: 0
path: Assets/Scenes/topdown.unity
guid: 490247da3cf48784ab657a183ba059d1
- enabled: 0
- enabled: 1
path: Assets/PlayroomKit/Examples/package-showcase/showcase.unity
guid: 85c9af77ae006408ab24500b953a9035
m_configObjects: {}
Loading