---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/hi/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/ko/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/ru/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/tr/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/vi/sdk/cocos/ysdk.md
  - https://yandex.com/dev/games/doc/zh/sdk/cocos/ysdk.md
  - href: vi/sdk/cocos/ysdk.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/vi/llms.txt

# Yandex Games SDK API

Sau khi cài đặt plugin, bạn sẽ tìm thấy đối tượng `ysdk`, là một phiên bản có kiểu của [đối tượng cùng tên từ SDK Yandex Games](https://yandex.com/dev/games/doc/vi/sdk/sdk-game-events.md). Nó cho phép bạn truy cập tất cả các phương thức của SDK.

Dưới đây là ví dụ về cách sử dụng [các biến môi trường](https://yandex.com/dev/games/doc/vi/sdk/sdk-environment.md) từ SDK Yandex Games.

```tsx
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) {}
}
```

## Thành phần để hiển thị quảng cáo

Ví dụ, tạo một thành phần cho nút bấm để khởi động video quảng cáo có thưởng.

Ngoài ra, xác định thêm phương thức `onReward()` và truyền nó làm callback cho phương thức `ysdk.adv.showRewardedVideo()`, để thực hiện logic sự kiện nhận thưởng.

```tsx
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() {
    // Thưởng người dùng.
  }
}
```

Khi nhấn vào nút với thành phần này trên nền tảng Yandex, bạn sẽ thấy quảng cáo. Để đơn giản hóa việc thử nghiệm, hãy tham khảo phần [Kiểm tra](https://yandex.com/dev/games/doc/vi/sdk/cocos/testing.md).


---


<!-- source: vi/_includes/button-git-cocos.md -->
<a href="https://github.com/yandex-games-plugins/cocos">
  <span class="button">Kho lưu trữ</span>
</a>
<!-- endsource: vi/_includes/button-git-cocos.md -->
