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