- Unity 2018.3 or higher.
-
Install via Package Manager (Recommended)
Open Window/Package Manager in the Unity menu bar, click the
+
icon at the top left, selectAdd package from git URL...
, enterhttps://github.com/psygames/UnityWebSocket.git#upm
and confirm. -
Install via Unity Package
Download the latest version of
UnityWebSocket.unitypackage
from the Releases page, then import the package into your project.
-
Easy to use
// the namespace using UnityWebSocket; // create instance string address = "ws://echo.websocket.org"; WebSocket socket = new WebSocket(address); // register callback socket.OnOpen += OnOpen; socket.OnClose += OnClose; socket.OnMessage += OnMessage; socket.OnError += OnError; // connect socket.ConnectAsync(); // send string data socket.SendAsync(str); // or send byte[] data (suggested) socket.SendAsync(bytes); // close connection socket.CloseAsync();
-
For more usage, refer to the UnityWebSocketDemo.cs example code in the project.
-
Menus
- Tools -> UnityWebSocket, version update check, bug report, etc.
-
Unity Define Symbols(Optional):
UNITY_WEB_SOCKET_LOG
Open internal log info.