# 04. Unity-Plugin Guide

## Development environment

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>Unity</strong></td><td>2022.3.11f1</td></tr><tr><td><strong>Java SDK (Java 11)</strong></td><td>ONE AdMax SDK v1.2.1</td></tr></tbody></table>

## Requirements

* Unity 2022.3.11f1 or higher
* Android SDK version
  * Minimum API Level 16 or higher
  * Target API Level 33 or higher

{% hint style="info" %}
The Android API level can be configured in **Project Settings > Player > Other Settings**.
{% endhint %}

{% embed url="<https://github.com/ONE-AdMax/ONEAdMax-Unity/releases>" %}

### Importing ONE AdMax for Unity Plugin

In the Unity menu bar, click **Assets > Import Package > Custom Package**.

<figure><img src="https://content.gitbook.com/content/ZDVBIifJAulXFJsiJTgC/blobs/3v48C0Kd8foeJPp16MgD/image.png" alt=""><figcaption></figcaption></figure>

The **`Assets/OneStoreCorpPlugins/com.oneadmax.global`** folder will be created.

> [EDM4U(External Dependency Manager for Unity)](https://github.com/googlesamples/unity-jar-resolver) is distributed as a required component.\
> If you are already using it, uncheck **`ExternalDependencyManager`** during the `Import Package` step before proceeding.

## Include external dependencies

To include repositories and dependencies in your project, follow these steps:\
\&#xNAN;**`Project Settings > Player > Publishing Settings > Build`**

* Custom Main Manifest
* Custom Main Gradle Template
* Custom Gradle Settings Template

<figure><img src="https://content.gitbook.com/content/ZDVBIifJAulXFJsiJTgC/blobs/qI0MeKKZtXq4Rxr3PRC8/image.png" alt=""><figcaption></figcaption></figure>

Go to **`Assets > External Dependency Manager > Android Resolver > Force Resolve`** and select it.

The Maven Repository URL will be applied to the **`settingsTemplate.gradle`** file.

<figure><img src="https://content.gitbook.com/content/ZDVBIifJAulXFJsiJTgC/blobs/vRjO3SzGJB8OoprAlPgF/image.png" alt=""><figcaption></figcaption></figure>

The Maven Module will be applied to the **`mainTemplate.gradle`** file.

<figure><img src="https://content.gitbook.com/content/ZDVBIifJAulXFJsiJTgC/blobs/vFHiLPcSJ20QSXK7hlII/image.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The dependencies for the ONEAdMax for Unity plugin are listed in the following file:\
**Assets/OneStoreCorpPlugins/com.oneadmax.global/Editor/ONEAdMaxDependencies.xml**
{% endhint %}

***

## Issuing and applying the media key

{% content-ref url="01.-how-to-issue-a-media-key" %}
[01.-how-to-issue-a-media-key](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/01.-how-to-issue-a-media-key)
{% endcontent-ref %}

If you have received the media key, you need to configure the `<meta-data />` in the **AndroidManifest.xml** file.

```csharp
<manifest>
    ...
    <application>
        ...
        <activity android:name="com.unity3d.player.UnityPlayerActivity">
            ...
        </activity>

        <meta-data android:name="com.oneadmax.global.appkey" android:value="your app key"/>
    </application>
</manifest>
```

{% hint style="warning" %}

* Please confirm that the media key is added to the **AndroidManifest.xml**.
* Since the media key is read by the Java SDK, regardless of the Unity plugin, the `<meta-data />` should be located inside the `<application>` element.
  {% endhint %}

## SDK required permissions

```csharp
<manifest>
    ...
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    ...
</manifest>
```

***

## SDK Initialize

Before loading ads, the app must initialize ONEAdMax.\
The initialization with `ONEAdMaxClient.Initialize()` should be done only once.

```csharp
...
using ONEAdMax;
...
public class ONEAdMaxDemo : MonoBehaviour
{
    private static bool _isInitialized = false;
    
    void Start()
    {
        if (!_isInitialized)
        {
            // Initialize the ONEAdMax SDK.
            ONEAdMaxClient.Initialize(() =>
            {
                // This callback is called once the ONEAdMax SDK is initialized.
                _isInitialized = true
            });
        }
    }
}
```

### Log Settings

For development, you can enable detailed logs for ONEAdMax. (default: false)

```csharp
ONEAdMaxClient.SetLogEnable(true);
```

### GDPR Settings

To comply with the EU's GDPR (General Data Protection Regulation), the following API is added. Please call the API only for users who require GDPR consent. (default: true)

```csharp
ONEAdMaxClient.GdprConsentAvailable(true);
```

### COPPA Settings <a href="#coppa" id="coppa"></a>

To comply with the COPPA (Children's Online Privacy Protection Act), the following API is added. On such devices, all ad requests will result in "No ad" being served. (default: false)

```csharp
ONEAdMaxClient.tagForChildDirectedTreatment(false);
```

### Application Quit

When the application is closed, it releases the resources allocated in memory (such as views and memory).

```csharp
void OnApplicationQuit()
{
    ONEAdMaxClient.Destroy();
}
```

***

## Mediation settings

For stable Fill Rates and eCPM, it is recommended to set up a waterfall mediation.

{% content-ref url="sdk" %}
[sdk](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/sdk)
{% endcontent-ref %}

***

## Choose ad format

### Rewarded Video ADs

This is a reward-based video ad.\
When the video ad finishes, the completion information is sent via the **Complete event callback**.

{% content-ref url="unityplugin/rewardedvideo" %}
[rewardedvideo](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/unityplugin/rewardedvideo)
{% endcontent-ref %}

### Interstitial ADs

This is an ad that covers the entire screen of the app. Once completed or interrupted by the user, the app's screen will be displayed.

{% content-ref url="unityplugin/interstitial" %}
[interstitial](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/unityplugin/interstitial)
{% endcontent-ref %}

### Banner ADs

This displays a rectangular ad that occupies part of the app's screen. \
You can set the position and time to automatically refresh the ad.

{% content-ref url="unityplugin/banner" %}
[banner](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/unityplugin/banner)
{% endcontent-ref %}

### Interstitial Video ADs (Non Reward)

This is an ad type similar to video ads, but without offering rewards.

{% content-ref url="unityplugin/video" %}
[video](https://one-admax-organization.gitbook.io/one-admax-sdk/oneadmax_dev_guide_en/unityplugin/video)
{% endcontent-ref %}
