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
'개발 > Unity' 카테고리의 다른 글
unity 용량 큰 상태로 올리기 (0) | 2024.06.28 |
---|---|
unity 유니티 최적화 texture 압축 compression (0) | 2024.06.28 |
점프가 잘 안되었던 이유.. (0) | 2024.06.15 |
유니티 배경화면 변경하기 (0) | 2024.06.05 |
유니티 데이터 암호화 저장 (0) | 2024.06.05 |