Yandex Games SDK API
플러그인을 설치한 후, ysdk
객체를 찾을 수 있습니다. 이는 SDK Yandex 게임의 동일한 이름의 객체의 타입핑된 등가물입니다. 이를 통해 SDK의 모든 메서드에 접근할 수 있습니다.
다음은 SDK Yandex 게임의 환경 변수를 사용하는 예제입니다.
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 플랫폼에서 클릭하면 광고가 표시됩니다. 간단한 테스트를 위해 테스트 항목을 참조하세요.
Copied