Skip to content

Commit

Permalink
Merge branch 'main' into ErrorPassing
Browse files Browse the repository at this point in the history
  • Loading branch information
momintlh authored Apr 18, 2024
2 parents ae869f7 + c288eb8 commit 97a41e5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 28 deletions.
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Bug Report
description: File a bug report.
title: "[Bug]: "
labels: ["bug", "triage"]
assignees:
- SaadBazaz
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: textarea
id: version
attributes:
label: Version
description: What version of our software are you running?
placeholder: x.x.x
validations:
required: true
- type: textarea
id: environment
attributes:
label: What is your environment?
description: Describe your project's environment. This will help us reproduce the issue.
placeholder: Unity version, Browser, Operating System, etc
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
validations:
required: true
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Suggest an improvement!
description: Do you want to see something better in the Unity SDK?
title: "[Feature-Request]: "
labels: ["enhancement", "triage"]
assignees:
- asadm
body:
- type: textarea
id: enhancement-description
attributes:
label: What do you want to see?
description: Also tell us, what alternatives have you tried?
placeholder: Tell us what you want!
value: "Better developer experience!"
validations:
required: true
29 changes: 26 additions & 3 deletions Assets/PlayroomKit/PlayroomKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PlayroomKit
public static readonly Dictionary<string, Player> Players = new();



[Serializable]
public class InitOptions
{
Expand Down Expand Up @@ -265,7 +266,8 @@ public static void OnPlayerJoin(Action<Player> onPlayerJoinCallback)
{
Debug.Log("On Player Join");
var testPlayer = GetPlayer(PlayerId);
onPlayerJoinCallback?.Invoke(testPlayer);
OnPlayerJoinCallbacks.Add(onPlayerJoinCallback);
__OnPlayerJoinCallbackHandler(PlayerId);
}
}
}
Expand Down Expand Up @@ -1085,6 +1087,8 @@ public static void RpcCall(string name, object data, Action callbackOnResponse)
[MonoPInvokeCallback(typeof(Action))]
private static void InvokeOnResponseCallback()
{
var namesToRemove = new List<string>();

foreach (var name in RpcEventNames)
{
try
Expand All @@ -1096,15 +1100,20 @@ private static void InvokeOnResponseCallback()
callback?.Invoke();
}

RpcEventNames.Remove(name);
OnResponseCallbacks.Remove(name);
namesToRemove.Add(name);
}
}
catch (Exception ex)
{
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);
}
}


Expand Down Expand Up @@ -1606,6 +1615,20 @@ public void Kick(Action OnKickCallBack = null)
OnKickCallBack = onKickCallBack;
KickInternal(id, InvokeKickCallBack);
}
else
{
if (!isPlayRoomInitialized)
{
Debug.LogError("[Mock Mode] Playroom not initialized yet! Please call InsertCoin.");
return;
}
else
{
var player = GetPlayer(PlayerId);
Players.Remove(player.id);
onKickCallBack?.Invoke();
}
}
}

[DllImport("__Internal")]
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scenes/Game.unity
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0.000061035156, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 522.891, y: 275.649}
m_Pivot: {x: 1, y: 1}
--- !u!114 &197975553
Expand Down Expand Up @@ -580,7 +580,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: -0.000061035156, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 522.891, y: 275.649}
m_Pivot: {x: 0, y: 1}
--- !u!114 &396053685
Expand Down Expand Up @@ -915,6 +915,7 @@ Canvas:
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
Expand Down
25 changes: 8 additions & 17 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ 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,
discord = true,
defaultPlayerStates = new() {
{"score", -500},
{"score", 0},
},

}, () =>
Expand Down Expand Up @@ -90,8 +89,10 @@ private void Update()
players[index].SetState("posX", playerGameObjects[index].GetComponent<Transform>().position.x);
players[index].SetState("posY", playerGameObjects[index].GetComponent<Transform>().position.y);


if (Input.GetKeyDown(KeyCode.Space))
{

Vector3 playerPosition = playerGameObjects[index].transform.position;
playerGameObjects[index].GetComponent<PlayerController>().ShootBullet(playerPosition, 50f);

Expand All @@ -108,7 +109,7 @@ private void Update()
PlayroomKit.ResetStates(null, () =>
{
var defscore = PlayroomKit.GetState<int>("score");
// scoreText.text = "Score: " + defscore.ToString();
scoreText.text = "Score: " + defscore.ToString();
});

}
Expand All @@ -132,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"),
Expand All @@ -152,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<PlayerController>().scoreText = scoreText;


Expand All @@ -161,8 +154,6 @@ public void AddPlayer(PlayroomKit.Player player)
player.OnQuit(RemovePlayer);
}



[MonoPInvokeCallback(typeof(Action<string>))]
private static void RemovePlayer(string playerID)
{
Expand Down
4 changes: 2 additions & 2 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,11 @@ PlayerSettings:
webGLTemplate: APPLICATION:Default
webGLAnalyzeBuildSize: 0
webGLUseEmbeddedResources: 0
webGLCompressionFormat: 2
webGLCompressionFormat: 0
webGLWasmArithmeticExceptions: 0
webGLLinkerTarget: 1
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
webGLDecompressionFallback: 1
webGLPowerPreference: 2
scriptingDefineSymbols: {}
additionalCompilerArguments: {}
Expand Down
43 changes: 39 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
### PlayroomKit SDK for Unity
<div align="center">
<img src="https://docs.joinplayroom.com/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Funity-blog.16612f8c.png&w=3840&q=75" width="100%" style="border-radius: 12px">
<h1 style="margin-top:8px">PlayroomKit SDK for Unity</h1>
<p>The easiest multiplayer infrastructure for the web</p>
<a href="https://docs.joinplayroom.com/usage/unity"><img src="https://img.shields.io/static/v1?label=Docs&message=API Ref&color=000&style=for-the-badge" /></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge" /></a>
<a href="https://discord.gg/HGkSRAD8"><img src="https://img.shields.io/static/v1?label=Discord&message=Join&color=7289da&style=for-the-badge" /></a>
</div>

This SDK is a wrapper over PlayroomKit JS. Currently, it only supports WebGL exported games.
See [PlayroomKit Unity docs](https://docs.joinplayroom.com/usage/unity) for more information.
<br/>
<br/>

This SDK is a wrapper over PlayroomKit JS. Currently, it only supports WebGL exported games. The API is meant to closely mirror the PlayroomKit JavaScript SDK.

<!-- Start SDK Installation -->
## Installation and Usage

See [PlayroomKit Unity docs](https://docs.joinplayroom.com/usage/unity) on how to use this SDK in your Unity project.


This beta version of the SDK might undergo changes that could break compatibility with previous versions, even without a major version update. To ensure stability, it's advisable to fix the usage to a particular package version. By doing so, you'll consistently install the same version and avoid unexpected changes, unless you deliberately seek the latest updates.

<!-- End SDK Installation -->

<!-- Start SDK Installation -->
## Contribution

### Reporting issues

You can search for help, or ask the community, in our [Discord channel](https://discord.gg/HGkSRAD8).

Found a bug, or want us to implement something? [Create an Issue](https://github.com/asadm/playroom-unity/issues/new) on GitHub.

### Creating a new release

Expand All @@ -12,4 +40,11 @@ git tag v0.Y.Z
git push origin --tags
```

This will create a draft release [on GitHub](https://github.com/asadm/playroom-unity/releases). Edit the release to add release notes and publish it.
This will create a draft release [on GitHub](https://github.com/asadm/playroom-unity/releases). Edit the release to add release notes and publish it.

### Learn more

Read more about the PlayroomKit Unity integration and the design behind it.

- [Official announcement blog](https://docs.joinplayroom.com/blog/unityweb)
- [Deep dive into PlayroomKit Unity](https://www.linkedin.com/pulse/building-unity-plugin-javascript-grayhatpk-gynfc/?trackingId=kbv0oZVNT6aLh2TjQ%2FhuVw%3D%3D)

0 comments on commit 97a41e5

Please sign in to comment.