본문 바로가기
개발/Unity

unity ads testmode

by dev_caleb 2024. 6. 26.
728x90
using UnityEngine;
using UnityEngine.Advertisements;

public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
[SerializeField] string _androidGameId;
[SerializeField] string _iOSGameId;
[SerializeField] bool _testMode = true; // 초기값은 true로 설정합니다.
private string _gameId;

void Awake()
{
SetTestMode();
InitializeAds();
}

private void SetTestMode()
{
#if DEBUG
_testMode = true;
#else
_testMode = false;
#endif
}

public void InitializeAds()
{
#if UNITY_IOS
_gameId = _iOSGameId;
#elif UNITY_ANDROID
_gameId = _androidGameId;
#elif UNITY_EDITOR
_gameId = _androidGameId; // Only for testing the functionality in the Editor
#endif
if (!Advertisement.isInitialized && Advertisement.isSupported)
{
Advertisement.Initialize(_gameId, _testMode, this);
}
}

public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
}

public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
}

 

728x90