# 리워드 비디오 광고

### 1 : 준비

* [프로젝트 설정](/adpie/unity/project-settings.md)을 통해 광고 연동을 위한 준비를 합니다.
* [사이트](http://my.adpies.com) 에서 매체를 등록하여 Media ID와 Slot ID 를 발급받습니다.

### 2 : SDK 초기화

* SDK 초기화를 하지 않았다면, [사이트](http://my.adpies.com)에서 발급받은 Media ID를 입력하여 초기화를 합니다.

```csharp
AdPieSDK.Instance.Initialize("AdPie-Media-ID");
```

### 3 : 광고 요청과 표출

* 사이트에서 발급받은 Slot ID를 입력하여 RewardedVideoAd 객체를 생성합니다.
* 광고 요청과 표출로 메소드가 각각 나누어져 있습니다.
* 광고 요청시 Load() 메소드를 호출하고, 표출 시 Show()를 호출을 합니다.
* 광고 컨텐츠가 로드되지 않을 가능성이 있기에 IsLoaded()를 통해 확인 후 Show() 메소드를 호출합니다.

```csharp
{
    // 광고 연동을 위한 슬롯 ID를 필수로 입력한다.
    RewardedVideoAd rewardedVideoAd = new RewardedVideoAd("AdPie-Slot-ID");
    rewardedVideoAd.Load();
}
```

### 4 : 광고 리스너 사용

* 광고 요청에 대한 이벤트를 수신할 수 있습니다.
* [에러코드](/adpie/unity/common/errorcode.md)를 통해 광고 실패에 대한 이유를 알 수 있습니다.

```csharp
{
    RewardedVideoAd rewardedVideoAd = new RewardedVideoAd("AdPie-Slot-ID");
    rewardedVideoAd.OnRewardedVideoLoaded += RewardedVideoAd_OnRewardedVideoLoaded;
    rewardedVideoAd.OnRewardedVideoFailedToLoad += RewardedVideoAd_OnRewardedVideoFailedToLoad;
    rewardedVideoAd.OnRewardedVideoClicked += RewardedVideoAd_OnRewardedVideoClicked;
    rewardedVideoAd.OnRewardedVideoStarted += RewardedVideoAd_OnRewardedVideoStarted;
    rewardedVideoAd.OnRewardedVideoFinished += RewardedVideoAd_OnRewardedVideoFinished;
    rewardedVideoAd.Load();
}

void RewardedVideoAd_OnRewardedVideoLoaded()
{
    // 광고 로딩 완료 후 이벤트 발생
    
    // 광고 요청 후 즉시 노출하고자 할 경우 아래의 코드를 추가합니다.
    if (rewardedVideoAd != null && rewardedVideoAd.IsLoaded())
    {
        rewardedVideoAd.Show();
    }
    
}

void RewardedVideoAd_OnRewardedVideoFailedToLoad(int errorCode)
{
    // 광고 요청 또는 표출 실패 후 이벤트 발생
}

void RewardedVideoAd_OnRewardedVideoClicked()
{
    // 광고 클릭 후 이벤트 발생
}

void RewardedVideoAd_OnRewardedVideoStarted()
{
    // 리워드 동영상 광고 시작 이벤트 발생
}

void RewardedVideoAd_OnRewardedVideoFinished(int finishState)
{
    // 리워드 동영상 광고 종료 이벤트 발생
    string state = "";
    switch(finishState) {
        case 0:
            state = "UNKNOWN";
            break;
        case 1:
            // 동영상 광고 시청완료
            state = "COMPLETED";
            break;
        case 2:
            // 동영상 광고 오류
            state = "ERROR";
            break;
        case 3:
            // 동영상 광고 건너뜀
            state = "SKIPPED";
            break;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform-business.gitbook.io/adpie/unity/integration/rewardedad.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
