@@ -16,15 +16,20 @@ Used in [Colyseus Unity SDK](https://github.com/colyseus/colyseus-unity-sdk).
1616
1717* Requires Unity 2019.1+ with .NET 4.x+ Runtime*
1818
19+ > ** Note:** Do not copy the raw source files from this repository directly into
20+ > your Unity project. The core ` WebSocket.cs ` requires a build-time
21+ > transformation to add WebGL conditional compilation guards. Use one of the
22+ > install methods below instead.
23+
1924** Via UPM (Unity Package Manager):**
20251 . Open Unity
21262 . Open Package Manager Window
22273 . Click Add Package From Git URL
23- 4 . Enter URL: ` https://github.com/endel/NativeWebSocket.git#upm `
28+ 4 . Enter URL: ` https://github.com/endel/NativeWebSocket.git#upm-2.0 `
2429
25- ** Manually :**
26- 1 . [ Download this project ] ( https://github.com/endel/NativeWebSocket/archive/master.zip )
27- 2 . Copy the sources from ` NativeWebSocket/ Assets/WebSocket ` into your ` Assets ` directory.
30+ ** Via .unitypackage :**
31+ 1 . Download ` NativeWebSocket.unitypackage ` from the [ Releases ] ( https://github.com/endel/NativeWebSocket/releases ) page
32+ 2 . In Unity, go to Assets > Import Package > Custom Package and select the downloaded file
2833
2934## MonoGame / .NET
3035
@@ -60,6 +65,8 @@ public class Connection : MonoBehaviour
6065
6166 async void Start ()
6267 {
68+ Application .runInBackground = true ; // Recommended for WebGL
69+
6370 websocket = new WebSocket (" ws://localhost:3000" );
6471
6572 websocket .OnOpen += () => Debug .Log (" Connection open!" );
@@ -93,6 +100,11 @@ public class Connection : MonoBehaviour
93100}
94101```
95102
103+ ** WebGL note:** Unity pauses the game loop when the browser tab loses focus, which
104+ stops all WebSocket send/receive callbacks. To keep the connection active in the
105+ background, set ` Application.runInBackground = true ` in your script or enable
106+ ** Run In Background** in Player Settings > Resolution and Presentation.
107+
96108## MonoGame
97109
98110Add the ` WebSocketGameComponent ` to your game. This installs a
0 commit comments