Unity (Android)
This guide is for anyone who wishes to integrate the Enefits Unity SDK for android o the Unity project. We highly recommend reviewing the General Usage guide to familiarise yourself with general SDK workflow concepts before continuing. You will need to generate an API key with your Enefits account before continuing with integration.
To obtain an API key, simply register at https://x.enefits.co/, and go to Developer in the account menu in the top right section. From there, generate an API key and save this for SDK initialization.

We only show this once, so if you lose this API Key, you’ll have to re-generate it from the Developer section.
To run a live demo, download EnefitsDemoApp. Open it with Unity and provide your own API key where requested. Also, note that EnefitsDemoApp requires an android device to work. It will not work in the Unity Editor Or the android Emulator.
Make sure you have android Build options support available in Unity.

Also, make sure you have support for android build OR android studio installed. Go to Unity -> File -> Build Settings.
Make sure 'android' option is selected. Select option 'Build', it will ask for a location where unity will generate Android Project.
Select a location, then it will generate Android Project at a specified location.
Open generated android project with android studio.
Open build.gradle file of exportAndroid Project.
add jitpack maven to repositories.
Also, add wallet connect dependencies.
Open build.gradle file of Launcher module.
add the following dependencies.
The EnefitsSDK Unity android package can be downloaded from this link.
Select Project layout. Go to the Assets folder. Right-click and select Import Package -> Custom Package.

Select a downloaded Enefits package and choose 'Open'. Make sure all components are selected from the package and then click on 'Import'.

Please make sure to call any SDK method inside 'UNITY_ANDROID && !UNITY_EDITOR' block, as it is only available for android device:
<App_Name> - string type - describes your Unity application name
<API_key> - string type - API key provided to you during the registration at https://x.enefits.co/.
EnefitsSessionCallback.cs has a method 'onInitComplete', where you will get init call status.
Display a button or call-to-action (for example: 'Connect Wallet') which when tapped will prompt the user to connect a wallet.
After the user selects a wallet and initiates a session, the returned address will be available to the Enefits SDK to check NFTs and any offers the user is eligible for.
This function will open a view with a list of supported providers
Enefits SDK fires the callback after successfully connecting with a blockchain account.
EnefitsSessionCallback.cs has a method called 'onSessionConnected', where you will get information about wallet connection address and info about blockchain.
and if the unity client app is not able to connect to the wallet then,
and if no supported wallet app is installed in device, then you will get EnefitsSessionCallback.cs callback at:
This method returns all Offers that the user is eligible for based on the address they provided when they connected their wallet.
you will receive offers related information in EnefitsOffersCallback.cs
Use the functions provided below to create tighter integration with the Enefits SDK and manage user connectivity states.
Once the Wallet becomes disconnected, method onSessionDisconnected will be called from EnefitsSessionCallback.cs.