Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- КОД КОТОРЫЙ ПИСАЛСЯ ДЛЯ ЯНДЕКС ПЛАГИНА
- =====================================================
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using YG;
- public class YandexPlugin : MonoBehaviour
- {
- public static YandexPlugin _instance;
- private void Awake()
- {
- if (_instance != null && _instance != this)
- {
- Destroy(gameObject);
- }
- else
- {
- _instance = this;
- }
- }
- private int passengersBestScore;
- private void Start()
- {
- LoadData();
- }
- public void AddNewLiderboard()
- {
- YandexGame.NewLeaderboardScores("Passengers", passengersBestScore);
- }
- public void ShowAd()
- {
- YandexGame.FullscreenShow();
- }
- public void LoadData()
- {
- passengersBestScore = YandexGame.savesData.passengersBestScoreDataSave;
- Debug.Log(passengersBestScore);
- }
- public void SaveData()
- {
- passengersBestScore = PlayerPrefs.GetInt("BestScore");
- YandexGame.savesData.passengersBestScoreDataSave = passengersBestScore;
- YandexGame.SaveProgress();
- AddNewLiderboard();
- }
- }
- =============================================================
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using TMPro;
- using UnityEngine;
- [System.Serializable]
- public class PlayerInfo
- {
- public int Money;
- }
- public class Progress : MonoBehaviour
- {
- public PlayerInfo PlayerInfo;
- [DllImport("__Internal")]
- private static extern void SaveExtern(string date);
- [DllImport("__Internal")]
- private static extern void LoadExtern();
- //[SerializeField] TextMeshProUGUI _playerInfoText;
- public static Progress Instance;
- private void Awake()
- {
- if (Instance == null)
- {
- transform.parent = null;
- DontDestroyOnLoad(gameObject);
- Instance = this;
- LoadExtern();
- } else
- {
- Destroy(gameObject);
- }
- }
- public void Save()
- {
- string jsonString = JsonUtility.ToJson(PlayerInfo);
- SaveExtern(jsonString);
- }
- public void SetPlayerInfo(string value)
- {
- PlayerInfo = JsonUtility.FromJson<PlayerInfo>(value);
- //_playerInfoText.text = PlayerInfo.Money.ToString();
- }
- }
- ======================================================================================
- my.jslib
- mergeInto(LibraryManager.library, {
- SaveExtern: function(date) {
- var dateString = UTF8ToString(date);
- var myobj = JSON.parse(dateString);
- player.setDate(myobj);
- },
- LoadExtern: function(){
- player.getDate().then(_date => {
- const myJSON = JSON.stringify(_date);
- myGameInstance.SendMessage("Progress", "SetPlayerInfo", myJSON);
- });
- },
- });
- =========================================================================
- index.html
- <!DOCTYPE html>
- <html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover, user-scalable=no"/>
- <!-- Спасибо за установку Advanced Templates -->
- <!-- Стой, не спускайся вниз. Залезь мне в сердце, а не в нижние строки код. (feat. Монеточка) -->
- <!-- Yandex Games SDK -->
- <script src="https://yandex.ru/games/sdk/v2"></script>
- <style>
- /* Убираем выделение по нажатию клавиш */
- canvas:focus {
- outline: none;
- }
- html, body {
- /* Убираем отступы */
- padding: 0;
- margin: 0;
- /* Отключаем скролл и лонгтап на IOS */
- overflow: hidden;
- -webkit-touch-callout:none;
- -webkit-user-select:none;
- -khtml-user-select:none;
- -moz-user-select:none;
- -ms-user-select:none;
- user-select:none;
- -webkit-tap-highlight-color:rgba(0,0,0,0);
- /* Ставим высоту на 100% */
- height: 100%;
- /* Центрируем, если привязана картинка или творим магию, чтобы можно было использовать градиент */
- background-position-x: 50%;
- background-repeat: no-repeat;
- background-size: cover;
- background-attachment: fixed;
- /* Скрываем скролл */
- -ms-overflow-style: none;
- scrollbar-width: none;
- scrollbar-height: none;
- }
- /* Канвас и загрузочный экран */
- #canvas {
- position: fixed;
- width: 100%;
- height: 100%;
- }
- .loading_bg {
- position: fixed;
- width: 100%;
- height: 100%;
- z-index: 1;
- /* Центрируем, если привязана картинка или творим магию, чтобы можно было использовать градиент */
- background-position-x: 50%;
- background-repeat: no-repeat;
- background-size: cover;
- background-attachment: fixed;
- }
- .loading {
- position: absolute;
- /*background-color:red;*/
- }
- .loading_bar {
- position: absolute;
- z-index: 6;
- transform: translate(-50%, -50%);
- }
- .loading_bar_fill {
- position: absolute;
- z-index: 6;
- width: 0%;
- height: 100%;
- top: 0%;
- bottom: 0%;
- left: 0%;
- }
- .loading_logo {
- position: absolute;
- transform: translate(-50%, -50%);
- z-index: 6;
- pointer-events: none;
- background-position: center;
- background-repeat: no-repeat;
- background-size: contain;
- background-attachment: scroll;
- }
- .console_helper {
- position: absolute;
- background-color: white;
- transform: translate(-50%, -50%);
- left: 50%;
- -webkit-box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
- -moz-box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
- box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
- overflow: hidden;
- display: none;
- }
- p {
- font-family: Arial, Helvetica, sans-serif;
- word-wrap: break-word;
- }
- .spinner {
- position: absolute;
- border: 5px solid #FFF;
- border-bottom-color: transparent;
- border-radius: 50%;
- box-shadow: 0px 0px 0px 7px rgba(34, 60, 80, 0.2);
- margin: auto;
- top: 70%;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 6;
- animation: spinner-spin 1.1s infinite linear;
- }
- @keyframes spinner-spin {
- 0% {
- transform: rotate(0deg);
- }
- 100% {
- transform: rotate(360deg);
- }
- }
- </style>
- <!-- Additional head modules -->
- </head>
- <body>
- <canvas id="canvas" class="canvas" tabindex="-1"></canvas>
- <div class="loading_bg">
- <div class="loading">
- <div class="console_helper">
- <p id="console_helper_text" style="position: absolute; overflow-x: hidden; overflow-y: scroll; scroll-behavior: smooth; scrollbar-width: none; margin: auto; top: 0; left: 0; bottom: 0; right: 0; overflow-width: hidden; text-align: left;"></p>
- </div>
- <div class="spinner"></div>
- <div class="loading_logo"></div>
- <div class="loading_bar">
- <div class="loading_bar_fill"></div>
- </div>
- </div>
- </div>
- <!-- Additional body modules -->
- <script>
- var player;
- function initPlayer() {
- return ysdk.getPlayer().then(_player => {
- player = _player;
- return player;
- });
- }
- initPlayer().then(_player => {
- if (_player.getMode() === 'lite') {
- // Игрок не авторизован.
- ysdk.auth.openAuthDialog().then(() => {
- // Игрок успешно авторизован
- initPlayer().catch(err => {
- // Ошибка при инициализации объекта Player.
- });
- }).catch(() => {
- // Игрок не авторизован.
- });
- }
- }).catch(err => {
- // Ошибка при инициализации объекта Player.
- });
- </script>
- //другой код
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement