-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separated native functions and mockmode
- Loading branch information
Showing
6 changed files
with
169 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
|
||
namespace Playroom | ||
{ | ||
public partial class PlayroomKit | ||
{ | ||
[DllImport("__Internal")] | ||
private static extern void InsertCoinInternal(string options, | ||
Action<string> onLaunchCallback, | ||
Action<string> onQuitInternalCallback, | ||
Action<string> onDisconnectCallback, | ||
Action<string> onError, | ||
string onLaunchCallBackKey, | ||
string onDisconnectCallBackKey); | ||
|
||
[DllImport("__Internal")] | ||
private static extern string OnPlayerJoinInternal(Action<string> callback); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void UnsubscribeOnPlayerJoinInternal(string id); | ||
|
||
[DllImport("__Internal")] | ||
private static extern bool IsHostInternal(); | ||
|
||
[DllImport("__Internal")] | ||
private static extern bool IsStreamModeInternal(); | ||
|
||
[DllImport("__Internal")] | ||
private static extern string MyPlayerInternal(); | ||
|
||
[DllImport("__Internal")] | ||
public static extern string GetRoomCode(); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void OnDisconnectInternal(Action<string> callback); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void SetStateString(string key, string value, bool reliable = false); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void SetStateInternal(string key, int value, bool reliable = false); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void SetStateInternal(string key, bool value, bool reliable = false); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void SetStateFloatInternal(string key, string floatAsString, bool reliable = false); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void SetStateDictionary(string key, string jsonValues, bool reliable = false); | ||
|
||
[DllImport("__Internal")] | ||
private static extern string GetStateStringInternal(string key); | ||
|
||
[DllImport("__Internal")] | ||
private static extern int GetStateIntInternal(string key); | ||
|
||
[DllImport("__Internal")] | ||
private static extern float GetStateFloatInternal(string key); | ||
|
||
[DllImport("__Internal")] | ||
private static extern string GetStateDictionaryInternal(string key); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void WaitForStateInternal(string stateKey, Action<string, string> onStateSetCallback); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void WaitForPlayerStateInternal(string playerID, string StateKey, Action onStateSetCallback); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void ResetStatesInternal(string keysToExclude = null, Action OnStatesReset = null); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void ResetPlayersStatesInternal(string keysToExclude, Action OnPlayersStatesReset = null); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void UnsubscribeOnQuitInternal(); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void CreateJoystickInternal(string joyStickOptionsJson); | ||
|
||
[DllImport("__Internal")] | ||
private static extern string DpadJoystickInternal(); | ||
|
||
[DllImport("__Internal")] | ||
private static extern void StartMatchmakingInternal(Action callback); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Buffers.Text; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Playroom | ||
{ | ||
public partial class PlayroomKit | ||
{ | ||
private const string PlayerId = "mockPlayer"; | ||
private static bool mockIsStreamMode; | ||
|
||
/* | ||
This is private, instead of public, to prevent tampering in Mock Mode. | ||
Reason: In Mock Mode, only a single player can be tested. | ||
Ref: https://docs.joinplayroom.com/usage/unity#mock-mode | ||
*/ | ||
private static Dictionary<string, object> MockDictionary = new(); | ||
|
||
public static void MockSetState(string key, object value) | ||
{ | ||
if (MockDictionary.ContainsKey(key)) | ||
MockDictionary[key] = value; | ||
else | ||
MockDictionary.Add(key, value); | ||
} | ||
|
||
public static T MockGetState<T>(string key) | ||
{ | ||
if (MockDictionary.TryGetValue(key, out var value) && value is T typedValue) | ||
{ | ||
return typedValue; | ||
} | ||
else | ||
{ | ||
Debug.LogWarning($"No {key} in States or value is not of type {typeof(T)}"); | ||
return default; | ||
} | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.