Last active
November 13, 2018 17:40
-
-
Save yasuyuki-kamata/c53e84fa2071e31c8a1996929e3441ca to your computer and use it in GitHub Desktop.
Unity Monetization SDK3.0 のリワード動画広告でコールバックを設定する例
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.Monetization; | |
public class AdsController : MonoBehaviour | |
{ | |
public bool TestMode; | |
public string IosGameId = "2907766"; | |
public string AndroidGameId = "2907765"; | |
// public string VideoPlacementId = "video"; | |
public string RewardedPlacementId = "rewardedVideo"; | |
private string _gameId = ""; | |
private ShowAdCallbacks _showAdCallbacks; | |
private void Start () | |
{ | |
InitUnityAds(); | |
} | |
private void InitUnityAds() | |
{ | |
if (!Monetization.isSupported) return; | |
#if UNITY_IOS | |
_gameId = IosGameId; | |
#elif UNITY_ANDROID | |
_gameId = AndroidGameId; | |
#endif | |
Monetization.Initialize(_gameId, TestMode); | |
_showAdCallbacks = new ShowAdCallbacks {startCallback = AdStart, finishCallback = AdFinished}; | |
} | |
public void ShowAd() | |
{ | |
if (!Monetization.IsReady(RewardedPlacementId)) return; | |
var pc = Monetization.GetPlacementContent(RewardedPlacementId) as ShowAdPlacementContent; | |
if (pc != null) 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("showResult", showResult, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment