Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psygames/UnityWebSocket
:whale: The Best Unity WebSocket Plugin for All Platforms.
https://github.com/psygames/UnityWebSocket
jslib socket unity webgl websocket
Last synced: 3 months ago
JSON representation
:whale: The Best Unity WebSocket Plugin for All Platforms.
- Host: GitHub
- URL: https://github.com/psygames/UnityWebSocket
- Owner: psygames
- License: mit
- Created: 2016-06-25T09:42:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-10T03:24:38.000Z (10 months ago)
- Last Synced: 2024-05-21T14:03:49.368Z (6 months ago)
- Topics: jslib, socket, unity, webgl, websocket
- Language: C#
- Homepage:
- Size: 17.2 MB
- Stars: 801
- Watchers: 27
- Forks: 171
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGE_LOG.md
- License: LICENSE
Awesome Lists containing this project
README
[(English)](README_EN.md)
## **在线示例**
- **[https://psygames.github.io/UnityWebSocket/](https://psygames.github.io/UnityWebSocket/)**
## **快速开始**
### **安装方法**
- **通过 Unity Package 安装**
在 [Releases](https://github.com/psygames/UnityWebSocket/releases) 页面中,下载最新版本的 `UnityWebSocket.unitypackage` 安装包,然后导入到您的项目中。
- **通过 Package Manager 安装**
在 Unity 菜单栏中打开 `Window/Package Manager`,点击左上角 `+` 号,选择 `Add package from git URL...` ,输入 `https://github.com/psygames/UnityWebSocket.git#upm` 并确认。
### **使用方法**
- 代码示例
```csharp
// 命名空间
using UnityWebSocket;// 创建实例
string address = "ws://echo.websocket.org";
WebSocket socket = new WebSocket(address);// 注册回调
socket.OnOpen += OnOpen;
socket.OnClose += OnClose;
socket.OnMessage += OnMessage;
socket.OnError += OnError;// 连接
socket.ConnectAsync();// 发送 string 类型数据
socket.SendAsync(str);// 或者 发送 byte[] 类型数据(建议使用)
socket.SendAsync(bytes);// 关闭连接
socket.CloseAsync();
```- 更多使用方法可参考项目中的 [UnityWebSocketDemo.cs](Assets/UnityWebSocket/Demo/UnityWebSocketDemo.cs) 示例代码。
- 功能菜单:
- Tools -> UnityWebSocket,版本更新检测,问题反馈渠道等。- Unity 编译宏(可选项):
- `UNITY_WEB_SOCKET_LOG` 打开底层日志输出。
- `UNITY_WEB_SOCKET_ENABLE_ASYNC` 针对非WebGL平台使用异步线程处理消息(需自行处理跨线程访问Unity组件问题)。### **QQ 交流群**
- 1126457634 >>> [入群通道](https://qm.qq.com/cgi-bin/qm/qr?k=KcexYJ9aYwogFXbj2aN0XHH5b2G7ICmd) <<<