|
5 | 5 | <img src="https://s1.ax1x.com/2020/08/21/dYIAQU.png" width=20%/> |
6 | 6 | </div> |
7 | 7 |
|
8 | | -[](https://openupm.com/packages/com.psygame.unitywebsocket/) |
9 | | - |
10 | 8 | ## **Online Demo** |
11 | 9 |
|
12 | 10 | - **[https://psygames.github.io/UnityWebSocket/](https://psygames.github.io/UnityWebSocket/)** |
13 | 11 |
|
14 | 12 |
|
15 | 13 | ## **Quick Start** |
16 | 14 |
|
17 | | -### **Requirements** |
18 | | - |
19 | | -- Unity 2018.3 or later |
20 | | -- No other SDK are required |
21 | | - |
22 | 15 | ### **Installation** |
23 | 16 |
|
24 | | -- **Using OpenUPM** |
25 | | - |
26 | | - This package is available on [OpenUPM](https://openupm.com/packages/com.psygame.unitywebsocket/). You can install it via [openupm package installer](https://package-installer.glitch.me/v1/installer/OpenUPM/com.psygame.unitywebsocket?registry=https%3A%2F%2Fpackage.openupm.com). |
27 | | - |
28 | | -- **Using Git** |
29 | | - |
30 | | - Find the manifest.json file in the Packages folder of your project and edit it to look like this: |
31 | | - ```js |
32 | | - { |
33 | | - "dependencies": { |
34 | | - "com.psygame.unitywebsocket": "https://github.com/psygames/UnityWebSocket.git", |
35 | | - ... |
36 | | - }, |
37 | | - } |
38 | | - ``` |
39 | | - |
40 | | - To update the package, change suffix `#{version}` to the target version. |
41 | | - * e.g. `"com.psygame.unitywebsocket": "https://github.com/psygames/UnityWebSocket.git#2.3.0",` |
42 | | - |
43 | | -- **Using Unity Package** |
44 | | - |
45 | | - Download an `UnityWebSocket.unitypackage` file from [Releases](https://github.com/psygames/UnityWebSocket/releases) page. |
| 17 | +- Download an `UnityWebSocket.unitypackage` file from [Releases](https://github.com/psygames/UnityWebSocket/releases) page. |
46 | 18 | Import it into your Unity project. |
47 | 19 |
|
48 | 20 |
|
|
67 | 39 | // connect |
68 | 40 | socket.ConnectAsync(); |
69 | 41 |
|
70 | | - // send data (two ways) |
71 | | - socket.SendAsync(str); // send string data |
72 | | - socket.SendAsync(bytes); // send byte[] data |
| 42 | + // send string data |
| 43 | + socket.SendAsync(str); |
| 44 | + // or send byte[] data (suggested) |
| 45 | + socket.SendAsync(bytes); |
73 | 46 |
|
74 | 47 | // close connection |
75 | 48 | socket.CloseAsync(); |
76 | 49 | ``` |
77 | 50 |
|
78 | | -- more detail usage, see the [UnityWebSocketDemo.cs](Samples~/Demo/UnityWebSocketDemo.cs) code in project。 |
79 | | - |
| 51 | +- more detail usage, see the [UnityWebSocketDemo.cs](Assets/UnityWebSocket/Demo/UnityWebSocketDemo.cs) code in project. |
| 52 | + |
| 53 | +- Unity Define Symbols: |
| 54 | + - `UNITY_WEB_SOCKET_LOG` open internal log info. |
| 55 | + - `UNITY_WEB_SOCKET_SHARP` use third-party plugin [websocket-sharp](https://github.com/sta/websocket-sharp). |
| 56 | + - `UNITY_WEB_SOCKET_NINJA` use third-party plugin [Ninja.WebSockets](https://github.com/ninjasource/Ninja.WebSockets) |
80 | 57 |
|
81 | 58 | ### **Attention(Warning)** |
82 | 59 |
|
|
0 commit comments