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