|
|
|
|
/*
|
|
|
|
|
http://www.cgsoso.com/forum-211-1.html
|
|
|
|
|
|
|
|
|
|
CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
|
|
|
|
|
|
|
|
|
|
CGSOSO 主打游戏开发,影视设计等CG资源素材。
|
|
|
|
|
|
|
|
|
|
插件如若商用,请务必官网购买!
|
|
|
|
|
|
|
|
|
|
daily assets update for try.
|
|
|
|
|
|
|
|
|
|
U should buy the asset from home store if u use it in your project!
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//using GoogleMobileAds.Api;
|
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class AdmobController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
private static AdmobController instance;
|
|
|
|
|
|
|
|
|
|
public static bool isRewardedAdAvailable = false;
|
|
|
|
|
public static bool isInterAdAvailable = false;
|
|
|
|
|
public static AdmobController Instance
|
|
|
|
|
{
|
|
|
|
|
get { return instance; }
|
|
|
|
|
}
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (instance == null)
|
|
|
|
|
{
|
|
|
|
|
instance = this;
|
|
|
|
|
DontDestroyOnLoad(this.gameObject);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_ANDROID
|
|
|
|
|
string appKey = "85460dcd";
|
|
|
|
|
#elif UNITY_IPHONE
|
|
|
|
|
string appKey = "8545d445";
|
|
|
|
|
#else
|
|
|
|
|
string appKey = "unexpected_platform";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log("unity-script: IronSource.Agent.validateIntegration");
|
|
|
|
|
IronSource.Agent.validateIntegration();
|
|
|
|
|
IronSource.Agent.setConsent(true);
|
|
|
|
|
|
|
|
|
|
Debug.Log("unity-script: unity version" + IronSource.unityVersion());
|
|
|
|
|
|
|
|
|
|
// SDK init
|
|
|
|
|
Debug.Log("unity-script: IronSource.Agent.init");
|
|
|
|
|
IronSource.Agent.init(appKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
//Add Init Event
|
|
|
|
|
IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
|
|
|
|
|
|
|
|
|
|
//Add ImpressionSuccess Event
|
|
|
|
|
IronSourceEvents.onImpressionDataReadyEvent += ImpressionDataReadyEvent;
|
|
|
|
|
|
|
|
|
|
//Add AdInfo Rewarded Video Events
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdOpenedEvent += RewardedVideoOnAdOpenedEvent;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdClosedEvent += RewardedVideoOnAdClosedEvent;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdAvailableEvent += RewardedVideoOnAdAvailable;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdUnavailableEvent += RewardedVideoOnAdUnavailable;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdShowFailedEvent += RewardedVideoOnAdShowFailedEvent;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdRewardedEvent += RewardedVideoOnAdRewardedEvent;
|
|
|
|
|
IronSourceRewardedVideoEvents.onAdClickedEvent += RewardedVideoOnAdClickedEvent;
|
|
|
|
|
|
|
|
|
|
//Add AdInfo Interstitial Events
|
|
|
|
|
IronSourceInterstitialEvents.onAdReadyEvent += InterstitialOnAdReadyEvent;
|
|
|
|
|
IronSourceInterstitialEvents.onAdLoadFailedEvent += InterstitialOnAdLoadFailed;
|
|
|
|
|
IronSourceInterstitialEvents.onAdOpenedEvent += InterstitialOnAdOpenedEvent;
|
|
|
|
|
IronSourceInterstitialEvents.onAdClickedEvent += InterstitialOnAdClickedEvent;
|
|
|
|
|
IronSourceInterstitialEvents.onAdShowSucceededEvent += InterstitialOnAdShowSucceededEvent;
|
|
|
|
|
IronSourceInterstitialEvents.onAdShowFailedEvent += InterstitialOnAdShowFailedEvent;
|
|
|
|
|
IronSourceInterstitialEvents.onAdClosedEvent += InterstitialOnAdClosedEvent;
|
|
|
|
|
|
|
|
|
|
//Add AdInfo Banner Events
|
|
|
|
|
IronSourceBannerEvents.onAdLoadedEvent += BannerOnAdLoadedEvent;
|
|
|
|
|
IronSourceBannerEvents.onAdLoadFailedEvent += BannerOnAdLoadFailedEvent;
|
|
|
|
|
IronSourceBannerEvents.onAdClickedEvent += BannerOnAdClickedEvent;
|
|
|
|
|
IronSourceBannerEvents.onAdScreenPresentedEvent += BannerOnAdScreenPresentedEvent;
|
|
|
|
|
IronSourceBannerEvents.onAdScreenDismissedEvent += BannerOnAdScreenDismissedEvent;
|
|
|
|
|
IronSourceBannerEvents.onAdLeftApplicationEvent += BannerOnAdLeftApplicationEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnApplicationPause(bool isPaused)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: OnApplicationPause = " + isPaused);
|
|
|
|
|
IronSource.Agent.onApplicationPause(isPaused);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Init callback handlers
|
|
|
|
|
|
|
|
|
|
void SdkInitializationCompletedEvent()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got SdkInitializationCompletedEvent");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!CUtils.IsBuyItem() && !CUtils.IsAdsRemoved())
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
IronSource.Agent.loadBanner(IronSourceBannerSize.SMART, IronSourceBannerPosition.BOTTOM);
|
|
|
|
|
IronSource.Agent.loadInterstitial();
|
|
|
|
|
IronSource.Agent.loadRewardedVideo();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region AdInfo Rewarded Video
|
|
|
|
|
public void RewardedVideoOnAdOpenedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdOpenedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdClosedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdClosedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdAvailable(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdAvailable With AdInfo " + adInfo);
|
|
|
|
|
isRewardedAdAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdUnavailable()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdUnavailable");
|
|
|
|
|
isRewardedAdAvailable = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdShowFailedEvent(IronSourceError ironSourceError, IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoAdOpenedEvent With Error" + ironSourceError + "And AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdRewardedEvent(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdRewardedEvent With Placement" + ironSourcePlacement + "And AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RewardedVideoOnAdClickedEvent(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got RewardedVideoOnAdClickedEvent With Placement" + ironSourcePlacement + "And AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region AdInfo Interstitial
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdReadyEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdReadyEvent With AdInfo " + adInfo);
|
|
|
|
|
isInterAdAvailable = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdLoadFailed(IronSourceError ironSourceError)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdLoadFailed With Error " + ironSourceError);
|
|
|
|
|
isInterAdAvailable = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdOpenedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdOpenedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdClickedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdClickedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdShowSucceededEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdShowSucceededEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdShowFailedEvent(IronSourceError ironSourceError, IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdShowFailedEvent With Error " + ironSourceError + " And AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InterstitialOnAdClosedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got InterstitialOnAdClosedEvent With AdInfo " + adInfo);
|
|
|
|
|
IronSource.Agent.loadInterstitial();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Banner AdInfo
|
|
|
|
|
|
|
|
|
|
void BannerOnAdLoadedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdLoadedEvent With AdInfo " + adInfo);
|
|
|
|
|
// IronSource.Agent.displayBanner();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BannerOnAdLoadFailedEvent(IronSourceError ironSourceError)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdLoadFailedEvent With Error " + ironSourceError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BannerOnAdClickedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdClickedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BannerOnAdScreenPresentedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdScreenPresentedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BannerOnAdScreenDismissedEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdScreenDismissedEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BannerOnAdLeftApplicationEvent(IronSourceAdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity-script: I got BannerOnAdLeftApplicationEvent With AdInfo " + adInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ImpressionSuccess callback handler
|
|
|
|
|
|
|
|
|
|
void ImpressionDataReadyEvent(IronSourceImpressionData impressionData)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("unity - script: I got ImpressionDataReadyEvent ToString(): " + impressionData.ToString());
|
|
|
|
|
Debug.Log("unity - script: I got ImpressionDataReadyEvent allData: " + impressionData.allData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|