Unity Ads Helper の使い方

18

Transcript of Unity Ads Helper の使い方

using UnityEngine;using UnityEngine.Advertisements;

public class UnityAdsSample : MonoBehaviour{

void Start (){

if (Advertisement.isSupported && !Advertisement.isInitialized) {Advertisement.Initialize ("1072596");

}}

public void ShowAd(){

if (Advertisement.IsReady()) {Advertisement.Show();

}}

}

• しかし・・

• iOSとAndroid分けるのめんどくさい

• 毎回同じif文を書くのはナンセンス

• 動画視聴完了時のコールバックを書くのがちょっと難しい

• 広告表示の仕組みをちょっとだけ工夫したい

• https://github.com/Applifier/unity-ads-helper

• Unity Adsヘルパーは、Unityプロジェクトへの Unity Ads の統合を簡素化するため

のもの

• 使い方はやや高度(プログラムがわかる人向け)だけれど、使いこなせると便利

• 簡単になってた

• Servicesウィンドウ(エディタ右上、雲のマーク)から

Unity AdsのサービスをONにする

• Unity Ads Helper を Github から探して README.md に書いてあるURLから

unitypackage をダウンロード

• 注意:2016年5月23日時点では、develop ブランチから持ってくること!

• https://github.com/Applifier/unity-ads-helper/tree/development

• ダウンロードした unitypackage をインポート

• Edit -> Unity Ads Settings を選択し、設定ファイルを作成する

• Resources/UnityAdsSettings という名前の SctiptableObject が作られる

• Servicesウィンドウに表示される Game ID を使う場合

はこのまま。

• そうでない場合は「Override initialization of Ads

Service」にチェックをいれて使用するGame IDを入力

• 必要なログレベルにチェックを入れる

• 動画広告のトリガーとなるボタンを用意する

• 作ったボタン(ButtonコンポーネントがついているGameObject)に、Add

Componentで UnityAdsButton コンポーネントを付与する。

• クリック時に発火する UnityEvent を設定

• UnityAdsButton クラスの中にある ShowAd () を選択

• Unity Ads Button コンポーネントの Cooldown Time に

クールダウンまでの時間(秒)を入力する

• Unity Ads Button コンポーネントの各UnityEvent

に任意の処理を登録

• OnFinished() - 動画視聴完了時に呼ばれる

• OnSkipped() - 動画視聴スキップして完了時に呼ばれる

• OnFailed() - 動画視聴失敗時に呼ばれる

public class UnityAdsSample : MonoBehaviour{/** 中略 **/

public void SomethingToDoWhenFinishedAd (){

Debug.Log ("Finished", this);}

public void SomethingToDoWhenSkippedAd (){

Debug.Log ("Skipped", this);}

public void SomethingToDoWhenFailedAd (){

Debug.Log ("Failed", this);}

}

Thank you!Hope your happy game development ;)

[email protected]