diff --git a/Assets/PlayroomKit/PlayroomKit.cs b/Assets/PlayroomKit/PlayroomKit.cs index b9dc00a..c6c64a6 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,12 @@ private static void InvokeOnResponseCallback() Debug.LogError($"C#: Error in Invoking callback for RPC event name: '{name}': {ex.Message}"); } } + + 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..419b050 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -23,18 +23,17 @@ 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, - matchmaking = true, defaultPlayerStates = new() { - {"score", -500}, + {"score", 0}, }, }, () => @@ -85,30 +84,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 +108,7 @@ private void Update() PlayroomKit.ResetStates(null, () => { var defscore = PlayroomKit.GetState("score"); - // scoreText.text = "Score: " + defscore.ToString(); + scoreText.text = "Score: " + defscore.ToString(); }); } @@ -140,14 +132,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 +144,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 +153,6 @@ public void AddPlayer(PlayroomKit.Player player) player.OnQuit(RemovePlayer); } - - [MonoPInvokeCallback(typeof(Action))] private static void RemovePlayer(string playerID) {