Yandex Games SDK API

Eklentiyi kurduktan sonra, Yandex Oyun SDK'sındaki aynı adlı nesnenin tip atanmış bir eşdeğeri olan ysdk nesnesini bulacaksınız. Bu nesne, SDK'nın tüm yöntemlerine erişmenizi sağlar.

İşte Yandex Oyun SDK'sından çevre değişkenlerini nasıl kullanacağınıza dair bir örnek.

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

Reklamı Gösterme Bileşeni

Örneğin, ödüllü video reklamını başlatacak bir düğme için bir bileşen oluşturalım.

Bunun yanı sıra, onReward() metodunu tanımlayıp, ödül alma olayının mantığını gerçekleştirmek için ysdk.adv.showRewardedVideo() metoduna callback olarak iletelim.

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() {
    // Kullanıcıyı ödüllendirin.
  }
}

Yandex platformunda bu bileşene sahip bir düğmeye bastığınızda, reklam göreceksiniz. Daha basit bir test için Test Etme bölümüne göz atın.


Depo
Önceki