Integration Examples
Example on handling the AdGem Offer Wall with the AdGem Unity SDK.
using UnityEngine;
public class AdGemOfferwallManager : MonoBehaviour
{
#if UNITY_IOS
private const int adGemAppId = 99999; // TODO: your AdGem iOS App ID goes here!
#elif UNITY_ANDROID
private const int adGemAppId = 88888; // TODO: your AdGem Android App ID goes here!
#endif
public delegate void OfferwallShownDelegate(bool shown);
void Awake()
{
AdGem.startSession(adGemAppId, false, false, true); // no standard videos or rewarded videos, but does use offerwall
}
void OnEnable()
{
AdGem.offerWallClosed += HandleOfferwallClosed;
AdGem.offerWallRewardReceived += HandleOfferwallRewardReceived;
}
void OnDisable()
{
AdGem.offerWallClosed -= HandleOfferwallClosed;
AdGem.offerWallRewardReceived -= HandleOfferwallRewardReceived;
}
private void HandleOfferwallClosed()
{
Debug.Log("AdGemOfferwallManager: OfferWall was closed");
UnmuteAudio();
}
private void HandleOfferwallRewardReceived(int currencyToAward)
{
if (currencyToAward > 0)
{
Debug.LogFormat("AdGemOfferwallManager: awarding {0} currency to player", currencyToAward);
// TODO: award the diamonds to the player in your game here!
}
}
public void ShowOfferwall(OfferwallShownDelegate onOfferwallShownCB)
{
if (AdGem.offerWallReady)
{
MuteAudio();
AdGem.showOfferWall();
// offerwall is ready, let the caller know that we have shown the offerwall
if (onOfferwallShownCB != null)
{
onOfferwallShownCB(true);
}
}
else
{
// offerwall is not ready, let the caller know that we couldn't show the offerwall
// TODO: you might want to notify the player that the OfferWall is not currently available, and to try again later
if (onOfferwallShownCB != null)
{
onOfferwallShownCB(false);
}
}
}
private void MuteAudio()
{
// pauses all sound and music (will resume from where left off when unpause)
AudioListener.pause = true;
}
private void UnmuteAudio()
{
// resume music and all sound effects
AudioListener.pause = false;
}
}
/*
// Sample use of AdGemOfferwallManager.ShowOfferwall:
// NOTE: this assumes you have an instance of AdGemOfferwallManager named adGemOfferwallManager
adGemOfferwallManager.ShowOfferwall(delegate (bool shown)
{
if (shown)
{
Debug.Log("AdGem Offerwall was shown");
}
else
{
Debug.Log("AdGem Offerwall was not shown");
}
});
*/