광고를 로드하기 전 ONEAdMax 초기화가 필요하며,
ONEAdMaxClient.Initialize() 는최초 한 번만 수행해야 합니다.
...
using ONEAdMax;
...
public class ONEAdMaxDemo : MonoBehaviour
{
private static bool _isInitialized = false;
void Start()
{
if (!_isInitialized)
{
// Initialize the ONEAdMax SDK.
ONEAdMaxClient.Initialize(() =>
{
// This callback is called once the ONEAdMax SDK is initialized.
_isInitialized = true
});
}
}
}
전면 비디오 광고 샘플 코드
OAMInterstitialVideo 인스턴스를 생성하고, 이벤트를 처리하여 기능을 확장할 수 있습니다.
전면 비디오 광고 인스턴스 생성하기
public class InterstitialVideoAdController : MonoBehaviour
{
OAMInterstitialVideo _interstitialVideoAd;
/// <summary>
/// Creates the ad.
/// </summary>
public void CreateInterstitialVideoAd()
{
Debug.Log("Creating Interstitial video ad.");
if (_interstitialVideoAd != null)
{
Debug.LogWarning("Already have a Interstitial video ad.");
return;
}
_interstitialVideoAd = new OAMInterstitialVideo();
}
}
네트워크 스케쥴 타임아웃 설정 (선택사항)
광고에 대한 네트워크 스케쥴 타임아웃을 설정합니다. (기본값: 5초)
광고 로딩 시 각 네트워크 별로 타임아웃 시간을 주어 해당 시간 안에 광고를 받지 못할 경우, 다음 네트워크로 넘어갑니다.
/// <summary>
/// Register to events the interstital video ad may raise.
/// </summary>
private void RegisterEvents(OAMInterstitialVideo ad)
{
// Raised when an ad is loaded into the interstitial ad.
ad.OnLoaded += () =>
{
Debug.Log("Interstitial video ad loaded.");
};
// Raised when an ad fails to load into the interstitial ad.
ad.OnLoadFailed += (OAMError error) =>
{
Debug.LogError("Interstitial video ad failed to load an ad with error : " + error);
};
// Raised when an ad opened full screen content.
ad.OnOpened += () =>
{
Debug.Log("Interstitial video ad has been opened.");
};
// Raised when the ad failed to open full screen content.
ad.OnOpenFailed += (OAMError error) =>
{
Debug.LogError("Interstitial video ad failed to open an ad with error : " + error);
};
// Raised when the ad closed full screen content.
ad.OnClosed += () =>
{
Debug.LogError("Interstitial video ad is closed.");
};
}
전면 비디오 광고 생성하기
모든 설정을 완료하고 OAMInterstitialVideo를 만듭니다.
// These ad units are configured to always serve test ads.
private readonly string _placementId = "string your placementID";
_interstitialVideoAd.Create(_placementId);
전면 비디오 광고 로드 하기
전면 비디오 광고 Load() API를 호출하여 서버에 광고를 요청합니다.
/// <summary>
/// Loads the ad.
/// </summary>
public void Load()
{
if (_interstitialVideoAd == null)
{
Debug.LogWarning("The interstital video ad is null.");
return;
}
_interstitialVideoAd.Load();
}
과도한 광고 요청은 차단 사유가 되니 주의해주세요!
전면 비디오 광고 노출하기
로드가 완료되면 광고를 노출을 원하는 시점에 Show() API를 호출하여 화면에 노출 시킵니다.
/// <summary>
/// Shows the ad.
/// </summary>
public void Show()
{
if (_interstitialVideoAd != null && _interstitialVideoAd.IsLoaded())
{
Debug.Log("Showing interstital video ad.");
_interstitialVideoAd.Show();
}
else
{
Debug.LogError("The Interstitial video ad hasn't loaded yet.");
}
}
전면 비디오 광고 메모리 해지하기
전면 광고의 인스턴스 내의 메모리를 해지 합니다.
/// <summary>
/// Destroys the ad.
/// </summary>
public void Destroy()
{
if (_interstitialVideoAd != null)
{
Debug.Log("Destroying interstitial video ad.");
_interstitialVideoAd.Destroy();
_interstitialVideoAd = null;
}
}