Unity SDK Integration
Step 1: Import Unity Jar Resolver
Download
external-dependency-manager-1.2.164.unitypackage
from the NetmeraPackages folder.Import the package into your Unity project.
Step 2: Import Firebase Messaging
Download
FirebaseMessaging.unitypackage
from the NetmeraPackages folder.Import the package into your project.
Do not uncheck any files during import.
Step 3: Import Netmera
Download
netmera-unity-1.1.4.noads.unitypackage
from the NetmeraPackages folder.Import it into your Unity project.
Step 4: Adding Netmera-Info.plist file
Add the
Netmera-Info.plist
file to your Assets folder.Do not move it from this path.
If needed, rename the
Netmera-Info.plist.example
file by removing the.example
extension. The sample file can be found here.Ensure the
Netmera-Info.plist
file includes the following structure:
Step 5: Android and iOS Specific Guides
The Step 5 is divided into two categories: Android or iOS.
1. Add a google-services.json
File
google-services.json
FileTo configure Firebase messaging for your Unity application, download the google-services.json
file from the Firebase Console. Follow these steps:
Download the file from the Firebase Console.
Place the
google-services.json
file directly in your Unity project'sAssets
folder.Note: The file path is important. Do not move it after placing it in the
Assets
folder.
2. Using a Custom mainTemplate.gradle
File
mainTemplate.gradle
FileUnity uses the Unity Jar Resolver to manage dependencies, and it automatically integrates the necessary Firebase components when you import the FirebaseMessaging.unitypackage
. You will need to enable custom gradle templates for the integration.
In the Unity Editor, go to Project Settings -> Publishing Settings.
Enable the following settings:
Enable Custom Main Gradle Template
Enable Custom Main Manifest
Enable Custom Gradle Properties Template
These settings will generate two gradle-related files in the Assets/Plugins/Android
folder: gradleTemplate.properties
and mainTemplate.gradle
.
Open the
gradleTemplate.properties
file and append the following line:
3. Jar Resolver Settings
To configure the Unity Jar Resolver, follow these steps:
In the Unity Editor, go to Assets -> External Dependency Manager -> Android Resolver -> Settings.
Apply the following recommended settings (though some are optional):
Uncheck Enable Auto Resolution.
Uncheck Enable Resolution on Build.
Check Install Android Packages.
Check Explode AARs.
Check Patch AndroidManifest.xml.
Check Patch mainTemplate.gradle.
Check Patch gradleTemplate.properties.
Check Use Jetifier.
These settings ensure that the Android dependencies are resolved and handled properly.
4. Jar Resolver Resolve Process
After configuring the resolver, follow these steps to ensure all dependencies are correctly imported:
In the Unity Editor, go to Assets -> External Dependency Manager -> Android Resolver -> Resolve.
After the process completes, open the
mainTemplate.gradle
file and verify that the necessary libraries have been imported correctly.In the
dependencies {}
section ofmainTemplate.gradle
, you should see the following libraries (version numbers may vary):If any libraries are missing, try using Force Resolve instead of Resolve.
Note: If you encounter any duplicate class errors during the build, check for and remove duplicate dependencies.
5. Enabling Multidex
If your Unity app exceeds the 64K method limit for a single APK, you will need to enable Multidex.
Open the
mainTemplate.gradle
file and navigate to theandroid -> defaultConfig
section.Add the following line to enable Multidex:
Note: If your
minSDK
version is below 21, additional steps are required. You can find more details on enabling Multidex here.
6. Editing the AndroidManifest.xml
File
AndroidManifest.xml
FileThe AndroidManifest.xml
file is a crucial configuration file for setting up Firebase and Netmera SDK integration. Follow these steps:
Open your Unity project’s MAIN AndroidManifest.xml file, which can be found at
Assets/Plugins/Android/AndroidManifest.xml
.Add the following lines inside the
<application>
tag to integrate Netmera and Firebase:Note: If you cannot use the Netmera
Application
class, you will need to manually add this line to theonCreate
method of your ownApplication
class:
By following these steps, you ensure that the integration between Firebase, Netmera, and Unity is correctly configured.
Step 6: Demo Scene
Navigate to Assets > Netmera > Demo > NetmeraDemoScene.
You can integrate this scene into your app to test the integration.
Step 7: Adding Prefab to your first Unity Scene
In your Unity scene, import the prefab located at: Assets > Netmera > Demo > Prefabs > NetmeraManager.
This prefab contains the
NetmeraGameObject
script, which demonstrates SDK methods.Do not destroy this object while switching between Unity scenes. It should persist throughout the app.
In the
Awake()
method of your scene, call:
Netmera Unity Sample Methods
1. Logging Configuration
The loggingEnabled
boolean controls whether logging is enabled in the Netmera SDK. This can be set in the Unity editor to toggle logging functionality.
2. Initialization (Awake Method)
In the Awake
method, the following actions are performed:
Stack trace logging for regular log messages is disabled.
The
NetmeraGameObject
is set to persist across scene loads usingDontDestroyOnLoad
.The
Test_Init
method is called to initialize the Netmera SDK.
3. Initialization Method: Test_Init
Test_Init
The Test_Init
method initializes the Netmera SDK. If the NetmeraCore
instance is available, logging is configured based on the loggingEnabled
flag, and the SDK is initialized.
4. Sample SDK Method Calls
Sending an Event
The following method sends an event to the Netmera SDK, with sample data provided for event category and count.
Updating User Information
This method creates a NetmeraUser
object and updates the user's birthday and city information.
Fetching Inbox Items
The Test_FetchInbox
method fetches inbox items, with a filter for "read or unread" push notifications.
Fetching the Next Page of Inbox Items
This method fetches the next page of inbox items.
Destroying the SDK Instance
The Test_Destroy
method destroys the current Netmera SDK instance.
Enabling Popup Presentation
This method allows for enabling or disabling popup presentations for push notifications.
Getting Push Notification Status Count
This method retrieves the count of push notifications based on their status (read/unread).
Changing the Status of Inbox Items
The Test_ChangeInboxItemStatuses
method allows for changing the status of specific inbox items.
Requesting Location Permissions
The Test_RequestPermissionsForLocation
method requests permissions to access the user’s location.
Changing the Status of All Inbox Items
This method changes the status of all inbox items to "deleted."
5. Callback Methods
The class implements several callback methods for handling events related to push notifications and inbox operations. Each callback is currently a placeholder, but you can add custom logic to process the events as needed.
Push Notifications:
OnPushRegister
: Triggered when the device registers for push notifications.OnPushReceive
: Triggered when a push notification is received.OnPushOpen
: Triggered when a push notification is opened by the user.OnPushDismiss
: Triggered when a push notification is dismissed.OnPushButtonClicked
: Triggered when a button in a push notification is clicked.
Inbox Operations:
OnInboxFetchSuccess
: Triggered when inbox items are successfully fetched.OnInboxFetchFail
: Triggered when there is a failure to fetch inbox items.OnInboxNextPageFetchSuccess
: Triggered when the next page of inbox items is successfully fetched.OnInboxNextPageFetchFail
: Triggered when there is a failure to fetch the next page of inbox items.OnInboxStatusChangeSuccess
: Triggered when the status of inbox items is successfully changed.OnInboxStatusChangeFail
: Triggered when there is a failure to change the status of inbox items.OnInboxStatusCount
: Triggered when the count of inbox items with a specific status is retrieved.
Last updated