Skip to content

Commit

Permalink
Merge branch 'pr/121' into rpc-override
Browse files Browse the repository at this point in the history
  • Loading branch information
momintlh committed Nov 22, 2024
2 parents ddccef0 + 522b61b commit ca0860e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vector3>("pos");

Debug.Log(pos);
Expand Down Expand Up @@ -176,7 +177,6 @@ public void AddPlayer(PlayroomKit.Player player)
/// <summary>
/// Remove player from the game, called when the player leaves / closes the game.
/// </summary>
[MonoPInvokeCallback(typeof(Action<string>))]
private static void RemovePlayer(string playerID)
{
if (PlayerDict.TryGetValue(playerID, out GameObject player))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"); });
}

Expand All @@ -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<Vector3>("move");
var rotate = players[i].GetState<Quaternion>("angle");
Expand Down Expand Up @@ -104,12 +104,15 @@ private void AddPlayer(PlayroomKit.Player player)

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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ public void ShootLaser()
score = playerGameObjects[index].GetComponent<Laser>().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()
Expand Down
4 changes: 4 additions & 0 deletions Assets/PlayroomKit/Examples/package-showcase/showcase.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
43 changes: 25 additions & 18 deletions Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -301,7 +310,5 @@ private void UnsubscribeOnQuit()
{
_playroomService.UnsubscribeOnQuit();
}

// DI END
}
}
2 changes: 1 addition & 1 deletion Assets/PlayroomKit/modules/Player/LocalPlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Profile GetProfile()

public Action OnQuit(Action<string> callback)
{
Debug.Log($"OnQuit is not implemented for local");
Debug.Log($"OnQuit is not supported in Local Mock Mode.");
return null;
}

Expand Down
17 changes: 17 additions & 0 deletions Assets/PlayroomKit/modules/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ public void WaitForState(string StateKey, Action<string> 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


Expand Down
12 changes: 10 additions & 2 deletions Assets/PlayroomKit/modules/Player/PlayerService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -139,6 +140,11 @@ void Unsubscribe()
return Unsubscribe;
}

internal void InvokePlayerOnQuitCallback(string id)
{
OnQuitWrapperCallback(id);
}


public void Kick(Action onKickCallBack = null)
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -186,6 +192,8 @@ private bool GetPlayerStateBoolById(string key)
stateValue == 0 ? false :
throw new InvalidOperationException($"GetStateBool: {key} is not a bool");
}


}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/PlayroomKit/modules/PlayroomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion Assets/PlayroomKit/modules/PlayroomkitDevManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void OnValidate()
private void UpdateMockMode()
{
PlayroomKit.CurrentMockMode = mockMode;

}

/// <summary>
Expand Down

0 comments on commit ca0860e

Please sign in to comment.