1 Star 2 Fork 1

小茗同学 / UnityWebSocket

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

(English)

在线示例

快速开始

安装方法

  • 通过 Unity Package 安装

    Releases 页面中,下载最新版本的 UnityWebSocket.unitypackage 安装包,然后导入到您的项目中。

  • 通过 Package Manager 安装

    在 Unity 菜单栏中打开 Window/Package Manager,点击左上角 + 号,选择 Add package from git URL... ,输入 https://github.com/psygames/UnityWebSocket.git#upm 并确认。

使用方法

  • 代码示例

    // 命名空间
    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 示例代码。

  • 功能菜单:

    • Tools -> UnityWebSocket,版本更新检测,问题反馈渠道等。
  • Unity 编译宏(可选项):

    • UNITY_WEB_SOCKET_LOG 打开底层日志输出。
    • UNITY_WEB_SOCKET_ENABLE_ASYNC 针对非WebGL平台使用异步线程处理消息(需自行处理跨线程访问Unity组件问题)。

QQ 交流群

MIT License Copyright (c) 2020 psy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

常用的unity websocket 支持2018以上版本 展开 收起
C# 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/JohnConstine/UnityWebSocket.git
git@gitee.com:JohnConstine/UnityWebSocket.git
JohnConstine
UnityWebSocket
UnityWebSocket
master

搜索帮助