Last active
September 21, 2019 07:01
-
-
Save yasuyuki-kamata/b4a4cf17e9576edc3aca998a5b0d5483 to your computer and use it in GitHub Desktop.
Unity Monetization SDK Load APIのサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UnityEngine.Advertisements; | |
public class LoadExample : MonoBehaviour, IUnityAdsListener | |
{ | |
public bool testMode; | |
public string appleAppStoreGameId = "INPUT YOUR GAME ID"; | |
public string googlePlayStoreGameId = "INPUT YOUR GAME ID"; | |
public string placementId = "rewardedVideo"; | |
private string _gameId = ""; | |
private void Start () | |
{ | |
InitUnityAds(); | |
} | |
private void InitUnityAds() | |
{ | |
if (!Advertisement.isSupported) return; | |
#if UNITY_IOS | |
_gameId = appleAppStoreGameId; | |
#elif UNITY_ANDROID | |
_gameId = googlePlayStoreGameId; | |
#endif | |
Advertisement.Initialize(_gameId, testMode, true); | |
Advertisement.AddListener(this); | |
} | |
public void LoadAd() | |
{ | |
if (Advertisement.isInitialized == false) | |
{ | |
Debug.Log("Unity Ads not initialized"); | |
return; | |
} | |
Advertisement.Load(placementId); | |
} | |
public void ShowAd() | |
{ | |
if (!Advertisement.IsReady(placementId)) return; | |
Advertisement.Show(placementId); | |
} | |
public void OnUnityAdsReady(string placementId) | |
{ | |
} | |
public void OnUnityAdsDidError(string message) | |
{ | |
} | |
public void OnUnityAdsDidStart(string placementId) | |
{ | |
Debug.Log("Ad Start!!!!"); | |
} | |
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult) | |
{ | |
switch (showResult) | |
{ | |
case ShowResult.Finished: | |
Debug.Log("Ads Finished!"); | |
break; | |
case ShowResult.Skipped: | |
Debug.Log("Ads Skipped!"); | |
break; | |
case ShowResult.Failed: | |
Debug.Log("Ads Failed.."); | |
break; | |
default: | |
throw new ArgumentOutOfRangeException(nameof(showResult), showResult, $"placementId:{placementId}"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment