diff --git a/Assets/PlayroomKit/Editor/PlayroomDevEditor.cs b/Assets/PlayroomKit/Editor/PlayroomDevEditor.cs index 070c290..7467626 100644 --- a/Assets/PlayroomKit/Editor/PlayroomDevEditor.cs +++ b/Assets/PlayroomKit/Editor/PlayroomDevEditor.cs @@ -41,10 +41,12 @@ public override VisualElement CreateInspectorGUI() VisualElement insertCoinContainer = InsertCoinContainerCreator(); Button launchPlayerButton = LaunchPlayerButtonCreator(); VisualElement docsLink = DocumentationLinkCreator(); + VisualElement enableLogsToggle = EnableLogsToggleCreator(); // Add elements to root root.Add(mockModeContainer); root.Add(insertCoinContainer); + root.Add(enableLogsToggle); root.Add(launchPlayerButton); root.Add(docsLink); @@ -170,6 +172,52 @@ private static VisualElement DocumentationLinkCreator() return docLink; } + + private VisualElement EnableLogsToggleCreator() + { + // Create a horizontal container + VisualElement enableLogsContainer = new VisualElement(); + enableLogsContainer.style.flexDirection = FlexDirection.Row; // Arrange items horizontally + + // Create the label for Enable Logs + var enableLogsLabel = new Label("Enable Logs"); + enableLogsLabel.AddToClassList("label"); // Add consistent styling + + // Create the tooltip button + var debugToggleToolTip = new Button(() => { }) + { + text = "?", + tooltip = "Enable or disable logging for debugging purposes." + }; + debugToggleToolTip.AddToClassList("tooltip-button"); + + // Create the toggle + var enableLogsToggle = new Toggle(); + enableLogsToggle.AddToClassList("toggle"); // Apply consistent styling to the toggle + + // Manually bind the property if BindProperty isn't supported + var enableLogsProperty = serializedObject.FindProperty("enableLogs"); + + // Set the initial value + enableLogsToggle.value = enableLogsProperty.boolValue; + + // Register value changed callback + enableLogsToggle.RegisterValueChangedCallback(evt => + { + enableLogsProperty.boolValue = evt.newValue; + serializedObject.ApplyModifiedProperties(); + }); + + // Add the elements to the container in the desired order + enableLogsContainer.Add(enableLogsLabel); // Add label first + enableLogsContainer.Add(debugToggleToolTip); // Add tooltip button next + enableLogsContainer.Add(enableLogsToggle); // Add toggle last + + return enableLogsContainer; + } + + + } } #endif \ No newline at end of file diff --git a/Assets/PlayroomKit/Editor/PlayroomkitDevManagerEditor.uss b/Assets/PlayroomKit/Editor/PlayroomkitDevManagerEditor.uss index 2f48198..e39718d 100644 --- a/Assets/PlayroomKit/Editor/PlayroomkitDevManagerEditor.uss +++ b/Assets/PlayroomKit/Editor/PlayroomkitDevManagerEditor.uss @@ -88,4 +88,12 @@ align-self: center; color: aqua; +} + +.toggle { + height: 25px; + font-size: 14px; + -unity-text-align: middle-center; + margin-left: 32px; + margin-bottom: 32px; } \ No newline at end of file diff --git a/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity b/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity index 160525e..620863a 100644 --- a/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity +++ b/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity @@ -307,13 +307,17 @@ PrefabInstance: propertyPath: insertCoinCaller value: objectReference: {fileID: 330732768} + - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: browser + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: webDriverDirectory value: Assets\ objectReference: {fileID: 0} - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: mockMode - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: insertCoinCaller diff --git a/Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity b/Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity index 8e487b2..31f37cf 100644 --- a/Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity +++ b/Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity @@ -226,6 +226,10 @@ PrefabInstance: propertyPath: mockMode value: 1 objectReference: {fileID: 0} + - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: enableLogs + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: insertCoinCaller value: diff --git a/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs b/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs index 5730087..5837975 100644 --- a/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs +++ b/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs @@ -54,7 +54,7 @@ private void Update() { Debug.Log("Space Down"); _playroomKit.RpcCall("one", "69420", PlayroomKit.RpcMode.ALL); - _playroomKit.RpcCall("two", "2", PlayroomKit.RpcMode.ALL); + // _playroomKit.RpcCall("two", "2", PlayroomKit.RpcMode.ALL); } var myPlayer = _playroomKit.MyPlayer(); @@ -77,7 +77,6 @@ private void Update() if (playerGameObjects[i] != null) { playerGameObjects[i].GetComponent().SetPositionAndRotation(pos, rotate); - playerGameObjects[i].GetComponent().material.color = color; } } diff --git a/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs b/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs index 161fcf1..e45d7cc 100644 --- a/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs +++ b/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs @@ -93,7 +93,6 @@ private void AddPlayer(PlayroomKit.Player player) } - [MonoPInvokeCallback(typeof(Action))] private void RemovePlayer(string playerID) { if (PlayerDict.TryGetValue(playerID, out var player)) @@ -239,15 +238,15 @@ public void HandleValueChange(int index) public void RegisterRpcShoot() { - _playroomKit.RpcRegister("ShootLaser", HandleScoreUpdate, "You shot a bullet!"); + _playroomKit.RpcRegister("ShootLaser", HandleScoreUpdate); + Debug.Log("Shoot function registered"); logsText.text = "ShootLaser RPC registered"; } private void HandleScoreUpdate(string data, string caller) { - var player = _playroomKit.GetPlayer(caller); - Debug.Log($"Caller: {caller}, Player Name: {player?.GetProfile().name}, Data: {data}"); + Debug.LogWarning("Handle Score Called"); if (PlayerDict.TryGetValue(caller, out var playerObj)) { @@ -274,6 +273,7 @@ public void ShootLaser() var myPlayer = _playroomKit.MyPlayer(); var index = players.IndexOf(myPlayer); score = playerGameObjects[index].GetComponent().ShootLaser(score); + _playroomKit.RpcCall("ShootLaser", score, PlayroomKit.RpcMode.ALL, () => { diff --git a/Assets/PlayroomKit/Examples/package-showcase/showcase.unity b/Assets/PlayroomKit/Examples/package-showcase/showcase.unity index c377cf5..bf989b0 100644 --- a/Assets/PlayroomKit/Examples/package-showcase/showcase.unity +++ b/Assets/PlayroomKit/Examples/package-showcase/showcase.unity @@ -6771,6 +6771,79 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1826344565} m_CullTransparentMesh: 1 +--- !u!1001 &1855243287 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 1824217503633254899, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_Name + value: PlayroomMockManager + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalPosition.x + value: -0.3 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: webDriverDirectory + value: Assets\ + objectReference: {fileID: 0} + - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: mockMode + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: enableLogs + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: insertCoinCaller + value: + objectReference: {fileID: 893908560} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} --- !u!1 &1883683081 GameObject: m_ObjectHideFlags: 0 @@ -7715,75 +7788,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2143370850} m_CullTransparentMesh: 1 ---- !u!1001 &2854658873105489201 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 1824217503633254899, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_Name - value: PlayroomMockManager - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalPosition.x - value: -0.3 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 4611920177403363027, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: webDriverDirectory - value: Assets\ - objectReference: {fileID: 0} - - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: mockMode - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} - propertyPath: insertCoinCaller - value: - objectReference: {fileID: 893908560} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -7795,4 +7799,4 @@ SceneRoots: - {fileID: 417229588} - {fileID: 1643951926} - {fileID: 181053975} - - {fileID: 2854658873105489201} + - {fileID: 1855243287} diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index a4c0cf5..83324af 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -31,17 +31,14 @@ public PlayroomKit() _rpc = new RPC(this); #elif UNITY_EDITOR - switch (CurrentMockMode) { case MockModeSelector.Local: - Debug.Log("Starting playroom in Local Mock Mode"); _playroomService = new LocalMockPlayroomService(); _rpc = new RPCLocal(); break; case MockModeSelector.Browser: - Debug.Log("Starting playroom in Browser Mock Mode"); _playroomService = new BrowserMockService(); _rpc = new BrowserMockRPC(); break; diff --git a/Assets/PlayroomKit/Prefabs/PlayroomMockManager.prefab b/Assets/PlayroomKit/Prefabs/PlayroomMockManager.prefab index 2c4876b..1478b30 100644 --- a/Assets/PlayroomKit/Prefabs/PlayroomMockManager.prefab +++ b/Assets/PlayroomKit/Prefabs/PlayroomMockManager.prefab @@ -10,7 +10,6 @@ GameObject: m_Component: - component: {fileID: 4611920177403363027} - component: {fileID: 8987662522597341863} - - component: {fileID: 7325353642485059119} m_Layer: 0 m_Name: PlayroomMockManager m_TagString: EditorOnly @@ -49,19 +48,7 @@ MonoBehaviour: m_EditorClassIdentifier: mockMode: 1 insertCoinCaller: {fileID: 0} ---- !u!114 &7325353642485059119 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1824217503633254899} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 37df37ffbaed24d5f858db19670affdf, type: 3} - m_Name: - m_EditorClassIdentifier: - logToggle: {fileID: 0} + enableLogs: 0 --- !u!1 &5935941862803782869 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs b/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs index 2adebdc..041fd1d 100644 --- a/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs +++ b/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs @@ -9,6 +9,43 @@ public static class CallbackManager { private static Dictionary callbacks = new(); + private static Dictionary>> RpcCallBacks = new(); + + public static string RegisterRpcCallback(Action callback, string key = null) + { + if (string.IsNullOrEmpty(key)) + key = GenerateKey(); + + if (RpcCallBacks.ContainsKey(key)) + { + RpcCallBacks[key].Add(callback); + } + else + { + RpcCallBacks.Add(key, new List> { callback }); + } + + return key; + } + + public static void InvokeRpcRegisterCallBack(string name, string data, string sender) + { + if (RpcCallBacks.TryGetValue(name, out List> callbacks)) + { + for (var i = 0; i < callbacks.Count; i++) + { + var callback = callbacks[i]; + callback?.Invoke(data, sender); + } + } + else + { + Debug.LogWarning( + $"Callback with key {name} not found!, maybe register the callback or call the correct playroom function?"); + } + } + + public static string RegisterCallback(Delegate callback, string key = null) { if (string.IsNullOrEmpty(key)) @@ -38,8 +75,19 @@ public static void InvokeCallback(string key, params string[] args) Debug.LogError( $"Callback with key {key} is of unsupported type or incorrect number of arguments: {args[0]}!"); } + else + { + Debug.LogWarning( + $"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() { return Guid.NewGuid().ToString(); diff --git a/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs b/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs deleted file mode 100644 index 5f27d62..0000000 --- a/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs +++ /dev/null @@ -1,17 +0,0 @@ -using UnityEngine; - -public class DebugToggle : MonoBehaviour -{ - [SerializeField] private bool enableLogs = false; - - private void Start() - { - DebugLogger.enableLogs = enableLogs; - } - - private void ToggleLogs(bool isEnabled) - { - DebugLogger.enableLogs = isEnabled; - } -} - diff --git a/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs.meta b/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs.meta deleted file mode 100644 index 21f27e9..0000000 --- a/Assets/PlayroomKit/modules/Helpers/DebugToggle.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 37df37ffbaed24d5f858db19670affdf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs b/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs index 5b438d8..a3a7dfd 100644 --- a/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs +++ b/Assets/PlayroomKit/modules/Interfaces/IPlayroomBase.cs @@ -58,7 +58,7 @@ protected static void __OnPlayerJoinCallbackHandler(string id) protected static void OnPlayerJoinWrapperCallback(string id) { var player = GetPlayerById(id); - foreach (var callback in IPlayroomBase.OnPlayerJoinCallbacks) + foreach (var callback in OnPlayerJoinCallbacks) { callback?.Invoke(player); } diff --git a/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs b/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs index ab10d0b..cbc104f 100644 --- a/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs +++ b/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs @@ -97,7 +97,7 @@ public Profile GetProfile() public Action OnQuit(Action callback) { - Debug.Log($"OnQuit is not supported in Local Mock Mode."); + DebugLogger.Log($"OnQuit is not supported in Local Mock Mode."); return null; } diff --git a/Assets/PlayroomKit/modules/Player/Player.cs b/Assets/PlayroomKit/modules/Player/Player.cs index fb431d3..1513a3e 100644 --- a/Assets/PlayroomKit/modules/Player/Player.cs +++ b/Assets/PlayroomKit/modules/Player/Player.cs @@ -136,22 +136,19 @@ public void WaitForState(string StateKey, Action onStateSetCallback = nu _playerService.WaitForState(StateKey, onStateSetCallback); } - + public void InvokePlayerOnQuitCallback() { _playerService.InvokePlayerOnQuitCallback(id); } - //DI END - [Serializable] public class Profile { [NonSerialized] public UnityEngine.Color color; - - [FormerlySerializedAs("jsonColor")] + public PlayerProfileColor playerProfileColor; public string name; public string photo; diff --git a/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs b/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs deleted file mode 100644 index 7744550..0000000 --- a/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs +++ /dev/null @@ -1,30 +0,0 @@ -// using System; -// using UnityEngine.Serialization; -// -// namespace Playroom -// { -// public partial class PlayroomKit -// { -// -// [Serializable] -// public class Profile -// { -// [NonSerialized] public UnityEngine.Color color; -// -// [FormerlySerializedAs("jsonColor")] public PlayerProfileColor playerProfileColor; -// public string name; -// public string photo; -// -// [Serializable] -// public class PlayerProfileColor -// { -// public int r; -// public int g; -// public int b; -// public string hexString; -// public int hex; -// } -// } -// } -// } -// diff --git a/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs.meta b/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs.meta deleted file mode 100644 index b17a6cf..0000000 --- a/Assets/PlayroomKit/modules/Player/PlayerHelpers.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 12dfc03fda994408822f84014a0a6478 -timeCreated: 1730208351 \ No newline at end of file diff --git a/Assets/PlayroomKit/modules/Player/PlayerService.cs b/Assets/PlayroomKit/modules/Player/PlayerService.cs index 99744e6..c6e5526 100644 --- a/Assets/PlayroomKit/modules/Player/PlayerService.cs +++ b/Assets/PlayroomKit/modules/Player/PlayerService.cs @@ -154,11 +154,12 @@ public void Kick(Action onKickCallBack = null) private static Action onSetState; + public void WaitForState(string stateKey, Action onStateSetCallback = null) { onSetState = onStateSetCallback; } - + [MonoPInvokeCallback(typeof(Action))] private static void InvokeKickCallBack(string data) { @@ -179,11 +180,6 @@ public void OnQuitWrapperCallback(string id) callback?.Invoke(id); } - public void InvokeOnQuitWrapperCallback(string id) - { - OnQuitWrapperCallback(id); - } - private bool GetPlayerStateBoolById(string key) { var stateValue = _interop.GetPlayerStateIntWrapper(_id, key); @@ -191,8 +187,6 @@ private bool GetPlayerStateBoolById(string key) stateValue == 0 ? false : throw new InvalidOperationException($"GetStateBool: {key} is not a bool"); } - - } } } diff --git a/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs b/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs index 2a0e7cb..05c9e23 100644 --- a/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs +++ b/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs @@ -18,6 +18,8 @@ public class PlayroomkitDevManager : MonoBehaviour "InsertCoin() must be called in order to connect PlayroomKit server.\n\nChoose the gameObject (with the script) which calls InsertCoin.\n\nRead More in the docs")] [SerializeField] private GameObject insertCoinCaller; + + [SerializeField] private bool enableLogs = false; private static PlayroomkitDevManager Instance { get; set; } @@ -34,6 +36,8 @@ private void Awake() Destroy(gameObject); } + DebugLogger.enableLogs = enableLogs; + UpdateMockMode(); UnityBrowserBridge.Instance.RegisterGameObject("InsertCoin", insertCoinCaller); UnityBrowserBridge.Instance.RegisterGameObject("devManager", gameObject); @@ -41,7 +45,9 @@ private void Awake() private void OnValidate() { + DebugLogger.enableLogs = enableLogs; UpdateMockMode(); + DebugLogger.Log("Setting Current Mode to: " + PlayroomKit.CurrentMockMode); } private void UpdateMockMode() diff --git a/Assets/PlayroomKit/modules/RPC/RPC.cs b/Assets/PlayroomKit/modules/RPC/RPC.cs index 62dc2c3..3a9923b 100644 --- a/Assets/PlayroomKit/modules/RPC/RPC.cs +++ b/Assets/PlayroomKit/modules/RPC/RPC.cs @@ -36,43 +36,42 @@ public RPC(PlayroomKit playroomKit, IInterop interop) public void RpcRegister(string name, Action rpcRegisterCallback, string onResponseReturn = null) { - CallbackManager.RegisterCallback(rpcRegisterCallback, name); + CallbackManager.RegisterRpcCallback(rpcRegisterCallback, name); _interop.RpcRegisterWrapper(name, InvokeRpcRegisterCallBack, onResponseReturn); } public void RpcCall(string name, object data, RpcMode mode, Action callbackOnResponse = null) { - string jsonData = ConvertToJson(data); + string jsonData = ConvertToJson(data); - if (OnResponseCallbacks.ContainsKey(name)) - { - OnResponseCallbacks[name].Add(callbackOnResponse); - } - else + if (OnResponseCallbacks.ContainsKey(name)) + { + OnResponseCallbacks[name].Add(callbackOnResponse); + } + else + { + OnResponseCallbacks.Add(name, new List { callbackOnResponse }); + if (!RpcCalledEvents.Contains(name)) { - OnResponseCallbacks.Add(name, new List { callbackOnResponse }); - if (!RpcCalledEvents.Contains(name)) - { - RpcCalledEvents.Add(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); } public void RpcCall(string name, object data, Action callbackOnResponse = null) @@ -130,26 +129,24 @@ protected static void InvokeRpcRegisterCallBack(string dataJson, string senderJs Debug.LogError(ex.Message); } - List updatedRpcCalledEvents = new(); // This state is required to update the called rpc events list, (Temp fix see RpcCall for more) string nameJson = _playroomKit.GetState("rpcCalledEventName"); - Debug.Log($"rpcCalledEventName {nameJson}: {dataJson}"); - JSONArray jsonArray = JSON.Parse(nameJson).AsArray; foreach (JSONNode node in jsonArray) { string item = node.Value; updatedRpcCalledEvents.Add(item); } - - foreach (string name in updatedRpcCalledEvents) + + for (var i = 0; i < updatedRpcCalledEvents.Count; i++) { - CallbackManager.InvokeCallback(name, dataJson, senderJson); + string name = updatedRpcCalledEvents[i]; + CallbackManager.InvokeRpcRegisterCallBack(name, dataJson, senderJson); } } - + #endregion #region Helpers diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index b12f361..57c333e 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -13,18 +13,23 @@ public class GameManager : MonoBehaviour /// /// List of players and their gameObjects. /// - [SerializeField] private List players = new(); + [SerializeField] + private List players = new(); private static readonly List playerGameObjects = new(); private static readonly Dictionary PlayerDict = new(); - [SerializeField] private GameObject playerPrefab; + [SerializeField] + private GameObject playerPrefab; - [SerializeField] private TextMeshProUGUI playerIDText; - [SerializeField] private TextMeshProUGUI score; + [SerializeField] + private TextMeshProUGUI playerIDText; + [SerializeField] + private TextMeshProUGUI score; - [SerializeField] private string playerID; + [SerializeField] + private string playerID; private PlayroomKit _playroomKit = new PlayroomKit(); @@ -37,12 +42,12 @@ void Start() }, () => { _playroomKit.OnPlayerJoin(AddPlayer); - _playroomKit.RpcRegister("score", (data, caller) => print($"{data} by {_playroomKit.GetPlayer(caller).GetProfile().name}")); + _playroomKit.RpcRegister("score", + (data, caller) => print($"{data} by {_playroomKit.GetPlayer(caller).GetProfile().name}")); }, () => { Debug.Log("OnDisconnect callback"); }); } - - - + + /// /// Update the player position and sync. /// diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 2f81a5e..71d6a92 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -675,7 +675,7 @@ PlayerSettings: webGLDebugSymbols: 0 webGLEmscriptenArgs: webGLModulesDirectory: - webGLTemplate: PROJECT:DiscordTemplate + webGLTemplate: APPLICATION:Default webGLAnalyzeBuildSize: 0 webGLUseEmbeddedResources: 0 webGLCompressionFormat: 2 diff --git a/readme.md b/readme.md index 790ba21..336b9a6 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,11 @@

PlayroomKit SDK for Unity

The easiest multiplayer infrastructure for the web

+ +
+ +
-