IEnumerator Start() { #if UNITY_IPHONE ADBannerView banner = new ADBannerView(); banner.autoSize = true; if(mPosition == AdBannerPosition.top) { banner.autoPosition = ADPosition.Top; } else { banner.autoPosition = ADPosition.Bottom; } while (true) { if (banner.error != null) { Debug.Log("Error: " + banner.error.description); break; } else if (banner.loaded) { banner.Show(); break; } yield return null; } #elif UNITY_ANDROID && !UNITY_EDITOR AndroidJavaClass plugin = new AndroidJavaClass("jp.radiumsoftware.unityplugin.admob.AdBannerController"); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); while (true) { plugin.CallStatic("tryCreateBanner", activity, mAdMobPublisherId, mAdMobTestDeviceId, mPosition.ToString()); yield return new WaitForSeconds(Mathf.Max(30.0f, mRefreshTime)); } #else return null; #endif }
IEnumerator Start() { #if UNITY_IPHONE ADBannerView banner = new ADBannerView(); banner.autoSize = true; banner.autoPosition = ADPosition.Bottom; while (true) { if (banner.error != null) { Debug.Log("Error: " + banner.error.description); break; } else if (banner.loaded) { banner.Show(); break; } yield return null; } #elif UNITY_ANDROID && !UNITY_EDITOR AndroidJavaClass plugin = new AndroidJavaClass("net.oira_project.adstirunityplugin.AdBannerController"); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); while (true) { plugin.CallStatic("tryCreateBanner", activity, mAdStirMediaId, mAdStirSpotId); yield return new WaitForSeconds(Mathf.Max(30.0f, mRefreshTime)); } #else return null; #endif }
private IEnumerator StartBanner() { if (dontDestroy) { GameObject.DontDestroyOnLoad(gameObject); // keep ad alive if we load a new scene } banner = new ADBannerView(); banner.autoSize = true; banner.autoPosition = showOnTop ? ADPosition.Top : ADPosition.Bottom; while (!banner.loaded && banner.error == null) { yield return null; } if (banner.error == null) { banner.Show(); } else { banner = null; } }