Zqdn/UnityProject/Assets/Plugins/com.psygames.unitywebsocket
SD-20250415ABSO\Administrator 321e38cb79 冠军框架迁移
2025-04-18 19:18:15 +08:00
..
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00
2025-04-18 19:18:15 +08:00

(中文版)

Online Demo

Quick Start

Installation

  • Download latest UnityWebSocket.unitypackage file from Releases page. Import it into your Unity project.

Usage

  • 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();
    
  • More detail usages, see the UnityWebSocketDemo.cs code in project.

  • Menus

    • Tools -> UnityWebSocket, version update check, bug report, etc.
  • Unity Define Symbols(Optional):

    • UNITY_WEB_SOCKET_LOG Open internal log info.
    • UNITY_WEB_SOCKET_ENABLE_ASYNC Use network thread handle message (not WebGL platform).