> ## Documentation Index
> Fetch the complete documentation index at: https://beta-guide.daro.so/llms.txt
> Use this file to discover all available pages before exploring further.

# 배너 광고

> Unity 프로젝트에서 DARO 배너 광고를 구현하는 방법을 알아봅니다.

## 배너 광고 형태 소개

* 화면 상단 또는 하단에 고정으로 노출되는 광고입니다.
* Unity 화면 위에 네이티브 배너 뷰를 배치합니다.

***

## 광고 연동하기

<Steps>
  <Step title="광고 인스턴스 생성">
    ```csharp theme={null}
    private DaroBannerAd ad;

    ad = new DaroBannerAd(
        "your-banner-ad-unit-id",
        DaroBannerSize.Standard,
        DaroBannerPosition.BottomCenter
    );
    ```
  </Step>

  <Step title="이벤트 핸들러 등록">
    ```csharp theme={null}
    ad.OnAdLoaded += info => Debug.Log("loaded");
    ad.OnAdFailedToLoad += error => Debug.LogWarning(error.Message);
    ad.OnAdShown += info => Debug.Log("shown");
    ad.OnAdImpression += info => Debug.Log("impression");
    ad.OnAdClicked += info => Debug.Log("clicked");
    ad.OnAdHidden += info => Debug.Log("hidden");
    ```
  </Step>

  <Step title="광고 로드">
    ```csharp theme={null}
    ad.Load();
    ```

    로드가 성공하면 배너가 자동으로 표시됩니다. `Show()`는 `Hide()` 후 다시 표시할 때만 호출하세요.
  </Step>

  <Step title="광고 숨기기, 다시 표시하기 또는 해제">
    ```csharp theme={null}
    ad.Hide(); // 배너를 일시적으로 숨깁니다.

    if (ad.IsReady())
    {
        ad.Show(); // 숨겨진 배너를 다시 표시합니다.
    }

    ad.Dispose(); // 광고를 완전히 해제합니다.
    ```
  </Step>
</Steps>

***

## 배너 표시 영역 확인하기

`DaroBannerAd.GetScreenRect()`를 사용하면 네이티브 배너 뷰가 실제로 배치된 화면 영역을 확인할 수 있습니다.

반환값은 Unity screen pixel 기준의 `Rect?`입니다. 좌표계는 `Screen.safeArea`와 동일하게 화면 왼쪽 아래를 원점으로 사용합니다.

```csharp theme={null}
private System.Collections.IEnumerator WaitForBannerRect()
{
    for (var i = 0; i < 10; i++)
    {
        Rect? rect = ad?.GetScreenRect();
        if (rect.HasValue)
        {
            Debug.Log($"Banner rect: {rect.Value}");
            yield break;
        }

        yield return null;
    }
}
```

<Tip>
  네이티브 배너는 `Load()` 성공 후 자동 표시되거나 이후 `Show()`로 다시 표시된 시점에서 몇 프레임 뒤에 레이아웃이 완료됩니다. 표시 직후나 `OnAdShown` 안에서는 `null`이 반환될 수 있으므로, 필요한 경우 몇 프레임 동안 다시 확인하세요.
</Tip>

<Warning>
  `GetScreenRect()`는 배너가 아직 표시되지 않았거나, 숨겨졌거나, 해제된 경우 `null`을 반환합니다. 화면 회전이나 resize 이후에는 값이 바뀔 수 있으므로 다시 확인하세요.
</Warning>

***

## Example

```csharp expandable theme={null}
using Daro;
using UnityEngine;

public sealed class BannerHost : MonoBehaviour
{
    [SerializeField] private string adUnitId = "your-banner-ad-unit-id";
    private DaroBannerAd ad;

    private void OnEnable()
    {
        ad = new DaroBannerAd(
            adUnitId,
            DaroBannerSize.Standard,
            DaroBannerPosition.BottomCenter
        );

        ad.OnAdLoaded += info => Debug.Log("banner loaded");
        ad.OnAdFailedToLoad += error => Debug.LogWarning(error.Message);
        ad.OnAdShown += info => Debug.Log("banner shown");
        ad.Load();
    }

    public void Hide()
    {
        ad?.Hide();
    }

    public void Show()
    {
        if (ad != null && ad.IsReady())
        {
            ad.Show();
        }
    }

    private void OnDisable()
    {
        ad?.Dispose();
        ad = null;
    }
}
```
