###前提・実現したいこと
こちらのサイトを参考にインタースティシャルを実装しようと思っているのですが、サイトに掲載されているコードで、破棄する処理にフラグをつけている理由がわかりません。
###該当のソースコード
C#
1using UnityEngine; 2using System.Collections; 3using GoogleMobileAds.Api; 4 5public class AdMob : MonoBehaviour { 6 7 public string Android_Interstitial; 8 public string ios_Interstitial; 9 10 private BannerView bannerView; 11 private InterstitialAd _interstitial; 12 13 bool is_close_interstitial = false; 14 15 // Use this for initialization 16 void Awake () { 17 } 18 // Use this for initialization 19 void Start () { 20 // 起動時にインタースティシャル広告をロードしておく 21 RequestInterstitial (); 22 } 23 public void RequestInterstitial() 24 { 25 #if UNITY_ANDROID 26 string adUnitId = Android_Interstitial; 27 #elif UNITY_IPHONE 28 string adUnitId = ios_Interstitial; 29 #else 30 string adUnitId = "unexpected_platform"; 31 #endif 32 33 if (is_close_interstitial == true) { 34 _interstitial.Destroy (); 35 } 36 37 // Initialize an InterstitialAd. 38 _interstitial = new InterstitialAd (adUnitId); 39 // Create an empty ad request. 40 AdRequest request = new AdRequest.Builder ().AddTestDevice("").Build (); 41 // Load the interstitial with the request. 42 _interstitial.LoadAd (request); 43 44 is_close_interstitial = false; 45 } 46 47 void HandleAdClosed (object sender, System.EventArgs e) 48 { 49 is_close_interstitial = true; 50 } 51}
なぜ、「is_close_interstitial」というフラグをつけて破棄させているのでしょうか?
HandleAdClosed()の中で直接、「_interstitial.Destroy ();」を呼び出して破棄しては不都合が生じることがあるのでしょうか?
HandleAdClosed()の中で直接、「_interstitial.Destroy ();」と書いた場合と、差異があるケースなどを教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/24 05:42