123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- <!DOCTYPE html>
- <html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>Unity WebGL Player | {{{ PRODUCT_NAME }}}</title>
- <link rel="shortcut icon" href="TemplateData/favicon.ico">
- <link rel="stylesheet" href="TemplateData/style.css">
- <script src="https://yandex.ru/games/sdk/v2"></script>
- <!-- Yandex.Metrika counter -->
- <script type="text/javascript">
- (function (m, e, t, r, i, k, a) {
- m[i] = m[i] || function () { (m[i].a = m[i].a || []).push(arguments) };
- m[i].l = 1 * new Date();
- for (var j = 0; j < document.scripts.length; j++) { if (document.scripts[j].src === r) { return; } }
- k = e.createElement(t), a = e.getElementsByTagName(t)[0], k.async = 1, k.src = r, a.parentNode.insertBefore(k, a)
- })
- (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
- ym( {{{ parseInt(APP_METRICA) }}} , "init", {
- clickmap: true,
- trackLinks: true,
- accurateTrackBounce: true,
- webvisor: true
- });
- </script>
- <noscript><div><img src="https://mc.yandex.ru/watch/{{{parseInt(APP_METRICA)}}}" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
- <!-- /Yandex.Metrika counter -->
- </head>
- <body bgcolor="#2DC8FF">
- <div align="center">
- <div id="unity-container" class="unity-desktop">
- <canvas id="unity-canvas" width={{{ WIDTH }}} height={{{ HEIGHT }}}></canvas>
- <div id="unity-loading-bar">
- <div id="unity-logo"></div>
- <div id="unity-progress-bar-empty">
- <div id="unity-progress-bar-full"></div>
- </div>
- </div>
- </div>
- </div>
- <div id="bottomAd"></div>
- <!--UnityBuild-->
- <script>
- var buildUrl = "Build";
- var loaderUrl = buildUrl + "/{{{ LOADER_FILENAME }}}";
- var config = {
- dataUrl: buildUrl + "/{{{ DATA_FILENAME }}}",
- frameworkUrl: buildUrl + "/{{{ FRAMEWORK_FILENAME }}}",
- codeUrl: buildUrl + "/{{{ CODE_FILENAME }}}",
- #if MEMORY_FILENAME
- memoryUrl: buildUrl + "/{{{ MEMORY_FILENAME }}}",
- #endif
- #if SYMBOLS_FILENAME
- symbolsUrl: buildUrl + "/{{{ SYMBOLS_FILENAME }}}",
- #endif
- streamingAssetsUrl: "StreamingAssets",
- companyName: "{{{ COMPANY_NAME }}}",
- productName: "{{{ PRODUCT_NAME }}}",
- productVersion: "{{{ PRODUCT_VERSION }}}",
- };
- var container = document.querySelector("#unity-container");
- var canvas = document.querySelector("#unity-canvas");
- var loadingBar = document.querySelector("#unity-loading-bar");
- var progressBarFull = document.querySelector("#unity-progress-bar-full");
- var fullscreenButton = document.querySelector("#unity-fullscreen-button");
- var mobileWarning = document.querySelector("#unity-mobile-warning");
- // By default Unity keeps WebGL canvas render target size matched with
- // the DOM size of the canvas element (scaled by window.devicePixelRatio)
- // Set this to false if you want to decouple this synchronization from
- // happening inside the engine, and you would instead like to size up
- // the canvas DOM size and WebGL render target sizes yourself.
- // config.matchWebGLToCanvasSize = false;
- Resize();
- window.addEventListener(`resize`, event => {
- Resize();
- }, false);
- function Resize() {
- var size = document.documentElement.clientHeight + 'px';
- console.log(size);
- container.style.height = size;
- }
- if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
- container.className = "unity-mobile";
- // Avoid draining fillrate performance on mobile devices,
- // and default/override low DPI mode on mobile browsers.
- //config.devicePixelRatio = 1;
- } else {
- canvas.style.width = "100%";
- canvas.style.height = "100%";
- }
- #if BACKGROUND_FILENAME
- canvas.style.background = "url('" + buildUrl + "/{{{ BACKGROUND_FILENAME.replace(/'/g, '%27') }}}') center / cover";
- #endif
- loadingBar.style.display = "block";
- var script = document.createElement("script");
- script.src = loaderUrl;
- script.onload = () => {
- createUnityInstance(canvas, config, (progress) => {
- progressBarFull.style.width = 100 * progress + "%";
- }).then((unityInstance) => {
- window.unityInstance = unityInstance;
- loadingBar.style.display = "none";
- }).catch((message) => {
- alert(message);
- });
- };
- document.body.appendChild(script);
- </script>
- <!-- Yandex Games SDK -->
- <script type="text/javascript">
- var player;
- var sdk;
- var payments = null;
- var playerData = null;
- var playerStats = null;
- YaGames.init({
- adv: {
- onAdvClose: wasShown => {
- console.info('adv closed!');
- }
- }
- })
- .then(ysdk => {
- sdk = ysdk;
- sdk.adv.showFullscreenAdv({ callbacks: {} });
- });
- function auth() {
- sdk.auth.openAuthDialog().then(() => {
- // Игрок успешно авторизован, теперь объект Player будет инициализирован.
- initPlayer();
- console.log('auth ok');
- }).catch(() => {
- // Игрок не авторизован.
- console.log('auth failed');
- });
- }
- function initPlayer() {
- return sdk.getPlayer({ scopes: false }).then(_player => {
- player = _player;
- return player;
- }).catch(err => {
- // Если игрок не авторизован, выбрасывает исключение USER_NOT_AUTHORIZED.
- });
- }
- function setScore(key, value) {
- playerStats[key] = value;
- console.log('Set score' + key + value);
- player.setStats(playerStats).then(() => { console.log('setted data!'); }).catch(err => { console.log('not setted' + err) });
- }
- function setData(key, value) {
- playerData[key] = value;
- console.log('Set Data' + key + value);
- player.setData(playerData, true).then(() => { console.log('setted data!'); }).catch(err => { console.log('not setted' + err) });
- }
- function initPlayerData() {
- initPlayer().then(_player => {
- if (_player.getMode() != 'lite') {
- var sendData = {};
- player.getData().then(datas => {
- var i = 0;
- playerData = datas;
- var adata = Array();
- for (var key in datas) {
- adata[i] = { key: key, value: datas[key] };
- i++;
- }
- sendData.data = adata;
- player.getStats().then(stats => {
- i = 0;
- playerStats = stats;
- var astats = Array();
- for (var keya in stats) {
- astats[i] = { key: keya, value: stats[keya] };
- i++;
- }
- sendData.score = astats;
- console.log('Geted data' + JSON.stringify(sendData));
- window.unityInstance.SendMessage('YandexSDK', 'OnGetData', JSON.stringify(sendData));
- }).catch(err => {
- console.log('No get data score' + err);
- window.unityInstance.SendMessage('YandexSDK', 'OnGetData', JSON.stringify(sendData));
- });
- }).catch(err => {
- console.log('NoNoAutorized' + err);
- window.unityInstance.SendMessage('YandexSDK', 'NoAutorized');
- });
- }
- else {
- console.log('NoNoAutorized');
- window.unityInstance.SendMessage('YandexSDK', 'NoAutorized');
- }
- }).catch(err => {
- console.log('NoNoAutorized' + err);
- window.unityInstance.SendMessage('YandexSDK', 'NoAutorized');
- // Ошибка при инициализации объекта Player.
- });
- }
- function getUserData() {
- if (initPlayer) {
- var data = { "id": player.getID(), "name": player.getName(), "avatarUrlSmall": player.getPhoto('small'), "avatarUrlMedium": player.getPhoto('medium'), "avatarUrlLarge": player.getPhoto('large') };
- window.unityInstance.SendMessage('YandexSDK', 'StoreUserData', JSON.stringify(data));
- }
- }
- function showFullscrenAd() {
- sdk.adv.showFullscreenAdv({
- callbacks: {
- onClose: function (wasShown) {
- window.unityInstance.SendMessage('YandexSDK', 'OnInterstitialShown');
- },
- onError: function (error) {
- window.unityInstance.SendMessage('YandexSDK', 'OnInterstitialError', JSON.stringify(error));
- }
- }
- })
- }
- function showRewardedAd(id) {
- sdk.adv.showRewardedVideo({
- callbacks: {
- onOpen: () => {
- window.unityInstance.SendMessage('YandexSDK', 'OnRewardedOpen', id);
- console.log('Video ad open. Id: ' + id);
- },
- onRewarded: () => {
- window.unityInstance.SendMessage('YandexSDK', 'OnRewarded', id);
- console.log('Rewarded! Id: ' + id);
- },
- onClose: () => {
- window.unityInstance.SendMessage('YandexSDK', 'OnRewardedClose', id);
- console.log('Video ad closed. Id: ' + id);
- },
- onError: (error )=> {
- var data = { "id": id, "error": error };
- window.unityInstance.SendMessage('YandexSDK', 'OnRewardedError', JSON.stringify(data));
- console.log('Error while open video ad:', error);
- }
- }
- })
- }
- function initPayments() {
- sdk.getPayments().then(_payments => {
- // Покупки доступны.
- payments = _payments;
- console.log('Purchases initialized!');
- window.unityInstance.SendMessage('YandexSDK', 'OnPurchaseInitialize');
- }).catch(err => {
- console.log(err);
- window.unityInstance.SendMessage('YandexSDK', 'OnPurchaseInitializeFailed', err);
- });
- }
- function buy(id) {
- payments.purchase(id).then(purchase => {
- // Покупка успешно совершена!
- var json = JSON.stringify(purchase);
- console.log(json);
- window.unityInstance.SendMessage('YandexSDK', 'OnPurchaseSuccess', json);
- }).catch(err => {
- // Покупка не удалась: в консоли разработчика не добавлен товар с таким id,
- // пользователь не авторизовался, передумал и закрыл окно оплаты,
- // истекло отведенное на покупку время, не хватило денег и т. д.
- console.log(err);
- window.unityInstance.SendMessage('YandexSDK', 'OnPurchaseFailed', err);
- })
- }
- window.onunload = function (e) {
- console.log("Calling OnClose from Browser!");
- window.unityInstance.SendMessage("YandexSDK", "OnClose");
- //var dialogText = "You game has been saved! Would you like to continue unloading the page?";
- // e.returnValue = dialogText;
- // return dialogText;
- };
- function ShowReview() {
- sdk.feedback.canReview()
- .then(({ value, reason }) => {
- if (value) {
- sdk.feedback.requestReview()
- .then(({ feedbackSent }) => {
- var data = { "CanReview": value, "Reason": "Success", "FeedbackSent": feedbackSent };
- SendCallback('OnReview', data);
- })
- } else {
- var data = { "CanReview": value, "Reason": reason, "FeedbackSent": false };
- SendCallback('OnReview', data);
- }
- });
- }
- function SendCallback(target, data) {
- window.unityInstance.SendMessage('YandexSDK', target, JSON.stringify(data));
- }
- </script>
- <script>
- function sendEvent(key, value) {
- ym({{{ parseInt(APP_METRICA) }}}, key, value);
- console.log('метрика отправлена');
- }
- </script>
- </body>
- </html>
|