diff --git a/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity b/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity index 34f52d2..160525e 100644 --- a/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity +++ b/Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity @@ -313,7 +313,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: mockMode - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8987662522597341863, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: insertCoinCaller diff --git a/Assets/PlayroomKit/Examples/2d-platformer/scripts/GameManager2d.cs b/Assets/PlayroomKit/Examples/2d-platformer/scripts/GameManager2d.cs index 8da38b9..a765c57 100644 --- a/Assets/PlayroomKit/Examples/2d-platformer/scripts/GameManager2d.cs +++ b/Assets/PlayroomKit/Examples/2d-platformer/scripts/GameManager2d.cs @@ -114,8 +114,9 @@ private void Update() for (var i = 0; i < players.Count; i++) { - if (players[i] != null) + if (players[i] != null && PlayerDict.TryGetValue(players[i].id, out GameObject playerObj)) { + Debug.Log("Getting state of: " + players[i].id); var pos = players[i].GetState("pos"); Debug.Log(pos); @@ -176,7 +177,6 @@ public void AddPlayer(PlayroomKit.Player player) /// /// Remove player from the game, called when the player leaves / closes the game. /// - [MonoPInvokeCallback(typeof(Action))] private static void RemovePlayer(string playerID) { if (PlayerDict.TryGetValue(playerID, out GameObject player)) diff --git a/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs b/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs index bd60052..5730087 100644 --- a/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs +++ b/Assets/PlayroomKit/Examples/discord-activity/scripts/GameManagerIsometric.cs @@ -32,17 +32,17 @@ private void Start() matchmaking = false, discord = true, gameId = "ii4pV1wfceCjjLvRoo3O", - roomCode = roomCode, + roomCode = "roomCode", }, () => { _playroomKit.OnPlayerJoin(AddPlayer); _playroomKit.RpcRegister("one", ((data, player) => { Debug.LogWarning("One Event Called"); })); - + _playroomKit.RpcRegister("two", ((data, player) => { Debug.LogWarning("two Event Called"); })); - - _playroomKit.RpcRegister("one", ((data, player) => { Debug.LogWarning("One Event Called With a diff callback"); })); - + + _playroomKit.RpcRegister("one", + ((data, player) => { Debug.LogWarning("One Event Called With a diff callback"); })); }, () => { Debug.Log("OnDisconnect callback"); }); } @@ -68,7 +68,7 @@ private void Update() for (var i = 0; i < players.Count; i++) { - if (players[i] != null) + if (players[i] != null && PlayerDict.TryGetValue(players[i].id, out GameObject playerObj)) { var pos = players[i].GetState("move"); var rotate = players[i].GetState("angle"); @@ -103,16 +103,17 @@ private void AddPlayer(PlayroomKit.Player player) player.OnQuit(RemovePlayer); } - // FIX: - [MonoPInvokeCallback(typeof(Action))] private static void RemovePlayer(string playerID) { - Debug.Log("Here?"); if (PlayerDict.TryGetValue(playerID, out var player)) { PlayerDict.Remove(playerID); playerGameObjects.Remove(player); Destroy(player); + + foreach (var (key, value) in PlayerDict) Debug.Log($"player {key} is still in the room"); + + Debug.Log(playerID + " has left the room!"); } else { diff --git a/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs b/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs index bcc79ea..161fcf1 100644 --- a/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs +++ b/Assets/PlayroomKit/Examples/package-showcase/scripts/GameManagerDemo.cs @@ -275,7 +275,10 @@ public void ShootLaser() var index = players.IndexOf(myPlayer); score = playerGameObjects[index].GetComponent().ShootLaser(score); _playroomKit.RpcCall("ShootLaser", score, PlayroomKit.RpcMode.ALL, - () => { logsText.text = "ShootLaser RPC Called"; }); + () => + { + Debug.Log("ShootLaser RPC Called"); + logsText.text = "ShootLaser RPC Called"; }); } public void GetRoomCode() diff --git a/Assets/PlayroomKit/Examples/package-showcase/showcase.unity b/Assets/PlayroomKit/Examples/package-showcase/showcase.unity index c377cf5..8d67717 100644 --- a/Assets/PlayroomKit/Examples/package-showcase/showcase.unity +++ b/Assets/PlayroomKit/Examples/package-showcase/showcase.unity @@ -7767,6 +7767,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} + propertyPath: httpServerPort + value: 6510 + objectReference: {fileID: 0} - target: {fileID: 8899696337967424923, guid: 1b30fa3a265114a45a7e23165a20aecc, type: 3} propertyPath: webDriverDirectory value: Assets\ diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 3421080..25dcd6c 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -29,18 +29,26 @@ public PlayroomKit() #if !UNITY_EDITOR _playroomService = new PlayroomBuildService(new PlayroomKitInterop()); _rpc = new RPC(this); - #elif UNITY_EDITOR - if (CurrentMockMode == MockModeSelector.Local) - { - _playroomService = new LocalMockPlayroomService(); - _rpc = new RPCLocal(); - } - else if (CurrentMockMode == MockModeSelector.Browser) + + switch (CurrentMockMode) { - _playroomService = new BrowserMockService(); - _rpc = new BrowserMockRPC(); + 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; + default: + _playroomService = new LocalMockPlayroomService(); + _rpc = new RPCLocal(); + break; } #endif } @@ -89,14 +97,15 @@ public Player GetPlayer(string playerId) else { #if UNITY_EDITOR - if (CurrentMockMode == MockModeSelector.Local) - { - player = new Player(playerId, new Player.LocalPlayerService(playerId)); - } - else if (CurrentMockMode == MockModeSelector.Browser) + switch (CurrentMockMode) { - player = new Player(playerId, - new BrowserMockPlayerService(UnityBrowserBridge.Instance, playerId)); + case MockModeSelector.Local: + player = new Player(playerId, new Player.LocalPlayerService(playerId)); + break; + case MockModeSelector.Browser: + player = new Player(playerId, + new BrowserMockPlayerService(UnityBrowserBridge.Instance, playerId)); + break; } #else player = new Player(playerId, new Player.PlayerService(playerId)); @@ -301,7 +310,5 @@ private void UnsubscribeOnQuit() { _playroomService.UnsubscribeOnQuit(); } - - // DI END } } \ No newline at end of file diff --git a/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs b/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs index 019fa9d..2adebdc 100644 --- a/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs +++ b/Assets/PlayroomKit/modules/Helpers/CallbackManager.cs @@ -8,7 +8,7 @@ namespace Playroom public static class CallbackManager { private static Dictionary callbacks = new(); - + public static string RegisterCallback(Delegate callback, string key = null) { if (string.IsNullOrEmpty(key)) @@ -38,18 +38,7 @@ 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() { diff --git a/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs b/Assets/PlayroomKit/modules/Player/LocalPlayerService.cs index 3060324..6eb6108 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 implemented for local"); + Debug.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 ce43740..9aff8a1 100644 --- a/Assets/PlayroomKit/modules/Player/Player.cs +++ b/Assets/PlayroomKit/modules/Player/Player.cs @@ -136,6 +136,23 @@ public void WaitForState(string StateKey, Action onStateSetCallback = nu _playerService.WaitForState(StateKey, onStateSetCallback); } + + public void InvokePlayerOnQuitCallback() + { + // Attempt the cast and throw an exception if it fails + if ((_playerService is PlayerService playerService)) + { + playerService.InvokePlayerOnQuitCallback(id); + } + else + { + Debug.LogWarning("InvokePlayerOnQuitCallback is only supported o build"); + } + + // Invoke the method on the casted object + + } + //DI END diff --git a/Assets/PlayroomKit/modules/Player/PlayerService.cs b/Assets/PlayroomKit/modules/Player/PlayerService.cs index 9f04196..0c3acca 100644 --- a/Assets/PlayroomKit/modules/Player/PlayerService.cs +++ b/Assets/PlayroomKit/modules/Player/PlayerService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Runtime.CompilerServices; using UnityEngine; using System.Runtime.InteropServices; using AOT; @@ -139,6 +140,11 @@ void Unsubscribe() return Unsubscribe; } + internal void InvokePlayerOnQuitCallback(string id) + { + OnQuitWrapperCallback(id); + } + public void Kick(Action onKickCallBack = null) { @@ -167,14 +173,14 @@ private static void InvokeKickCallBack() } [MonoPInvokeCallback(typeof(Action))] - private void OnQuitWrapperCallback(string id) + public void OnQuitWrapperCallback(string id) { if (OnQuitCallbacks != null) foreach (var callback in OnQuitCallbacks) callback?.Invoke(id); } - void InvokeOnQuitWrapperCallback(string id) + public void InvokeOnQuitWrapperCallback(string id) { OnQuitWrapperCallback(id); } @@ -186,6 +192,8 @@ private bool GetPlayerStateBoolById(string key) stateValue == 0 ? false : throw new InvalidOperationException($"GetStateBool: {key} is not a bool"); } + + } } } diff --git a/Assets/PlayroomKit/modules/PlayroomService.cs b/Assets/PlayroomKit/modules/PlayroomService.cs index fecb767..538e758 100644 --- a/Assets/PlayroomKit/modules/PlayroomService.cs +++ b/Assets/PlayroomKit/modules/PlayroomService.cs @@ -213,7 +213,7 @@ private static void __OnQuitInternalHandler(string playerId) { if (Players.TryGetValue(playerId, out Player player)) { - throw new NotImplementedException(); //implement OnQuitWrapperCallback; + player.InvokePlayerOnQuitCallback(); } else { diff --git a/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs b/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs index e543f69..4750ae5 100644 --- a/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs +++ b/Assets/PlayroomKit/modules/PlayroomkitDevManager.cs @@ -47,7 +47,6 @@ private void OnValidate() private void UpdateMockMode() { PlayroomKit.CurrentMockMode = mockMode; - } /// diff --git a/Assets/PlayroomKit/modules/RPC/RPC.cs b/Assets/PlayroomKit/modules/RPC/RPC.cs index 051d43a..62dc2c3 100644 --- a/Assets/PlayroomKit/modules/RPC/RPC.cs +++ b/Assets/PlayroomKit/modules/RPC/RPC.cs @@ -42,8 +42,6 @@ public void RpcRegister(string name, Action rpcRegisterCallback, public void RpcCall(string name, object data, RpcMode mode, Action callbackOnResponse = null) { - if (CallbackManager.CheckCallback(name)) - { string jsonData = ConvertToJson(data); if (OnResponseCallbacks.ContainsKey(name)) @@ -74,11 +72,7 @@ public void RpcCall(string name, object data, RpcMode mode, Action callbackOnRes */ _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) diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index ab0bf7e..0273124 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -5,18 +5,12 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 m_Scenes: - - enabled: 0 - path: Assets/Scenes/Lobby.unity - guid: 27215d4ccddeb6d49af03911dd97f9b1 - enabled: 0 path: Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity guid: cf82eec4c654cf44b89cec2a91afebd5 - enabled: 0 path: Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity guid: bb7ef8e4a67f3fb46b78e5d95a6858a7 - - enabled: 0 - path: Assets/Scenes/topdown.unity - guid: 490247da3cf48784ab657a183ba059d1 - enabled: 1 path: Assets/PlayroomKit/Examples/package-showcase/showcase.unity guid: 85c9af77ae006408ab24500b953a9035