Skip to content

Setup game ads to sponsor gas fees

Overview

This sample project showcases the Openfort integration with Unity LevelPlay.

The sample includes:

Application Workflow

Integration workflow

Prerequisites

Set up Openfort dashboard

  • Add an NFT contract

    This sample requires an NFT contract to run. We use 0xbed6a05ce8719bc00db1cc81a814192c82be1bb1 (contract deployed in 80002 Amoy). You can use it for this tutorial too:

    Contract Info
  • Add an ERC20 contract

    This sample also requires an ERC20 contract to run. You can deploy a standard one and then add it to the Openfort dashboard following the same logic as above.

  • Add a Full Sponsor Policy

    We aim to cover gas fees for our users when they mint the NFT (if they have watched the ad video). Set a new gas policy for that:

    Gas Policy

    Add a rule so the NFT contract uses this policy:

    NFT Policy Rule

    Add also a rule for the ERC20 contract, as we want to send some ERC20 tokens to the player to be able to test the sample:

    ERC20 Policy Rule
  • Add a Fixed Charge Policy

    The users will be charged with 1 in-game ERC20 token when they decide not to watch the ad:

    Fixed charge policy

    Add a rule so the policy applies to the NFT contract:

    NFT Policy Rule
  • Add a Backend wallett

    Enter a name and choose Add account:

    Developer account

    This will automatically create a custodial wallet that we'll use to send the ERC20 tokens to the users. IMPORTANT: Transfer a good amount of tokens from the created ERC20 contract to this wallet to facilitate testing.

Set up ironSource

  • Get Unity Cloud keys

    Before going into ironSource, go to the Unity Cloud dashboard and open Unity Ads Monetization using Shortcuts:

    Unity Cloud dashboard: Unity Ads Monetization
    • Create a LevelPlay Service Account

      Now go to the API management section and choose Create LevelPlay Service Account:

      Unity Cloud dashboard: Create LevelPlay Service Account

      Copy and save the Key ID and the Secret key somewhere safe and choose Done:

      Unity Cloud dashboard: Copy LevelPlay Service Account credentials
    • Get Monetization Stats API Access

      Copy and save the API Key. Choose Create API Key if it's not already there:

      Unity Cloud dashboard: copy Monetization Stats API key
    • Get Organization Core ID

      Copy and save the Organization Core ID:

      Unity Cloud dashboard: copy Organization Core ID
  • Create an ironSource LevelPlay app

    Go to the ironSource dashboard and under the LevelPlay section, choose Add app and enter your app details:

    ironSource: new app

    Select the following settings and choose Add app:

    ironSource: app details

    Activate Rewarded Video as an ad unit and choose Continue:

    ironSource: activate ad units
  • Set up SDK Networks

    In the Available Networks panel select Unity Ads:

    ironSource: available networks

    Enable the Unity bidder auto-setup option, add all the credentials from the Get Unity Cloud keys section and choose Save:

    ironSource: adding Unity Ads

    Unity Ads will have appeared as a new available network. Choose Setup:

    ironSource: setup Unity Ads

    Because we enabled the Unity bidder auto-setup option, now you can choose Add bidder:

    ironSource: add bidder

    The needed information from Unity will be automatically retrieved. Choose Save:

    ironSource: save app

Set up Unity Cloud

Thanks to the Unity bidder auto-setup option, a new project has been automatically created in the Unity Cloud dashboard. Now your LevelPlay Service Account needs to have some admin roles over this newly created project. Go to Administration --> Service accounts and choose your account:

Set up Unity Cloud: service account

Scroll down and choose Manage project roles:

Set up Unity Cloud: manage project roles

Select your project and choose Next:

Set up Unity Cloud: select project

In the Admin dropdown select:

  • Player Resource Policy Editor
  • Project Resource Policy Editor
  • Unity Environments Admin

In the LiveOps dropdown select:

  • Cloud Code Script Publisher
  • Triggers Configuration Editor
  • Leaderboards Admin
  • Cloud Code Editor

Choose Save:

Set up Unity Cloud dashboard: add roles

Set up ugs-backend

Set up unity-client

In Unity go to Edit --> Project Settings --> Services and link the unity-client to your UGS Project:

Services settings

Select your Environment:

UGS environment

Under Assets --> Scripts --> Controllers open the AdsController.cs:

AdsController.cs

Fill the appKey variable with the ironSource LevelPlay app key and save the script:

ironSource LevelPlay app key
ironSource LevelPlay app key

Build to Android

In Unity go to Android Player settings and make sure Other Settings looks like this:

Android Player settings

Also, make sure to sign the application with a Keystore in Publishing Settings:

Application Signing

Return to Build Settings and choose Build:

Build

Send and run the .apk on your device.

Conclusion

Upon completing the above steps, your Unity game will be fully integrated with Openfort and Unity LevelPlay. Always remember to test every feature before deploying to guarantee a flawless player experience.

For a deeper understanding of the underlying processes, check out the tutorial video.

Get support

If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.

If you have questions, or comments, or need help with code, we're here to help: