Skip to content

Commit f097774

Browse files
nventimiglicopybara-github
authored andcommitted
Added Anchored Adaptive Banner snippets.
PiperOrigin-RevId: 794662645
1 parent f4347ef commit f097774

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using GoogleMobileAds.Api;
5+
using GoogleMobileAds.Api.AdManager;
6+
7+
namespace GoogleMobileAds.Snippets
8+
{
9+
internal class AdManagerAnchoredAdaptiveBannerViewSnippets
10+
{
11+
private const string AD_UNIT_ID = "/21775744923/example/adaptive-banner";
12+
13+
AdManagerBannerView bannerView;
14+
15+
private void CreateAnchoredAdaptiveBannerView()
16+
{
17+
// [START get_device_full_width]
18+
// Get the device full width in density-independent pixels.
19+
int deviceFullWidth = Mathf.RoundToInt(Screen.width / MobileAds.Utils.GetDeviceScale());
20+
// [END get_device_full_width]
21+
22+
// [START get_device_width]
23+
// Get the device safe width in density-independent pixels.
24+
int deviceWidth = MobileAds.Utils.GetDeviceSafeWidth();
25+
// [END get_device_width]
26+
27+
// [START get_adaptive_size]
28+
// Define the anchored adaptive ad size.
29+
AdSize adaptiveSize =
30+
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);
31+
// [END get_adaptive_size]
32+
33+
// [START create_anchored_adaptive_banner_view]
34+
// Create an anchored adaptive banner view.
35+
bannerView = new AdManagerBannerView(AD_UNIT_ID, adaptiveSize, AdPosition.Bottom);
36+
// [END create_anchored_adaptive_banner_view]
37+
}
38+
}
39+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using GoogleMobileAds.Api;
5+
using GoogleMobileAds.Api.AdManager;
6+
7+
namespace GoogleMobileAds.Snippets
8+
{
9+
internal class AnchoredAdaptiveBannerViewSnippets
10+
{
11+
#if UNITY_ANDROID
12+
private const string AD_UNIT_ID = "ca-app-pub-3940256099942544/9214589741";
13+
#elif UNITY_IPHONE
14+
private const string AD_UNIT_ID = "ca-app-pub-3940256099942544/2435281174";
15+
#else
16+
private const string AD_UNIT_ID = "unused";
17+
#endif
18+
BannerView bannerView;
19+
20+
private void CreateAnchoredAdaptiveBannerView()
21+
{
22+
// [START get_device_full_width]
23+
// Get the device full width in density-independent pixels.
24+
int deviceFullWidth = Mathf.RoundToInt(Screen.width / MobileAds.Utils.GetDeviceScale());
25+
// [END get_device_full_width]
26+
27+
// [START get_device_width]
28+
// Get the device safe width in density-independent pixels.
29+
int deviceWidth = MobileAds.Utils.GetDeviceSafeWidth();
30+
// [END get_device_width]
31+
32+
// [START get_adaptive_size]
33+
// Define the anchored adaptive ad size.
34+
AdSize adaptiveSize =
35+
AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);
36+
// [END get_adaptive_size]
37+
38+
// [START create_anchored_adaptive_banner_view]
39+
// Create an anchored adaptive banner view.
40+
bannerView = new BannerView(AD_UNIT_ID, adaptiveSize, AdPosition.Bottom);
41+
// [END create_anchored_adaptive_banner_view]
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)