using UnityEngine;
using System.Collections.Generic;
public class AdColonyManager : MonoBehaviour
{
private const string android_appId = "xxxxxxxxxxxxxxxxxxx";
private const string android_zoneId = "xxxxxxxxxxxxxxxxxxx";
private const string ios_appId = "xxxxxxxxxxxxxxxxxxx";
private const string ios_zoneId = "xxxxxxxxxxxxxxxxxxx";
private string appId = string.Empty;
private string zoneId = string.Empty;
private AdColony.InterstitialAd ad = null;
void Start()
{
Initialize();
}
private void Initialize()
{
#if UNITY_ANDROID
this.appId = android_appId;
this.zoneId = android_zoneId;
#elif UNITY_IOS
this.appId = ios_appId;
this.zoneId = ios_zoneId;
#endif
AdColony.Ads.OnConfigurationCompleted += (List<AdColony.Zone> zones_) =>
{
Debug.Log("AdColony.Ads.OnConfigurationCompleted called");
if (zones_ == null || zones_.Count <= 0)
{
Debug.Log("Configure Failed");
}
else
{
Debug.Log("Configure Succeeded.");
}
};
AdColony.Ads.OnRequestInterstitial += (AdColony.InterstitialAd ad_) =>
{
Debug.Log("AdColony.Ads.OnRequestInterstitial called");
ad = ad_;
// to do ...
// 광고 요청에 성공했을 때 처리
ShowAd();
};
AdColony.Ads.OnRequestInterstitialFailed += () =>
{
Debug.Log("AdColony.Ads.OnRequestInterstitialFailed called");
// to do ...
// 광고 요청에 실패했을 때 처리
};
AdColony.Ads.OnOpened += (AdColony.InterstitialAd ad_) =>
{
Debug.Log("AdColony.Ads.OnOpened called");
};
AdColony.Ads.OnClosed += (AdColony.InterstitialAd ad_) =>
{
Debug.Log("AdColony.Ads.OnClosed called, expired: " + ad_.Expired);
};
AdColony.Ads.OnExpiring += (AdColony.InterstitialAd ad_) =>
{
Debug.Log("AdColony.Ads.OnExpiring called");
};
AdColony.Ads.OnRewardGranted += (string zoneId, bool success, string name, int amount) =>
{
Debug.Log(string.Format("AdColony.Ads.OnRewardGranted called\n\tzoneId: "
+ "{0}\n\tsuccess: {1}\n\tname: {2}\n\tamount: {3}",
zoneId, success, name, amount));
if (success)
{
// to do ...
// 광고 시청이 완료되었을 때 처리
// 광고 시청에 대한 보상 지급 등 ...
}
};
AdColony.AppOptions appOptions = new AdColony.AppOptions();
appOptions.AdOrientation = AdColony.AdOrientationType.AdColonyOrientationAll;
AdColony.Ads.Configure(this.appId, appOptions, this.zoneId);
}
public void RequestAd()
{
Debug.Log("**** Request Ad ****");
AdColony.AdOptions adOptions = new AdColony.AdOptions();
adOptions.ShowPrePopup = false;
adOptions.ShowPostPopup = false;
AdColony.Ads.RequestInterstitialAd(this.zoneId, adOptions);
}
public void ShowAd()
{
Debug.Log("**** Show Ad ****");
if (this.ad != null)
{
AdColony.Ads.ShowAd(this.ad);
}
}
}