Loading an MREC

To load an MREC, call CreateMRec(), passing in your ad unit ID and desired adview position:

string mrecAdUnitId = "ios_ad_unit_ID"; // Retrieve the ID from your account
string mrecAdUnitId = "android_ad_unit_ID"; // Retrieve the ID from your account

public void InitializeMRecAds()
  // MRECs are sized to 300x250 on phones and tablets
  MaxSdk.CreateMRec(mrecAdUnitId, MaxSdkBase.AdViewPosition.Centered);

  MaxSdkCallbacks.MRec.OnAdLoadedEvent      += OnMRecAdLoadedEvent;
  MaxSdkCallbacks.MRec.OnAdLoadFailedEvent  += OnMRecAdLoadFailedEvent;
  MaxSdkCallbacks.MRec.OnAdClickedEvent     += OnMRecAdClickedEvent;
  MaxSdkCallbacks.MRec.OnAdRevenuePaidEvent += OnMRecAdRevenuePaidEvent;
  MaxSdkCallbacks.MRec.OnAdExpandedEvent    += OnMRecAdExpandedEvent;
  MaxSdkCallbacks.MRec.OnAdCollapsedEvent   += OnMRecAdCollapsedEvent;

public void OnMRecAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo error) {}

public void OnMRecAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdExpandedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

public void OnMRecAdCollapsedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {}

The above example creates an MREC centered on the display (Centered). The complete list of position options are:

  • TopLeft
  • TopCenter
  • TopRight
  • Centered
  • CenterLeft
  • CenterRight
  • BottomLeft
  • BottomCenter
  • BottomRight

You can also position an MREC at a specific (x, y) coordinate on the screen by calling MaxSdk.CreateMRec(ad-unit-ID, x, y);. This sets the position of the top-left corner of the ad. The coordinate system represents the safe area bounds of the screen. Make sure to account for the width and height of the ad when you set these coordinates. The position (0, 0) is equivalent to TopLeft; the bottom-right corner of the safe area is (safeAreaWidth, safeAreaHeight). Note that Unity might have a different screen size or safe area size than Android or iOS. To convert between Unity’s screen size and the sizes used in Android or iOS, use code like the following:

var density = MaxSdkUtils.GetScreenDensity();
var dp = pixels / density;

Hiding and Showing an MREC

To show an MREC ad, call ShowMRec():


To hide an MREC ad, call HideMRec():


Destroying MREC Ads

After you are no longer using an MREC ad, you must clean up its resources by calling DestroyMRec(). If you do not do this, the performance of your app will degrade.


Stopping and Starting Auto-Refresh

There may be cases when you would like to stop auto-refresh, for instance, if you want to manually refresh MREC ads. To stop auto-refresh for an MREC ad, use the following code:


Start auto-refresh for an MREC ad with the following code:


Manually refresh the contents with the following code. Note that you must stop auto-refresh before you call LoadMRec().