# Unity

### PushExpress -- SDK Unity

You will need to integrate your Push.Express account with Firebase.

1. Follow [Firebase Cloud Messaging integration guide](#setup-firebase)
2. [Create application in Push.Express](#setup-pushexpress)
3. [Add sdk in your application](#add-sdk-in-your-application)

### Setup Firebase

1. Go to [Firebase Console](https://console.firebase.google.com) and create a new project (or use existing one)

   You can use one project for all your apps.
2. Open Project Settings -> General

   <div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-a8252e7021a7e46720b40975dcec06834a016718%2Ffcm-project-settings.png?alt=media" alt="" width="800"></div>
3. Create new Unity app or just download `google-services.json` from existing app

<div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-5acc3664b8fdd0d781bb4e5f1441913c34b70c05%2Ffcm-apps-settings.png?alt=media" alt="" width="800"></div>

If you need to create new app, just:

* Register it
* Download `google-services.json`
* Press next-next-next =)
*

<div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-67fb2209df86c839112438844161af0ea3a4ca2d%2Ffcm-new-android-app.png?alt=media" alt="" width="800"></div>

4. Put `google-services.json` to your Assets dir (like `Assets/google-services.json`)

\
\
\
\ <br>

### Setup Push.Express

#### Get Firebase Private key

1. Go to [Firebase Console](https://console.firebase.google.com) and create a new project (or use existing one)

   You can use one project for all your apps.
2. Open Project Settings

   <div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-a8252e7021a7e46720b40975dcec06834a016718%2Ffcm-project-settings.png?alt=media" alt="" width="800"></div>
3. Go to Service accounts, press `Generate new private key` and save it to file `private-key.json` (**you can use same key for all apps**)

   <div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-2a00f0365ac888f714f77eef7b0eae1cc1257077%2Ffcm-private-key-page.png?alt=media" alt="" width="800"></div>

#### Integrate your Push.Express App with Firebase

1. Go to your [Push.Express](https://push.express) account
2. Open existing *App* settings or create a new App
3. Switch type application Firebase

   <div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-4d4659530a7db5c6d52f24524f829d751c591de6%2Fpx-sdk-switch.png?alt=media" alt="" width="800"></div>
4. Paste `private-key.json` file to *Firebase Admin SDK private key* textbox

   <div align="center"><img src="https://4196027459-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEXhSGyb0mYOQ2RZvkDaH%2Fuploads%2Fgit-blob-2f39e9dc21f10066a0e59387d28f727cd6345b59%2Fpx-sdk-fcm-key.png?alt=media" alt="" width="800"></div>

\
\
\
\ <br>

### Add sdk in your application

1. Import the main resources TextMeshPro. To do this, go to Window > TextMeshPro > Import TMP Essential Resources > Press All > Press Import.
2. Add package Newton json. To do this, go to Window > Package Manager > In the upper-left corner, click on the + > Install package by name... > Enter in input com.unity.nuget.newtonsoft-json > Press instal.
3. Add SDK Firebase Messaging. To do this, go to the official download page [Firebase Unity SDK](https://firebase.google.com/download/unity) > Download the latest SDK version (as .zip archive) > Unzip the downloaded archive to a convenient location on your computer > Inside the archive you will find several .unitypackage of files for various Firebase modules.\
   Open Unity > Assets > Import Package > Custom Package > Select a file FirebaseMessaging.unitypackage > In the import window, select all files and press Import
4. Add SDK Push Express. To do this, go to the GitHub page [Push Express Unity SDK](https://github.com/pushex/px-unity-sdk) > Download SDK version (as .zip archive) > Unzip the downloaded archive to a convenient location on your computer.\
   Open Unity > Assets > Import Package > Custom Package > Select a file PushExpressSdkV1.3.unitypackage > In the import window, select all files and press Import
5. Add Push Express Prefab на сцену. Open Unity > Open the Project window > Go to Assets > PushExpress > Drag the Prefab from the Project window to the Hierarchy or Scene window > Prefab will appear on the stage and you can adjust its settings.
6. Configure the Push Express Prefab settings. To do this, double-click on it in the Project window > Prefab Mode opens > In the Inspector window, set the parameters of your application. Paste the PUSH EXPRESS\_APP\_ID value of your application into the App Id Prefab field (the value of PUSH EXPRESS\_APP\_ID can be found in the [Applications](https://app.push.express) section of the personal account). Set the Platform and Platform Name parameters according to the type of your application.
7. Add permissions to AndroidManifest if your app is for Android. To do this, go to Assets > Plugins > Android > AndroidManifest.xml > add the code inside the application section

```kotlin
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
   <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
```

Add android:theme="@style/Theme.AppCompat.Light.NoActionBar" in the activity tag

```kotlin
   <activity android:name="com.google.firebase.MessagingUnityPlayerActivity" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="@style/Theme.AppCompat.Light.NoActionBar">
```
