Skip to content

Commit

Permalink
release yandex-ads-unity-plugin-0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
satsakul committed Sep 20, 2018
0 parents commit ff0ce52
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

## Version 0.1.0

#### Added
* Support for Banner Ads
* Support for Interstitial Ads
2 changes: 2 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EULA could be found at:
https://legal.yandex.com/partner_ch/
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Yandex Mobile Ads Unity Plugin

This repository contains Yandex Mobile Ads Unity plugin. This plugin allows Unity developers to easily integrate Yandex Mobile Ads on Android and iOS apps.

## Documentation
Documentation could be found at the [official website][DOCUMENTATION]

## License
EULA is available at [EULA website][LICENSE]

## Quick start

1. To use Yandex Mobile Ads Unity plugin in your project download folder `mobileads-unity-plugin`

2. Open your project in the Unity editor

3. Select `Assets > Import Package > Custom Package` and find the `yandex-mobileads-<version>.unitypackage` file.

If you are already using [Google resolver] just use `yandex-mobileads-lite-<version>.unitypackage`

4. Make sure all of the files are selected and click Import.

5. Add [Metrica Unity plugin](https://appmetrica.yandex.com/doc//mobile-sdk-dg/concepts/unity-plugin-docpage/) to the project.

6. You can use one of demo scripts in folder `samples` to test plugin. Just add one of this files to your project.

## Yandex Mobile Ads Mediation

Third-party networks can be connected to Yandex Mobile Ads Mediation by several steps:

1. Import `yandex-mobileads-lite-<version>.unitypackage` to your project

2. Import unity package of the desired third-party network

3. Set up meditation according to [AdFox documentation](https://tech.yandex.com/mobile-ads/doc/dg/ios/adfox/my-target-adfox-docpage/)

## Third-party mediation

### AdMob

1. Integrate [AdMob](https://developers.google.com/admob/unity/start)

2. Import package `admob-mobileads-mediation-<version>.unitypackage` from folder `third-party-networks-mediation`

3. Get the Block ID in the Yandex Partner interface for each Ad Unit created in AdMob. Then set up mediation in [the AdMob web interface](apps.admob.com).

For more information, please visit [AdMob documentation](https://tech.yandex.com/mobile-ads/doc/dg/android/quick-start/admob-adapter-docpage/#setting)

### MoPub

1. Integrate [MoPub](https://developers.mopub.com/docs/unity)

2. Import package `mopub-mobileads-mediation-<version>.unitypackage` from the folder `third-party-networks-mediation`

3. Get the Block ID in the Yandex Partner interface for each Ad Unit created in MoPub. Then set up mediation in [the MoPub web interface](app.mopub.com).

For more information, please visit [MoPub documentation](https://tech.yandex.com/mobile-ads/doc/dg/android/quick-start/mopub-adapter-docpage/)

## Unity packages

| Package | Description |
| --- | --- |
| yandex-mobileads | Main Yandex Mobile Ads package |
| yandex-mobileads-lite | Main Yandex Mobile Ads package distributed for using with [Google resolver]|
| mobileads-admob-mediation | AdMob mediation |
| mobileads-facebook-mediation | Facebook mediation |
| mobileads-mytarget-mediation | MyTarget mediation |
| mobileads-startapp-mediation | StartApp mediation |
| admob-mobileads-mediation | Third-party mediation with AdMob |
| mopub-mobileads-mediation| Third-party mediation with MoPub |

[Google resolver]: https://github.com/googlesamples/unity-jar-resolver
[DOCUMENTATION]: https://tech.yandex.com/mobile-ads/
[LICENSE]: https://legal.yandex.com/partner_ch/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
123 changes: 123 additions & 0 deletions samples/YandexMobileAdsBannerDemoScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* This file is a part of the Yandex Advertising Network
*
* Version for Android (C) 2018 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
*/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YandexMobileAds;
using YandexMobileAds.Base;

public class YandexMobileAdsBannerDemoScript : MonoBehaviour
{
private readonly float ButtonWidth = 0.8f * Screen.width;
private readonly float ButtonHeight = 0.1f * Screen.height;
private readonly float ColumnPosition = 0.1f * Screen.width;
private readonly float RowFirstPosition = 0.05f * Screen.height;
private readonly float RowSecondPosition = 0.225f * Screen.height;
private readonly int FontSize = (int) (0.035f * Screen.width);

private Banner banner;

void Start() {
Screen.orientation = ScreenOrientation.Portrait;
}

public void OnGUI()
{
GUIStyle style = new GUIStyle();

GUI.skin.button.fontSize = FontSize;

Rect requestBannerRect = this.CreateButton(ColumnPosition, RowFirstPosition);
if (GUI.Button(requestBannerRect, "Request\nBanner"))
{
this.RequestBanner();
}

Rect destroyBannerRect = this.CreateButton(ColumnPosition, RowSecondPosition);
if (GUI.Button(destroyBannerRect, "Destroy\nBanner"))
{
this.banner.Destroy();
}
}

private void RequestBanner()
{
// Replace demo R-M-DEMO-320x50 with actual Block ID
// Following demo Block IDs may be used for testing:
// R-M-DEMO-320x50
// R-M-DEMO-320x50-app_install
// R-M-DEMO-728x90
// R-M-DEMO-320x100-context
// R-M-DEMO-300x250
// R-M-DEMO-300x250-context
// R-M-DEMO-300x300-context
string adUnitId = "R-M-DEMO-320x50";

if (this.banner != null)
{
this.banner.Destroy();
}

this.banner = new Banner(adUnitId, AdSize.BANNER_320x50, AdPosition.BottomCenter);

this.banner.OnAdLoaded += this.HandleAdLoaded;
this.banner.OnAdFailedToLoad += this.HandleAdFailedToLoad;
this.banner.OnAdOpened += this.HandleAdOpened;
this.banner.OnAdClosed += this.HandleAdClosed;
this.banner.OnAdLeftApplication += this.HandleAdLeftApplication;

this.banner.LoadAd(this.CreateAdRequest());
}

private Rect CreateButton(float positionX, float positionY)
{
return new Rect(
positionX,
positionY,
ButtonWidth,
ButtonHeight);
}

private AdRequest CreateAdRequest()
{
return new AdRequest.Builder().Build();
}

#region Banner callback handlers

public void HandleAdLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLoaded event received");
this.banner.Show();
}

public void HandleAdFailedToLoad(object sender, AdFailureEventArgs args)
{
MonoBehaviour.print("HandleAdFailedToLoad event received with message: " + args.Message);
}

public void HandleAdOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdOpened event received");
}

public void HandleAdClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdClosed event received");
}

public void HandleAdLeftApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleAdLeftApplication event received");
}

#endregion
}
158 changes: 158 additions & 0 deletions samples/YandexMobileAdsInterstitialDemoScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* This file is a part of the Yandex Advertising Network
*
* Version for Android (C) 2018 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
*/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YandexMobileAds;
using YandexMobileAds.Base;

public class YandexMobileAdsInterstitialDemoScript : MonoBehaviour
{
private readonly float ButtonWidth = 0.8f * Screen.width;
private readonly float ButtonHeight = 0.1f * Screen.height;
private readonly float ColumnPosition = 0.1f * Screen.width;
private readonly float RowFirstPosition = 0.05f * Screen.height;
private readonly float RowSecondPosition = 0.225f * Screen.height;
private readonly float RowThirdPosition = 0.4f * Screen.height;
private readonly int FontSize = (int) (0.035f * Screen.width);

private Interstitial interstitial;

void Start() {
Screen.orientation = ScreenOrientation.Portrait;
}

public void OnGUI()
{
GUIStyle style = new GUIStyle();

GUI.skin.button.fontSize = FontSize;

Rect requestInterstitialRect = this.CreateButton(ColumnPosition, RowFirstPosition);
if (GUI.Button(requestInterstitialRect, "Request\nInterstitial"))
{
this.RequestInterstitial();
}

Rect showInterstitialRect = this.CreateButton(ColumnPosition, RowSecondPosition);
if (GUI.Button(showInterstitialRect, "Show\nInterstitial"))
{
this.ShowInterstitial();
}

Rect destroyInterstitialRect = this.CreateButton(ColumnPosition, RowThirdPosition);
if (GUI.Button(destroyInterstitialRect, "Destroy\nInterstitial"))
{
this.interstitial.Destroy();
}
}

private void RequestInterstitial()
{
// Replace demo R-M-DEMO-240x400-context with actual Block ID
// Following demo Block IDs may be used for testing:
// R-M-DEMO-240x400-context
// R-M-DEMO-400x240-context
// R-M-DEMO-320x480
// R-M-DEMO-480x320
string adUnitId = "R-M-DEMO-240x400-context";

if (this.interstitial != null)
{
this.interstitial.Destroy();
}

this.interstitial = new Interstitial(adUnitId);

this.interstitial.OnInterstitialLoaded += this.HandleInterstitialLoaded;
this.interstitial.OnInterstitialFailedToLoad += this.HandleInterstitialFailedToLoad;
this.interstitial.OnInterstitialOpened += this.HandleInterstitialOpened;
this.interstitial.OnInterstitialClosed += this.HandleInterstitialClosed;
this.interstitial.OnInterstitialLeftApplication += this.HandleInterstitialLeftApplication;
this.interstitial.OnInterstitialShown += this.HandleInterstitialShown;
this.interstitial.OnInterstitialFailedToShow += this.HandleInterstitialFailedToShow;
this.interstitial.OnInterstitialDismissed += this.HandleInterstitialDismissed;

this.interstitial.LoadAd(this.CreateAdRequest());
}

private Rect CreateButton(float positionX, float positionY)
{
return new Rect(
positionX,
positionY,
ButtonWidth,
ButtonHeight);
}

private void ShowInterstitial()
{
if (this.interstitial.IsLoaded())
{
this.interstitial.Show();
}
else
{
MonoBehaviour.print("Interstitial is not ready yet");
}
}

private AdRequest CreateAdRequest()
{
return new AdRequest.Builder().Build();
}

#region Interstitial callback handlers

public void HandleInterstitialLoaded(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialLoaded event received");
}

public void HandleInterstitialFailedToLoad(object sender, AdFailureEventArgs args)
{
MonoBehaviour.print(
"HandleInterstitialFailedToLoad event received with message: " + args.Message);
}

public void HandleInterstitialOpened(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialOpened event received");
}

public void HandleInterstitialClosed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialClosed event received");
}

public void HandleInterstitialLeftApplication(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialLeftApplication event received");
}

public void HandleInterstitialShown(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialShown event received");
}

public void HandleInterstitialFailedToShow(object sender, AdFailureEventArgs args)
{
MonoBehaviour.print(
"HandleInterstitialFailedToShow event received with message: " + args.Message);
}

public void HandleInterstitialDismissed(object sender, EventArgs args)
{
MonoBehaviour.print("HandleInterstitialDismissed event received");
}

#endregion
}
Binary file not shown.
Binary file not shown.

0 comments on commit ff0ce52

Please sign in to comment.