Yandex Games SDK API

After installing the plugin, you will find the ysdk object, which is a typed equivalent of the same-named object from the Yandex Games SDK. It allows you to access all methods of the SDK.

Here is an example of how to use environment variables from the Yandex Games 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) {}
}

Component for Displaying Ads

For example, let's create a component for a button that launches a rewarded video ad.

Additionally, we will define a method onReward() and pass it as a callback for the method ysdk.adv.showRewardedVideo(), to implement the event logic for receiving a reward.

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() {
    // Reward the user.
  }
}

When you click on a button with this component on the Yandex platform, you will see an advertisement. For simplified testing, refer to the Testing section.


Repository