Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1.  
  2. public float GetPixelToPointFactor()
  3. {
  4. BannerView banner = new BannerView(BannerId, AdSize.Banner, AdPosition.TopLeft);
  5.  
  6. return AdSize.Banner.Width / banner.GetWidthInPixels();
  7. }
  8.  
  9. public float GetScaleFactor()
  10. {
  11. float scaleFactor = 0;
  12. if (scaleFactor == 0) scaleFactor = GetPixelToPointFactor();
  13. return scaleFactor;
  14. }
  15.  
  16. public void RequestBanner()
  17. {
  18. AdSize adSize = new AdSize(300, 250);
  19.  
  20.  
  21. int w;
  22. int h;
  23. if (Screen.dpi < 250)
  24. {
  25. w = 280;
  26. h = 200;
  27. }
  28. else
  29. {
  30. w = 75;
  31. h = 50;
  32. }
  33.  
  34. int xLocation = (int)(((float)Screen.width * 0.3125f) * GetScaleFactor());
  35. int yLocation = (int)(((float)Screen.height / 2f) * GetScaleFactor());
  36. if (xLocation < 0) xLocation = 0;
  37.  
  38. int adX = xLocation - (w / 2);
  39. int adY = yLocation - (h / 2);
  40.  
  41. bannerView = new BannerView(BannerId, AdSize.MediumRectangle, adX, adY);
  42.  
  43. AdRequest request = new AdRequest.Builder().Build();
  44.  
  45.  
  46. bannerView.LoadAd(request);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement