Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BaseProject/Assets/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<config>
<add key="repositoryPath" value="./Packages" />
<add key="repositoryPath" value="./PusherWebsocketUnity/Packages" />
<add key="DefaultPushSource" value="http://www.nuget.org/api/v2/" />
</config>
</configuration>
</configuration>
50 changes: 30 additions & 20 deletions BaseProject/Assets/NuGet/Editor/DotNetZip.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 30 additions & 20 deletions BaseProject/Assets/NuGet/Editor/NuGetForUnity.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BaseProject/Assets/PusherWebsocketUnity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "PusherWebsocketUnity"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions BaseProject/Assets/PusherWebsocketUnity/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "com.pusher.pusherwebsocketunity",
"displayName": "PusherWebsocketUnity",
"version": "1.0.2+190808",
"unity": "2018.1",
"description": "Pusher Channels Client for realtime websockets on Unity"
}
7 changes: 7 additions & 0 deletions BaseProject/Assets/PusherWebsocketUnity/package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build-release:
git subtree split --prefix=BaseProject/Assets/PusherWebsocketUnity --branch upm
git tag $(VERSION) upm

push-release:
git push origin upm --tags
94 changes: 67 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
## Pusher Channels Unity Client Library

This library packages [the official WebSocket .NET SDK for Pusher Channels](https://github.com/pusher/pusher-websocket-dotnet) as a `.unitypackage` to make it easier to use in [Unity](https://unity.com/) projects. For API documentation, see [the pusher-websocket-dotnet README](https://github.com/pusher/pusher-websocket-dotnet).

### Usage
1) Download the latest `.unitypackage` from this repo's [Releases](/../../releases)
2) Open a new/existing Unity project and make sure it is being opened by a [supported version of Unity](#unity-versions-support)
3) [if your Unity version is **2018.x.x**] Make sure that under `Edit -> Project Settings -> Player` the `Configuration -> Scripting Runtime Version` is set to **.NET 4.x Equivalent**
4) Click on `Assets -> Import Package -> Custom Package...`, find and select the `PusherWebsocketUnity-x.x.x-xxxxxxx.unitypackage` and click *Import* on the `Import Unity Package` window.
5) Create a Pusher Channels app at https://pusher.com/channels.
6) Open the `PusherManager.cs` file in the Assets folder and add your keys as values for `private const string APP_KEY` and `private const string APP_CLUSTER` obtained at the previous step.
7) Create a new GameObject, by going on `GameObject -> Create Empty`. Drag the `PusherManager.cs` script onto the GameObject Inspector to set it as a script for the object.
8) Save and click Play to start the game in Unity.
9) Verify that in the Console tab the following is logged: `Connection state changed`, `Connected`, `Subscribed`.
10) You can now customise the channel name (by default is `"my-channel"`) and events to bind to (by default is `"my-event"`) in the `PusherManager.cs` script.

### Repository Structure
# Pusher Channels Unity Client Library

This library packages [the official WebSocket .NET SDK for Pusher Channels](https://github.com/pusher/pusher-websocket-dotnet) as a `.unitypackage` and an `UPM package` to make it easier to use in [Unity](https://unity.com/) projects. For API documentation, see [the pusher-websocket-dotnet README](https://github.com/pusher/pusher-websocket-dotnet).

## Repository Structure
- `BaseProject` a Unity Base project which demonstrates how to integrate Pusher Channels with Unity
- `Builds` a build environment for the `PusherWebsocketUnity` _unitypackage_ and its Asset Store release
- `Builds` a build environment for the `PusherWebsocketUnity` _unitypackage_ and the _Unity Package Manager_ (UPM) release
- `Examples` example projects that combines Unity and Pusher Channels

### Unity Versions Support
## Unity Versions Support
- Unity 2018.1
- Unity 2018.1.0
- Unity 2018.1.2
Expand All @@ -35,17 +23,69 @@ This library packages [the official WebSocket .NET SDK for Pusher Channels](http

- All Unity 2019.2.x

### Unity Platforms Support

#### Supported Platforms:
## Getting Started
1. [Create a Pusher Channels app](#1-create-a-pusher-channels-app)
2. [Install](#2-install) the **Pusher Channels Unity Client Library** via `unitypackage` or via Unity Package Manager (UPM)
3. [Add PusherManager and run the game](#3-add-pushermanager-and-run-the-game)

### 1 Create a Pusher Channels app
1.1 - Create a Pusher Channels app at https://pusher.com/channels

### 2 Install
#### 2.1 Install it via unitypackage
2.1.1 - Download the latest `PusherWebsocketUnity-1.0.2+190808.unitypackage` from [releases](/../../releases)<br>
2.1.2 - Open a new/existing Unity project and make sure it is being opened by a [supported version of Unity](#unity-versions-support)<br>
2.1.3 - [if your Unity version is **2018.x.x**] Make sure that under `Edit -> Project Settings -> Player` the `Configuration -> Scripting Runtime Version` is set to **.NET 4.x Equivalent**.<br>
2.1.4 - Click on `Assets -> Import Package -> Custom Package...`, find and select the `PusherWebsocketUnity-1.0.2+190808.unitypackage` and click *Import* on the `Import Unity Package` window.<br>

#### 2.2 Install it via Unity Package Manager (UPM)
**WARNING** this method works only if your version of Unity is **2018.3.x or greater**, if you don't satisfy that, use the [unitypackage](#2-install) method.<br>
2.2.1 - [if your Unity version is **2018.x.x**] Make sure that under `Edit -> Project Settings -> Player` the `Configuration -> Scripting Runtime Version` is set to **.NET 4.x Equivalent**.<br>
2.2.2 - Open `Packages/manifest.json` with your favourite editor and add the following in your `dependencies` (make sure to respect JSON commas):
```
{
"dependencies": {
...
"com.pusher.pusherwebsocketunity": "https://github.com/pusher/pusher-websocket-unity.git#1.0.2+190808"
}
}
```
2.2.3 - Now Unity should auto resolve dependencies and fetch the newly defined package.

### 3 Add PusherManager and run the game
3.1 - Copy the sample [`PusherManager.cs`](BaseProject/Assets/PusherManager.cs) into your project's Assets folder and add your keys as values for `private const string APP_KEY` and `private const string APP_CLUSTER` obtained when you created the Pusher Channels app in the dashboard.<br>
3.2 - Create a new GameObject, by going on `GameObject -> Create Empty`. Drag the `PusherManager.cs` script onto the GameObject Inspector to set it as a script for the object.<br>
3.3 - Save and click *Play* to start the game in Unity.<br>
3.4 - Verify that `Connection state changed`, `Connected`, `Subscribed` is logged in the *Console* tab.<br>
3.5 - You can now customize the channel name (by default is `"my-channel"`) and events to bind to (by default is `"my-event"`) in the `PusherManager.cs` script.

## Update this package
### Update the version of .unitypackage
To update the version of the `.unitypackage` you can delete the `Assets/PusherWebsocketUnity` directory and repeat the [install steps](#2-install).

### Update the version of Unity Package Manager (UPM) package
To update the version of `com.pusher.pusherwebsocketunity` you just need to check the available versions in [releases](/../../releases) and change the package version in the `Packages/manifest.json`, like so:

From:
```json
"com.pusher.pusherwebsocketunity": "https://github.com/pusher/pusher-websocket-unity.git#0.0.0+000000"
```
To:
```json
"com.pusher.pusherwebsocketunity": "https://github.com/pusher/pusher-websocket-unity.git#1.0.2+190808"
```

## Unity Platforms Support

### Supported Platforms:
The supported platforms should be the ones that can be targeted by Unity.
Thus far we tested this, and can confirm that works, on:
Thus far we tested this, and can confirm the library works, on:
- Windows
- MacOS
- Android
- iOS

#### Unsupported Platforms:
### Unsupported Platforms:
- WebGL: due to incompatibility with Websockets (more [here](https://docs.unity3d.com/Manual/webgl-networking.html) under the _"No direct socket access"_ section)

<!--
Expand All @@ -56,11 +96,11 @@ TODO
TODO
-->

### Known Issues
## Known Issues
This library is INCOMPATIBLE with 2018.1.4 <= Unity <= 2018.2.4 due to
a [bug](https://issuetracker.unity3d.com/issues/opened-event-of-a-websocket4net-dot-websocket-does-not-get-called-when-opening-a-web-socket)
in the Unity engine that prevents WebSocket4Net (one of the dependencies) to work correctly
in the Unity engine that prevents WebSocket4Net (one of the dependencies) to work correctly.

### Credits
## Credits
- Unity Technologies https://unity3d.com/company - for the Unity3d environment
- Patrick McCarthy (GlitchEnzo) https://github.com/GlitchEnzo - for [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)