Created
September 21, 2019 06:10
-
-
Save yasuyuki-kamata/330780cd3a4f7f71231172ac5dc137ae to your computer and use it in GitHub Desktop.
Unity Monetization SDK 動画広告表示のサンプルコード
This file contains 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.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