Проблема с SDK Яндекс Игры

Публикую в первый раз игру на Яндекс Игры, написанную Unity. Хочу подключить к проекту оценку игры от игрока и рекламу с вознаграждением. Во время билда проекта на Unity вылазит похожая ошибка:

JS optimizer error:
Unexpected token: punc ()) (line: 1900, col: 19, pos: 79940)

Например, когда хочу подключить оценку игры, в качестве ошибки указывается следующий код:

================================

        return Module.SystemInfo.hasWebGL;
    }

  function _RateGame() {
      ysdk.feedback.canReview()
          .then(({ value, reason }) => {
                        ^
================================

Или когда хочу подключить рекламу с вознаграждением, то пишет так:

================================



  function _AddBonusExtern(value) {
      ysdk.adv.showRewardedVideo({
      callbacks: {
          onOpen: () => {
                   ^
================================

Понятно, что проблема в написании кода javascript. Копирую код с официального сайта Яндекс для разработчиков: https://yandex.ru/dev/games/doc/dg/sdk/sdk-adv.html. Подозреваю, что проблема описана в документации Unity https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html, где написано следующее:

The recommended approach is to execute all the build code in its own scope. This allows you to embed your content on an arbitrary page without causing conflicts with the embedding page code, and lets you embed more than one build on the same page.

If you have all your JavaScript code in the form of .jslib plugins inside your project, then this JavaScript code will run inside the same scope as the compiled build and your code should work the same way as in previous versions of Unity. For example, the following objects and functions should be directly visible from the JavaScript plugin code: Module, SendMessage, HEAP8, ccall etc..

However, if you are planning to call the internal JavaScript functions from the global scope of the embedding page, you must use the unityInstance variable in your WebGL Template index.html. Do this after the Unity engine instantiation succeeds, for example:

  var myGameInstance = null;
  script.onload = () => {
    createUnityInstance(canvas, config, (progress) => {...}).then((unityInstance) => {
      myGameInstance = unityInstance;
      …
Then you can send a message to the build using myGameInstance.SendMessage(), or access the build Module object using myGameInstance.Module.

Я полный ноль в javascript, может мне кто-нибудь подсказать как мне правильно переписать код с оценкой игры и с рекламой с вознаграждением на Яндекс SDK?

Оценка игры, тут ошибка в написании кода с сайта:

ysdk.feedback.canReview()
        .then(({ value, reason }) => {
            if (value) {
                ysdk.feedback.requestReview()
                    .then(({ feedbackSent }) => {
                        console.log(feedbackSent);
                    })
            } else {
                console.log(reason)
            }
        })

И в рекламе с вознаграждением:

ysdk.adv.showRewardedVideo({
    callbacks: {
        onOpen: () => {
          console.log('Video ad open.');
        },
        onRewarded: () => {
          console.log('Rewarded!');
        },
        onClose: () => {
          console.log('Video ad closed.');
        }, 
        onError: (e) => {
          console.log('Error while open video ad:', e);
        }
    }
})

Эти два куска кода во время билда проекта на Unity вызывают ошибки.


Ответы (0 шт):