From 6494eb6b054cf1024c0f1ba9a2db72952c948920 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Wed, 17 Apr 2024 22:48:23 +0500 Subject: [PATCH 1/3] fix: resolved #53 --- Assets/PlayroomKit/PlayroomKit.cs | 12 +++++++-- Assets/Scripts/GameManager.cs | 41 +++++++++---------------------- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index b9dc00a..23deebe 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -1074,6 +1074,8 @@ public static void RpcCall(string name, object data, Action callbackOnResponse) [MonoPInvokeCallback(typeof(Action))] private static void InvokeOnResponseCallback() { + var namesToRemove = new List(); + foreach (var name in RpcEventNames) { try @@ -1085,8 +1087,7 @@ private static void InvokeOnResponseCallback() callback?.Invoke(); } - RpcEventNames.Remove(name); - OnResponseCallbacks.Remove(name); + namesToRemove.Add(name); } } catch (Exception ex) @@ -1094,6 +1095,13 @@ private static void InvokeOnResponseCallback() Debug.LogError($"C#: Error in Invoking callback for RPC event name: '{name}': {ex.Message}"); } } + + // Remove the names after the loop + foreach (var name in namesToRemove) + { + RpcEventNames.Remove(name); + OnResponseCallbacks.Remove(name); + } } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 58fea9a..eecaac2 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -23,12 +23,12 @@ public class GameManager : MonoBehaviour [SerializeField] private static bool playerJoined; + [SerializeField] private Text scoreText; + bool isMoving; private void Awake() { - // PlayroomKit.OnPlayerJoin(AddPlayer); - PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2, @@ -85,30 +85,23 @@ private void Update() var myPlayer = PlayroomKit.MyPlayer(); var index = players.IndexOf(myPlayer); - Debug.Log(index); + playerGameObjects[index].GetComponent().Move(); + players[index].SetState("posX", playerGameObjects[index].GetComponent().position.x); + players[index].SetState("posY", playerGameObjects[index].GetComponent().position.y); + - if (index != -1) - { - playerGameObjects[index].GetComponent().Move(); - players[index].SetState("posX", playerGameObjects[index].GetComponent().position.x); - players[index].SetState("posY", playerGameObjects[index].GetComponent().position.y); - } if (Input.GetKeyDown(KeyCode.Space)) { - myPlayer.Kick(() => - { - Destroy(playerGameObjects[index]); - }); Vector3 playerPosition = playerGameObjects[index].transform.position; playerGameObjects[index].GetComponent().ShootBullet(playerPosition, 50f); score += 50; - // PlayroomKit.RpcCall("ShootBullet", score, () => - // { - // Debug.Log("shooting bullet!"); - // }); + PlayroomKit.RpcCall("ShootBullet", score, () => + { + Debug.Log("shooting bullet!"); + }); } if (Input.GetKeyDown(KeyCode.R) && PlayroomKit.IsHost()) @@ -116,7 +109,7 @@ private void Update() PlayroomKit.ResetStates(null, () => { var defscore = PlayroomKit.GetState("score"); - // scoreText.text = "Score: " + defscore.ToString(); + scoreText.text = "Score: " + defscore.ToString(); }); } @@ -140,14 +133,6 @@ private void Update() } - void rpcRegisterCallback(string data, string sender) - { - Debug.Log("sender: " + sender); - var player = PlayroomKit.GetPlayer(sender); - Debug.Log("Name of sender: " + player.GetProfile().name); - } - - public void AddPlayer(PlayroomKit.Player player) { GameObject playerObj = (GameObject)Instantiate(Resources.Load("Player"), @@ -160,7 +145,7 @@ public void AddPlayer(PlayroomKit.Player player) players.Add(player); playerGameObjects.Add(playerObj); - Text scoreText = (players.Count == 1) ? scoreText1 : scoreText2; + scoreText = (players.Count == 1) ? scoreText1 : scoreText2; playerObj.GetComponent().scoreText = scoreText; @@ -169,8 +154,6 @@ public void AddPlayer(PlayroomKit.Player player) player.OnQuit(RemovePlayer); } - - [MonoPInvokeCallback(typeof(Action))] private static void RemovePlayer(string playerID) { From 6506e627a7306e0c4eb2a8f34f5a261f67b3e3c3 Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:00:32 +0500 Subject: [PATCH 2/3] chore: demo changes --- Assets/Scripts/GameManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index eecaac2..419b050 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -32,9 +32,8 @@ private void Awake() PlayroomKit.InsertCoin(new PlayroomKit.InitOptions() { maxPlayersPerRoom = 2, - matchmaking = true, defaultPlayerStates = new() { - {"score", -500}, + {"score", 0}, }, }, () => From db3034565b091ca566a8e3647c552c8232a7b86c Mon Sep 17 00:00:00 2001 From: Talha Momin <77355191+momintlh@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:59:19 +0500 Subject: [PATCH 3/3] chore: removed a comment --- Assets/PlayroomKit/PlayroomKit.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index 23deebe..c6c64a6 100644 --- a/Assets/PlayroomKit/PlayroomKit.cs +++ b/Assets/PlayroomKit/PlayroomKit.cs @@ -1096,7 +1096,6 @@ private static void InvokeOnResponseCallback() } } - // Remove the names after the loop foreach (var name in namesToRemove) { RpcEventNames.Remove(name);