Skip to content
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
84 changes: 58 additions & 26 deletions Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ private static T MockGetState<T>(string key)
}
else
{
Debug.LogError($"No {key} in States or value is not of type {typeof(T)}");
Debug.LogWarning($"No {key} in States or value is not of type {typeof(T)}");
return default;
}
}
Expand Down Expand Up @@ -1052,8 +1052,15 @@ public enum RpcMode

public static void RpcRegister(string name, Action<string, string> rpcRegisterCallback, string onResponseReturn = null)
{
rpcRegisterCallbacks.Add(name, rpcRegisterCallback);
RpcRegisterInternal(name, InvokeRpcRegisterCallBack, onResponseReturn);
if (IsRunningInBrowser())
{
rpcRegisterCallbacks.Add(name, rpcRegisterCallback);
RpcRegisterInternal(name, InvokeRpcRegisterCallBack, onResponseReturn);
}
else
{
Debug.LogError("[Mock Mode] RPC is currently not supported in Mock Mode!\n Please build the project to test RPC.");
}
}

[MonoPInvokeCallback(typeof(Action<string, string>))]
Expand Down Expand Up @@ -1106,35 +1113,40 @@ private static void InvokeRpcRegisterCallBack(string dataJson, string senderJson
public static void RpcCall(string name, object data, RpcMode mode, Action callbackOnResponse)
{

string jsonData = ConvertToJson(data);

if (OnResponseCallbacks.ContainsKey(name))
{
OnResponseCallbacks[name].Add(callbackOnResponse);
}
else
if (IsRunningInBrowser())
{
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);
}
string jsonString = jsonArray.ToString();
/*
This is requrired to sync the rpc events between all players, without this players won't know which event has been called.
this is a temporary fix, RPC's need to be handled within JS for better control.
*/
SetState("rpcCalledEventName", jsonString, reliable: true);

JSONArray jsonArray = new JSONArray();
foreach (string item in rpcCalledEvents)
RpcCallInternal(name, jsonData, mode, InvokeOnResponseCallback);
}
else
{
jsonArray.Add(item);
Debug.LogError("[Mock Mode] RPC Calls are not supported in Mock Mode! yet.\nPlease make a build to test RPC.");
}
string jsonString = jsonArray.ToString();
/*
This is requrired to sync the rpc events between all players, without this players won't know which event has been called.
this is a temporary fix, RPC's need to be handled within JS for better control.
*/
SetState("rpcCalledEventName", jsonString, reliable: true);

RpcCallInternal(name, jsonData, mode, InvokeOnResponseCallback);
}

// Default Mode
Expand Down Expand Up @@ -1236,7 +1248,27 @@ private static string ConvertComplexToJson(object data)
}

[DllImport("__Internal")]
public static extern void StartMatchmaking();
public static extern void StartMatchmakingInternal(Action callback);

static Action startMatchmakingCallback = null;
public static void StartMatchmaking(Action callback = null)
{
if (IsRunningInBrowser())
{
startMatchmakingCallback = callback;
StartMatchmakingInternal(InvokeStartMatchmakingCallback);
}
else
{
Debug.LogError("[Mock Mode] Matchmaking is not supported in Mock Mode! yet.\nPlease build the project to test Matchmaking.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the namespacing in the logs. Good job.

}
}

[MonoPInvokeCallback(typeof(Action))]
private static void InvokeStartMatchmakingCallback()
{
startMatchmakingCallback?.Invoke();
}

// Player class
public class Player
Expand Down
Loading