Skip to content

Instantly share code, notes, and snippets.

@yasuyuki-kamata
Created September 21, 2019 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuyuki-kamata/330780cd3a4f7f71231172ac5dc137ae to your computer and use it in GitHub Desktop.
Save yasuyuki-kamata/330780cd3a4f7f71231172ac5dc137ae to your computer and use it in GitHub Desktop.
Unity Monetization SDK 動画広告表示のサンプルコード
using System;
using UnityEngine;
using UnityEngine.Monetization;
public class MonetizationVideoExample : MonoBehaviour
{
public bool testMode;
public string appleAppStoreGameId = "3289755";
public string googlePlayStoreGameId = "3289754";
public string placementId = "rewardedVideo";
private string _gameId = "";
private ShowAdCallbacks _showAdCallbacks;
private void Start ()
{
InitUnityAds();
}
private void InitUnityAds()
{
if (!Monetization.isSupported) return;
#if UNITY_IOS
_gameId = appleAppStoreGameId;
#elif UNITY_ANDROID
_gameId = googlePlayStoreGameId;
#endif
Monetization.Initialize(_gameId, testMode);
_showAdCallbacks = new ShowAdCallbacks {startCallback = AdStart, finishCallback = AdFinished};
}
public void ShowAd()
{
if (!Monetization.IsReady(placementId)) return;
ShowAdPlacementContent pc =
(ShowAdPlacementContent) Monetization.GetPlacementContent(placementId);
pc.Show(_showAdCallbacks);
}
private static void AdStart()
{
Debug.Log("Ad Start!!!!");
}
private static void AdFinished(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, null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment