기술 자료

지원

Unity에서 SDK 초기화

Initialize the Unity Ads SDK with your Game ID to enable monetization and access Unity Ads public APIs in your Unity project.
읽는 시간 1분

SDK를 초기화하려면, 해당 플랫폼의 프로젝트에 있는 게임 ID를 참조해야 합니다. Unity Ads Monetization 대시보드에서 Monetization 제품군을 선택하고 두 번째 내비게이션 바에서 현재 프로젝트, Settings로 차례로 이동한 다음 Game IDs 섹션으로 스크롤하여 게임 ID를 찾을 수 있습니다. 게임 스크립트 헤더에
UnityEngine.Advertisements
네임스페이스를 포함시킵니다.
Initialize
함수를 사용하여 게임 런타임 수명주기 초반에, 가능하다면 앱 시작 시 SDK를 초기화하십시오. SDK 버전 3.7.0 이상에서는
IUnityAdsInitializationListener
콜백을 사용하면 초기화가 완료되었을 때 알림을 받거나 오류가 발생할 때 세부 정보를 받을 수 있습니다.
using UnityEngine;
using UnityEngine.Advertisements;
 
public class AdsInitializer : MonoBehaviour, IUnityAdsInitializationListener
{
    [SerializeField] string _androidGameId;
    [SerializeField] string _iOSGameId;
    [SerializeField] bool _testMode = true;
    private string _gameId;
 
    void Awake()
    {
        InitializeAds();
    }
 
    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}");
    }
}
다음 단계: Unity에서 기본 광고 구현 기술 자료를 참조하여 연동을 계속 진행하십시오.

Unity에서 SDK 초기화 • Unity Grow • Unity Docs