---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
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: ko/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/ko/llms.txt

# Yandex Games SDK API

플러그인을 설치한 후, `ysdk` 객체를 찾을 수 있습니다. 이는 [SDK Yandex 게임의 동일한 이름의 객체](https://yandex.com/dev/games/doc/ko/sdk/sdk-game-events.md)의 타입핑된 등가물입니다. 이를 통해 SDK의 모든 메서드에 접근할 수 있습니다.

다음은 SDK Yandex 게임의 [환경 변수](https://yandex.com/dev/games/doc/ko/sdk/sdk-environment.md)를 사용하는 예제입니다.

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

## 광고 표시를 위한 컴포넌트

예를 들어, 보상형 동영상 광고를 시작하는 버튼 컴포넌트를 만들어보겠습니다.

추가적으로 `onReward()` 메서드를 정의하고 이 메서드를 `ysdk.adv.showRewardedVideo()` 메서드의 콜백으로 전달하여 보상 획득 이벤트의 로직을 구현합니다.

```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() {
    // 사용자에게 보상하기.
  }
}
```

이 컴포넌트가 있는 버튼을 Yandex 플랫폼에서 클릭하면 광고가 표시됩니다. 간단한 테스트를 위해 [테스트](https://yandex.com/dev/games/doc/ko/sdk/cocos/testing.md) 항목을 참조하세요.


---


<!-- source: ko/_includes/button-git-cocos.md -->
<a href="https://github.com/yandex-games-plugins/cocos">
  <span class="button">저장소</span>
</a>
<!-- endsource: ko/_includes/button-git-cocos.md -->
