Displaying Ads - Banners

Homa Belly does support the following Ad formats:

  • Rewarded video ads
  • Banners
  • Interstitials

Banners

Showing a Banner

In order to show a banner, register the onBannerAdLoadedEvent and call LoadBanner

// Register events & load banner
Events.onBannerAdLoadedEvent += OnBannerAdLoadedEvent;
HomaBelly.Instance.LoadBanner(HomaGames.HomaBelly.BannerSize.BANNER, HomaGames.HomaBelly.BannerPosition.BOTTOM);

Once the banner is loaded, onBannerAdLoadedEvent will be invoked, so you are ready to show it

// Callback invoked when the requested banner is loaded
private void OnBannerAdLoadedEvent()
{
    HomaBelly.Instance.ShowBanner();
}

Hiding a Banner

Whenever you want to hide the currently displayed banner, call HideBanner

HomaBelly.Instance.HideBanner();

Showing two banners at the same time

It is possible to show two banners at the same time.

Make sure to obtain a secondary banner ad unit id and to not place the second banner in the same `BannerPosition` than the default one.

Here's a sample code snippet you can use as inspiration:


using HomaGames.HomaBelly; using UnityEngine; public class MultipleBannerSample : MonoBehaviour { // To show multiple banner ads, you need the secondary placement ID (not the default one) private const string BannerSecondPlacementId = "YOUR_PLACEMENT_ID_2"; private void Start() { // Register a callback to show an ad after it has loaded Events.onBannerAdLoadedEvent += ShowAd; // Register a callback to load an ad after SDK initialization Events.onInitialized += LoadBanners; } private void LoadBanners() { // To show an ad it has to be loaded beforehand HomaBelly.Instance.LoadBanner(BannerPosition.BOTTOM); HomaBelly.Instance.LoadBanner(BannerPosition.TOP, BannerSecondPlacementId); } private void ShowAd(AdInfo adInfo) { // show an ad with placement ID provided in the `Events.onBannerAdLoadedEvent` payload HomaBelly.Instance.ShowBanner(adInfo.PlacementId); } }

Making UI work with a banner

To get the size of the displayed banner in pixel, you can call

HomaBelly.Instance.GetBannerHeight();

⚠️ Like all methods in this page, you must wait for Homa Belly initialization before calling it.

You can also make use of the BannerSafeAreaHelper component. If you apply it on your canvas game object, it will take its “SafeArea” child and resize it to make sure its content is not blocked by banners.

💡 This component will also resize the SafeArea object to fit the Screen.safeArea rectangle.

When you add it to your canvas object, it should look like this:

Untitled-2

You can use the editor tool to create a “SafeArea” child and automatically move the current canvas children into the safe area.

You then need to specify the position and the background color of the banner you will use and you are all set:

HomaBelly.Instance.SetBannerPosition(BannerPosition position, string placementId = null);
HomaBelly.Instance.SetBannerBackgroundColor(Color color, string placementId = null);

An AdInfo holds :

  • A PlacementId : the “ad unit”, “placement id”, or identifier used by the mediator
  • An AdType : the type of ad (usually Banner, Interstitial or Rewarded)
  • An AdPlacementType : tells you where this ad placement is coming from

API Reference