icon
Download from Unity Asset Store.
More about PluginYG2 — benefits and other information.
Telegram channel — updates, useful and important information.
Telegram chat — ask questions or find ready answers.

Below are video materials. It is recommended to refer to the documentation as it contains more detailed and always up-to-date information. The YouTube player may not display due to restrictions.

Getting Started

• Supported Unity versions: 2021.3.18+, 2022.3+, 2023.2+ including Unity 6. • Do not move plugin files within the project! • Before importing the plugin, ensure there are no compilation errors in the project!

Download PluginYG2 from Unity Asset Store and import it. You're greeted by a welcome window. It duplicates buttons from the context menu:
icon
Open the plugin settings – this is the fundamental window. Note that many fields have tooltips!
icon
It's recommended to familiarize yourself with all parameters in the Basic Settings section.

If you opted out of setting optimal settings for the standard Yandex Games platform during plugin import
In Basic Settings → Platform, you need to select the platform. For porting to WebGL, choose the appropriate template in Player Settings → Resolution and Presentation → WebGL Template. Instead of choosing a template manually, you can tick the Auto Apply Settings box under the Platform field. In this case, the template will be applied automatically, along with other settings offered by the plugin. You can disable the automatic project settings choice, which can be adjusted in the platform properties (Platform field).
Local host and hosting on your server
Testing the game on a localhost with Build And Run works. However, SDK initialization (retrieving platform data) will be ignored. When hosting the game on your server for Yandex Games, enable the Own Host option located in the platform settings (Platform field in the Basic Settings section). This will add the appropriate connection string to index.html. Note that your host might not support certain project settings. For instance, Brotli compression. If you agreed to set optimal settings during the plugin import, PluginYG2 will alter some project parameters accordingly. To control this process, go to the platform settings and make changes as per your preferences. For local testing of the game with SDK connection, modify the IsLocalHost function in Index.html as needed. You can adjust this file in the WebGLTemplates/YandexGames folder.

Modular System

All plugin functions are divided into separate modules. You can read more about the advantages of this approach and the plugin overall on the home page of the site.
Open the version control tool. Let's download and import the InterstitialAdv module for example:
icon

When the module is imported:

  1. It goes into the Modules folder. Any folder within the Modules directory will be identified as a plugin module.
  2. If the module has global settings, they will appear in the plugin settings.
  3. Each module will have its define (preprocessor directive link). You can use it in your code.

icon
Module defines are suffixed with _yg. Platform modules are labeled with Platform_yg. In case of problems, check if all defines are correctly set and adjust them. You can also try updating module data in the project by deleting the PluginYourGames/Editor/ModulesListYG2.txt file.

If you discover clear issues with the plugin, please report them in the chat Plugin Your Games. There you can find discussions with ready solutions and interact about game development topics. You are encouraged to follow updates and other important information in the telegram channel PluginYG2 on call.

Working with Code

PluginYG is in the YG namespace, import it at the beginning of your script: using YG;
Almost all functions are located in the YG2 class. For example, we can find the method for calling ads in this class: YG2.InterstitialAdvShow();
For how to work with ads and other modules, see the relevant sections.

Other objects contained in PluginYG2 without separate modules:

Main
platform — example of values the platform field may contain: YandexGames, CrazyGames. onGetSDKData — event indicating that the platform SDK is initialized (may be useful when using the Sync Init option). isSDKEnabled — field is true when the SDK is initialized. isFirstGameSession — field indicating whether it is the first game session currently. If first, it will equal true for the entire current game session. But note! This field is not stored in cloud storage.
Gameplay Markup
GameReadyAPI — execute the method when the game is loaded, and the user can start the gameplay. It should be used if the Auto GRA option is disabled in Basic Settings. More about Game Ready. By default, the GameReadyAPI method is executed automatically after the game loads because the AutoGRA option in plugin settings is enabled. If your game has additional delays after loading, disable AutoGRA and call the method manually. GameplayStart — use this method to signal the platform that gameplay has started. GameplayStop — use this method to signal the platform that gameplay has stopped. When opening or closing ads or during other pauses, GameplayStart and GameplayStop methods are executed. But only if the GameplayStart method was previously called in the game. That is, if markup methods are used in the code, they will be automatically executed during ad views and other similar pauses. After the pause, the gameplay state will be restored to how it was before. Gameplay markup methods are optional, but their implementation is encouraged. isGameplaying — field indicating the activity of gameplay. YG2.optionalPlatform.HappyTime — happy time.

Demo Materials

icon
All demo materials are in the Example folders. Open the main demo scene: PluginYourGames/Example/Scenes/ExampleYG2. The main scene displays demo objects of all modules. If a module has a demo object scene, it will be displayed. But first, you need to click on the «Add Demo Scenes» button. Then module scenes will be added to Build Settings. Before releasing the game or finishing exploring the plugin, you can delete demo scenes from Build Settings by clicking the «Delete» button or perform removal of all demo materials from the project.

When deleting a module, the module scene will remain in Build Settings and will be undefined. Before deleting a module, it's advisable to click the «Delete» button in the demo scenes section.

EventsYG2 Component

icon

  • The EventsYG2 component stores most of the plugin's available methods. It allows, for example, to assign an ad call method to a button without code.
  • Using the EventsYG2 component, methods can be executed by event. To do this, click the «Add a New Event Type» button and select the event when any method should be executed. It works similarly to how you attach methods on a button click in the Button component.

Building

Now you know the basics of working with Plugin Your Games 2.0. With this knowledge, you can already assemble a working build. But there are still a couple of interesting points. Further about the build number and slightly about the correct project settings for WebGL.

Build Number

PluginYG2 stores build information in the PluginYourGames/Editor/BuildLogYG2.txt file. The build number is recorded there. For example, if you compile the project with PluginYG imported for the third time, the build number will be = 3.

The build number is displayed in the following places:

  • In the Unity Editor log after compiling the project
  • In the name of the zip archive of the build (suffix, for example, "b3")
  • In the browser console (in the first logs)
  • In the corner of the game screen during build testing (more about this below)

To reset build information, you can delete the BuildLogYG2.txt file.
You are allowed to delete the entire PluginYourGames/Editor folder to clear the plugin cache.

After compiling the project, if the Archiving Build checkbox in the plugin settings in the Basic Settings section is enabled, the game build will be automatically archived in the zip format, so you don't have to archive it manually each time. PluginYG does not delete the original build and does not place the archive inside it since the plugin does not violate any basic Unity logic when compiling a build. Therefore, the location of the created archive may seem strange. For convenience, within the folder you are going to build the build, create another folder with the same game name. And already compile the game build inside it:
icon

Project Settings

In the plugin settings, under the Template section, the Developer Build option will aid in testing the game build. When using this option, scripts displaying the build number in the game screen corner will enter the build. This allows you to instantly ensure that the build on the platform server is up to date.
Also, the display of such a panel signals that the build is not final, which helps remind you to change project settings for the final build.
icon
You can click on the build number panel to make it disappear.
Before the final build, you need to disable the Developer Build option. Also in Build Settings for WebGL, there's the Code Optimization option:
icon
For saving time when compiling a test build, set the Shorter Build Time parameter. For a release build, Runtime Speed with LTO. More details in official documentation.

Other major WebGL project settings will be applied automatically by the plugin if you allowed it, more above.
By default, the Color Space option is not applied. For WebGL, it's recommended to use the Gamma value. Games for IOS and some other devices only support the Gamma mode. This also applies to the Auto Graphic API option (recommended to enable).

Of the main recommendations, there's the DSP Buffer Size option for sound - an optimization setting for sound, which can also help eliminate issues with extraneous noise, if present. In the sound settings for WebGL itself, the Load Type needs to be set to Decompress On Load. Otherwise, on mobile devices, the drawer will display a Media Player, as if the sounds of your game are music playback.

Another beginner's problem is the font not displaying on the WebGL build. The standard Unity font cannot be used, replace it. If difficulties arise, read the "Frequently Asked Questions" section (not ready yet).

I suggest an excellent article about project setup and optimization.