Skip to content

Commit

Permalink
fix: WaitForState updated
Browse files Browse the repository at this point in the history
  • Loading branch information
momintlh committed Jan 10, 2025
1 parent 4916b0d commit 0406580
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
23 changes: 9 additions & 14 deletions Assets/PlayroomKit/Examples/2d-platformer/scripts/GameManager2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public class GameManager2d : MonoBehaviour
private static readonly List<GameObject> playerGameObjects = new();
private static Dictionary<string, GameObject> PlayerDict = new();

private PlayroomKit _playroomKit = new();
private PlayroomKit _playroomKit;


void Awake()
{
_playroomKit = new();
Initialize();
}

Expand Down Expand Up @@ -69,6 +70,11 @@ private void Initialize()
void Start()
{
_playroomKit.RpcRegister("ShootBullet", HandleScoreUpdate, "You shot a bullet!");

_playroomKit.WaitForState("test", (s) =>
{
Debug.LogWarning($"After waiting for test: {s}");
});
}

/// <summary>
Expand Down Expand Up @@ -106,17 +112,14 @@ private void Update()
{
var myPlayer = _playroomKit.MyPlayer();
var index = players.IndexOf(myPlayer);

if (Input.GetKeyDown(KeyCode.L)) _playroomKit.SetState("test", "yes");

playerGameObjects[index].GetComponent<PlayerController2d>().Move();
playerGameObjects[index].GetComponent<PlayerController2d>().Jump();

players[index].SetState("pos", playerGameObjects[index].transform.position);

players[index].SetState("a", "HELLO WORLD");
players[index].SetState("d", 11);
players[index].SetState("b", 9.81f);
players[index].SetState("c", false);

ShootBullet(index);

for (var i = 0; i < players.Count; i++)
Expand All @@ -126,14 +129,6 @@ private void Update()
// Debug.Log("Getting state of: " + players[i].id);
var pos = players[i].GetState<Vector3>("pos");

string a = players[i].GetState<string>("a");
float b = players[i].GetState<float>("b");
bool c = players[i].GetState<bool>("c");
int d = players[i].GetState<int>("d");

Debug.Log($"Player {i} state: a: {a}, b: {b}, c: {c}, d: {d}");
Debug.Log($"a type: {a.GetType()}, b type: {b.GetType()}, c type: {c.GetType()}, d type: {d.GetType()}");


var color = players[i].GetState<Color>("color");
if (playerGameObjects != null)
Expand Down
2 changes: 1 addition & 1 deletion Assets/PlayroomKit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ mergeInto(LibraryManager.library, {

var key = _ConvertString(stateKey);

{{{ makeDynCall('vi', 'onStateSetCallback') }}}(stringToNewUTF8(stateVal))
{{{ makeDynCall('vii', 'onStateSetCallback') }}}(key, stringToNewUTF8(stateVal))
})
.catch((error) => {
console.error("Error Waiting for state:", error);
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 0
- enabled: 1
path: Assets/PlayroomKit/Examples/2d-platformer/2d-platformer.unity
guid: cf82eec4c654cf44b89cec2a91afebd5
- enabled: 1
- enabled: 0
path: Assets/PlayroomKit/Examples/discord-activity/discord-activity.unity
guid: bb7ef8e4a67f3fb46b78e5d95a6858a7
- enabled: 0
Expand Down

0 comments on commit 0406580

Please sign in to comment.