Yandex Games SDK API
安装插件后,您会发现对象 ysdk
,它是 同名的 Yandex 游戏 SDK 对象 的类型化等价物。它允许您访问 SDK 的所有方法。
以下是如何使用 Yandex 游戏 SDK 的 环境变量 的示例。
import { Component } from "cc";
import { ysdk } from "db://yandex-games-sdk/ysdk";
const { ccclass, property } = _decorator;
@ccclass("YourGameComponent")
export class YourGameComponent extends Component {
start() {
console.debug(`App ID: ${ysdk.environment.app.id}`);
console.debug(`User Language: ${ysdk.environment.i18n.lang}`);
console.debug(`URL Payload: ${ysdk.environment.payload}`);
}
update(deltaTime: number) {}
}
用于显示广告的组件
例如,我们创建一个按钮组件,用于启动带有奖励的视频广告。
此外,我们定义了方法 onReward()
并将其作为回调传递给 ysdk.adv.showRewardedVideo()
方法,以实现获取奖励事件的逻辑。
import { _decorator, Button, Component } from "cc";
import { ysdk } from "db://yandex-games-sdk/ysdk";
const { ccclass, property, requireComponent } = _decorator;
@ccclass("RewardADButton")
@requireComponent(Button)
export class RewardADButton extends Component {
start() {
this.node.on("click", this.onClick.bind(this));
}
onClick() {
const callbacks = {
onRewarded: this.onReward.bind(this),
};
ysdk.adv.showRewardedVideo({ callbacks });
}
onReward() {
// 奖励用户。
}
}
在 Yandex 平台上点击带有此组件的按钮时,您将看到广告。为了简化测试,请参阅 测试 部分。
已复制