Rewarded Video Integration for Unity (Chinese)
第 1 步. 实现激励视频事件
ironSource Unity 插件可触发多个事件通知您广告可用性。在 IronSource/Assets/Prefabs 下,您可以找到 IronSourceEventsPrefab。将其添加至您的项目中以接收这些事件。 添加以下代码以注册这些事件:
public class VideoScript : MonoBehaviour {
void Start()
{
IronSourceEvents.onRewardedVideoAdOpenedEvent += RewardedVideoAdOpenedEvent;
IronSourceEvents.onRewardedVideoAdClosedEvent += RewardedVideoAdClosedEvent;
IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += RewardedVideoAvailabilityChangedEvent;
IronSourceEvents.onRewardedVideoAdStartedEvent += RewardedVideoAdStartedEvent;
IronSourceEvents.onRewardedVideoAdEndedEvent += RewardedVideoAdEndedEvent;
IronSourceEvents.onRewardedVideoAdRewardedEvent += RewardedVideoAdRewardedEvent;
IronSourceEvents.onRewardedVideoAdShowFailedEvent += RewardedVideoAdShowFailedEvent;
}
}
插件将通知Listener所有下列可能的事件:
//Invoked when the RewardedVideo ad view has opened.
//Your Activity will lose focus. Please avoid performing heavy
//tasks till the video ad will be closed.
void RewardedVideoAdOpenedEvent() {
}
//Invoked when the RewardedVideo ad view is about to be closed.
//Your activity will now regain its focus.
void RewardedVideoAdClosedEvent() {
}
//Invoked when there is a change in the ad availability status.
//@param - available - value will change to true when rewarded videos are available.
//You can then show the video by calling showRewardedVideo().
//Value will change to false when no videos are available.
void RewardedVideoAvailabilityChangedEvent(bool available) {
//Change the in-app 'Traffic Driver' state according to availability.
bool rewardedVideoAvailability = available;
}
//Invoked when the video ad starts playing.
void RewardedVideoAdStartedEvent() {
}
//Invoked when the video ad finishes playing.
void RewardedVideoAdEndedEvent() {
}
//Invoked when the user completed the video and should be rewarded.
//If using server-to-server callbacks you may ignore this events and wait for
//the callback from the ironSource server.
//@param - placement - placement object which contains the reward data
void RewardedVideoAdRewardedEvent(IronSourcePlacement placement) {
}
//Invoked when the Rewarded Video failed to show
//@param description - string - contains information about the failure.
void RewardedVideoAdShowFailedEvent (IronSourceError error){
}
第 2 步. 向您的用户展示视频广告
通过 onRewardedVideoAvailabilityChangedEvent 事件,您可获得激励视频广告可用状态。
void onRewardedVideoAvailabilityChangedEvent(bool available) {
//Change the in-app 'Traffic Driver' state according to availability.
bool rewardedVideoAvailability = available;
}
或者,您可通过此调用直接请求广告可用状态:
bool available = IronSource.Agent.isRewardedVideoAvailable();
一旦广告网络有可用视频时,您即已准备好向用户展示此视频广告。此时是插入鼓励用户观看视频广告触发器的理想时机。在您的 IronSource.Agent 实例内调用 showRewardedVideo() 方法,您即可向用户展示视频广告:
IronSource.Agent.showRewardedVideo();
籍由 ironSource 广告展示位置工具,您可自定义并优化激励视频体验。此工具允许您依奖励不同而从不同展示位置向用户展示视频。您可使用以下函数定义您希望的准确广告展示位置来源。请前往广告展示位置文档以了解更多细节信息。 此展示位置的奖励设置将从 ironSource 服务器中抓取获得:
IronSource.Agent.showRewardedVideo("YOUR_PLACEMENT_NAME");
要获取关于每个广告展示位置关联的指定奖励详情,您可调用以下代码:
Placement placement = IronSource.Agent.getPlacementInfo(placementName);
//Placement can return null if the placementName is not valid.
if(placement != null)
{
String rewardName = placement.getRewardName();
int rewardAmount = placement.getRewardAmount();
}
除 ironSource’s 广告展示位置外,您现在可为所选展示位置广告配置频次和花费预算节奏设置。频次和花费预算节奏可通过限制在给定时间内的总广告投放数来提升应用的用户体验。请在此处了解更多关于频次和花费预算节奏的信息。
bool isRewardedVideoPlacementCapped(string placementName);
全新!动态 UserID 验证 AdRewarded Transactions 动态 UserID 是在会话中可更改的参数,其可在服务器至服务器广告奖励回调中接收。此参数可帮助验证 AdRewarded transactions ,且其必须在调用 ShowRewardedVideo 前设置。
boolean setDynamicUserId(String dynamicUserID);
第 3 步. 奖励用户
IronSource SDK 将在用户每次成功完成一条视频时触发 onRewardedVideoAdRewardedEvent 。
void RewardedVideoAdRewardedEvent(IronSourcePlacement ssp){
//TODO - here you can reward the user according to the reward name and amount
ssp.getPlacementName();
ssp.getRewardName());
ssp.getRewardAmount();
}
完成! 您现在已在应用中设置好投放激励视频。