여기서는 Unity 애즈를 Unity 엔진에 통합하는 다음 두 가지 방법에 대해 설명합니다.
내용
빌드 설정 창을 사용하여 프로젝트를 지원 플랫폼에 맞게 설정할 수 있습니다.
플랫폼을 iOS 또는 Android 로 설정한 다음 Switch Platform 을 클릭합니다.
서비스 창 방법과 에셋 패키지 방법 중 선택한 통합 방법에 따라 애즈 서비스 활성화 절차가 약간 다릅니다.
애즈를 활성화하려면 Unity 서비스를 사용할 수 있게 프로젝트를 설정해야 합니다. 그러기 위해서는 Organization 과 Project Name 을 설정해야 합니다. 서비스 설정 문서를 참조하십시오.
서비스가 설정되면 다음과 같이 Unity 애즈를 활성화할 수 있습니다.
애즈를 에셋 패키지에 통합하려면 아래 설명에 따라 Unity 애즈 게임 ID를 먼저 생성해야 합니다.
Unity 애즈 게임 ID 생성
웹 브라우저에서 Unity 개발자 네크워크(UDN) 계정을 사용하여 Unity 애즈 대시보드로 이동한 후 Add new project 를 선택합니다.
해당 플랫폼(iOS, Android, 또는 둘 다)을 선택합니다.
플랫폼에 해당하는 Game ID
를 찾아서 나중에 사용할 수 있게 복사합니다.
에셋 패키지에 애즈 통합
Unity 애즈 네임스페이스 UnityEngine.Advertisements
를 스크립트 헤더에서 선언합니다. ( UnityEngine.Advertisements 문서 참조)
using UnityEngine.Advertisements;
복사한 게임 ID 문자열인 gameId
를 사용하여 스크립트에서 Unity 애즈를 초기화합니다.
Advertisement.Initialize(string gameId)
참고: 초기화 호출은 일반적으로 코드의 Start()
함수에 포함됩니다.
참고: Unity 애즈는 Unity 5.2 이상의 서비스 창에서 사용 가능합니다.
서비스가 활성화된 상태에서 코드를 스크립트에서 구현하여 광고를 표시할 수 있습니다.
Unity 애즈 네임스페이스 UnityEngine.Advertisement
를 스크립트 헤더에서 선언합니다. ( UnityEngine.Advertisements 문서 참조)
``` using UnityEngine.Advertisements;
```
Show()
함수를 호출하여 광고를 표시합니다.
Advertisement.Show()
광고를 시청한 플레이어에게 보상을 제공하면 사용자 참여가 증가하여 수익이 높아집니다. 예를 들어 게임에서 플레이어에게 게임 화폐, 소모품, 추가 생명, 경험치 증가 아이템 등을 보상으로 제공할 수 있습니다.
비디오 광고를 모두 본 플레이어에게 보상하려면 아래 예제의 HandleShowResult
콜백 메서드를 사용합니다. result
가 ShowResult.Finished
와 같은지 확인하여 사용자가 광고를 건너뛰지 않았음을 입증해야 합니다.
Show()
호출 시 메서드를 파라미터로 전달합니다.Show()
를 "rewardedVideo"
플레이스먼트와 함께 호출하여 비디오를 건너뛸 수 없게 합니다.참고: placements
에 대한 자세한 내용은 Unity 애즈 문서를 참조하십시오.
void ShowRewardedVideo ()
{
var options = new ShowOptions();
options.resultCallback = HandleShowResult;
Advertisement.Show("rewardedVideo", options);
}
void HandleShowResult (ShowResult result)
{
if(result == ShowResult.Finished) {
Debug.Log("Video completed - Offer a reward to the player");
}else if(result == ShowResult.Skipped) {
Debug.LogWarning("Video was skipped - Do NOT reward the player");
}else if(result == ShowResult.Failed) {
Debug.LogError("Video failed to show");
}
}
아래 코드를 사용하여 보상 광고 버튼을 생성할 수 있습니다. 광고 버튼을 누르면 사용 가능한 광고가 있는 경우 해당 광고가 표시됩니다.
Game Object > UI > Button 을 선택하여 버튼을 씬에 추가합니다.
씬에 추가한 버튼을 선택한 다음 인스펙터를 사용하여 스크립트 컴포넌트를 버튼에 추가합니다. (인스펙터에서 Add Component > New Script 선택)
스크립트를 열고 아래 코드를 추가합니다.
참고: 에셋 패키지 통합에만 해당하는 코드 섹션 두 개가 따옴표로 콜아웃되어 있습니다.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
//---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
#if UNITY_IOS
private string gameId = "1486551";
#elif UNITY_ANDROID
private string gameId = "1486550";
#endif
//-------------------------------------------------------------------//
ColorBlock newColorBlock = new ColorBlock();
public Color green = new Color(0.1F, 0.8F, 0.1F, 1.0F);
[RequireComponent(typeof(Button))]
public class UnityAdsButton : MonoBehaviour
{
Button m_Button;
public string placementId = "rewardedVideo";
void Start ()
{
m_Button = GetComponent<Button>();
if (m_Button) m_Button.onClick.AddListener(ShowAd);
if (Advertisement.isSupported) {
Advertisement.Initialize (gameId, true);
}
//---------- ONLY NECESSARY FOR ASSET PACKAGE INTEGRATION: ----------//
if (Advertisement.isSupported) {
Advertisement.Initialize (gameId, true);
}
//-------------------------------------------------------------------//
}
void Update ()
{
if (m_Button) m_Button.interactable = Advertisement.IsReady(placementId);
}
void ShowAd ()
{
var options = new ShowOptions();
options.resultCallback = HandleShowResult;
Advertisement.Show(placementId, options);
}
void HandleShowResult (ShowResult result)
{
if(result == ShowResult.Finished) {
Debug.Log("Video completed - Offer a reward to the player");
}else if(result == ShowResult.Skipped) {
Debug.LogWarning("Video was skipped - Do NOT reward the player");
}else if(result == ShowResult.Failed) {
Debug.LogError("Video failed to show");
}
}
}
}
Unity 에디터에서 Play 를 눌러 애즈 버튼이 제대로 통합되었는지 테스트합니다.
자세한 내용은 Unity 애즈 포럼을 참조하십시오.
프로젝트에서 설정을 사용하여 플레이스먼트와 기타 게임별 설정을 수정할 수 있습니다. 플레이스먼트에 대한 자세한 내용은 Unity 애즈 문서를 참조하십시오.
웹 브라우저에서 Unity 개발자 네크워크(UDN) 계정을 사용하여 Unity 애즈 대시보드로 이동한 후 게임 프로젝트를 찾습니다.
해당 플랫폼(iOS 또는 Android)을 선택합니다.
플레이스먼트를 선택합니다. Unity 애즈 문서를 참조하십시오.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.