Advertisement
Guest User

Untitled

a guest
Apr 8th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.99 KB | None | 0 0
  1. КОД КОТОРЫЙ ПИСАЛСЯ ДЛЯ ЯНДЕКС ПЛАГИНА
  2. =====================================================
  3.  
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using YG;
  8.  
  9. public class YandexPlugin : MonoBehaviour
  10. {
  11. public static YandexPlugin _instance;
  12.  
  13. private void Awake()
  14. {
  15. if (_instance != null && _instance != this)
  16. {
  17. Destroy(gameObject);
  18. }
  19. else
  20. {
  21. _instance = this;
  22. }
  23. }
  24.  
  25.  
  26. private int passengersBestScore;
  27.  
  28. private void Start()
  29. {
  30. LoadData();
  31. }
  32.  
  33. public void AddNewLiderboard()
  34. {
  35. YandexGame.NewLeaderboardScores("Passengers", passengersBestScore);
  36. }
  37.  
  38. public void ShowAd()
  39. {
  40. YandexGame.FullscreenShow();
  41. }
  42.  
  43. public void LoadData()
  44. {
  45. passengersBestScore = YandexGame.savesData.passengersBestScoreDataSave;
  46. Debug.Log(passengersBestScore);
  47. }
  48.  
  49. public void SaveData()
  50. {
  51. passengersBestScore = PlayerPrefs.GetInt("BestScore");
  52. YandexGame.savesData.passengersBestScoreDataSave = passengersBestScore;
  53. YandexGame.SaveProgress();
  54. AddNewLiderboard();
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. =============================================================
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. using System.Collections;
  77. using System.Collections.Generic;
  78. using System.Runtime.InteropServices;
  79. using TMPro;
  80. using UnityEngine;
  81.  
  82. [System.Serializable]
  83. public class PlayerInfo
  84. {
  85. public int Money;
  86. }
  87.  
  88. public class Progress : MonoBehaviour
  89. {
  90. public PlayerInfo PlayerInfo;
  91.  
  92. [DllImport("__Internal")]
  93. private static extern void SaveExtern(string date);
  94.  
  95. [DllImport("__Internal")]
  96. private static extern void LoadExtern();
  97.  
  98. //[SerializeField] TextMeshProUGUI _playerInfoText;
  99.  
  100.  
  101. public static Progress Instance;
  102.  
  103. private void Awake()
  104. {
  105. if (Instance == null)
  106. {
  107. transform.parent = null;
  108. DontDestroyOnLoad(gameObject);
  109. Instance = this;
  110. LoadExtern();
  111. } else
  112. {
  113. Destroy(gameObject);
  114. }
  115. }
  116.  
  117. public void Save()
  118. {
  119. string jsonString = JsonUtility.ToJson(PlayerInfo);
  120. SaveExtern(jsonString);
  121. }
  122.  
  123. public void SetPlayerInfo(string value)
  124. {
  125. PlayerInfo = JsonUtility.FromJson<PlayerInfo>(value);
  126. //_playerInfoText.text = PlayerInfo.Money.ToString();
  127. }
  128. }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ======================================================================================
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. my.jslib
  149.  
  150. mergeInto(LibraryManager.library, {
  151. SaveExtern: function(date) {
  152. var dateString = UTF8ToString(date);
  153. var myobj = JSON.parse(dateString);
  154. player.setDate(myobj);
  155. },
  156.  
  157. LoadExtern: function(){
  158. player.getDate().then(_date => {
  159. const myJSON = JSON.stringify(_date);
  160. myGameInstance.SendMessage("Progress", "SetPlayerInfo", myJSON);
  161. });
  162. },
  163. });
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. =========================================================================
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. index.html
  194.  
  195. <!DOCTYPE html>
  196. <html lang="en-us">
  197. <head>
  198. <meta charset="utf-8">
  199. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  200. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover, user-scalable=no"/>
  201.  
  202.  
  203. <!-- Спасибо за установку Advanced Templates -->
  204. <!-- Стой, не спускайся вниз. Залезь мне в сердце, а не в нижние строки код. (feat. Монеточка) -->
  205.  
  206. <!-- Yandex Games SDK -->
  207. <script src="https://yandex.ru/games/sdk/v2"></script>
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214. <style>
  215. /* Убираем выделение по нажатию клавиш */
  216. canvas:focus {
  217. outline: none;
  218. }
  219. html, body {
  220. /* Убираем отступы */
  221. padding: 0;
  222. margin: 0;
  223.  
  224. /* Отключаем скролл и лонгтап на IOS */
  225. overflow: hidden;
  226. -webkit-touch-callout:none;
  227. -webkit-user-select:none;
  228. -khtml-user-select:none;
  229. -moz-user-select:none;
  230. -ms-user-select:none;
  231. user-select:none;
  232. -webkit-tap-highlight-color:rgba(0,0,0,0);
  233.  
  234. /* Ставим высоту на 100% */
  235. height: 100%;
  236.  
  237. /* Центрируем, если привязана картинка или творим магию, чтобы можно было использовать градиент */
  238. background-position-x: 50%;
  239. background-repeat: no-repeat;
  240. background-size: cover;
  241. background-attachment: fixed;
  242.  
  243. /* Скрываем скролл */
  244. -ms-overflow-style: none;
  245. scrollbar-width: none;
  246. scrollbar-height: none;
  247. }
  248. /* Канвас и загрузочный экран */
  249. #canvas {
  250. position: fixed;
  251. width: 100%;
  252. height: 100%;
  253. }
  254. .loading_bg {
  255. position: fixed;
  256. width: 100%;
  257. height: 100%;
  258. z-index: 1;
  259. /* Центрируем, если привязана картинка или творим магию, чтобы можно было использовать градиент */
  260. background-position-x: 50%;
  261. background-repeat: no-repeat;
  262. background-size: cover;
  263. background-attachment: fixed;
  264. }
  265. .loading {
  266. position: absolute;
  267. /*background-color:red;*/
  268. }
  269. .loading_bar {
  270. position: absolute;
  271. z-index: 6;
  272. transform: translate(-50%, -50%);
  273. }
  274. .loading_bar_fill {
  275. position: absolute;
  276. z-index: 6;
  277. width: 0%;
  278. height: 100%;
  279. top: 0%;
  280. bottom: 0%;
  281. left: 0%;
  282. }
  283. .loading_logo {
  284. position: absolute;
  285. transform: translate(-50%, -50%);
  286. z-index: 6;
  287. pointer-events: none;
  288. background-position: center;
  289. background-repeat: no-repeat;
  290. background-size: contain;
  291. background-attachment: scroll;
  292. }
  293. .console_helper {
  294. position: absolute;
  295. background-color: white;
  296. transform: translate(-50%, -50%);
  297. left: 50%;
  298. -webkit-box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
  299. -moz-box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
  300. box-shadow: 0px 0px 10px 5px rgba(34, 60, 80, 0.24);
  301. overflow: hidden;
  302. display: none;
  303. }
  304. p {
  305. font-family: Arial, Helvetica, sans-serif;
  306. word-wrap: break-word;
  307. }
  308. .spinner {
  309. position: absolute;
  310. border: 5px solid #FFF;
  311. border-bottom-color: transparent;
  312. border-radius: 50%;
  313. box-shadow: 0px 0px 0px 7px rgba(34, 60, 80, 0.2);
  314. margin: auto;
  315. top: 70%;
  316. left: 0;
  317. right: 0;
  318. bottom: 0;
  319. z-index: 6;
  320. animation: spinner-spin 1.1s infinite linear;
  321. }
  322. @keyframes spinner-spin {
  323. 0% {
  324. transform: rotate(0deg);
  325. }
  326. 100% {
  327. transform: rotate(360deg);
  328. }
  329. }
  330. </style>
  331.  
  332. <!-- Additional head modules -->
  333.  
  334. </head>
  335. <body>
  336. <canvas id="canvas" class="canvas" tabindex="-1"></canvas>
  337. <div class="loading_bg">
  338. <div class="loading">
  339. <div class="console_helper">
  340. <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>
  341. </div>
  342. <div class="spinner"></div>
  343. <div class="loading_logo"></div>
  344. <div class="loading_bar">
  345. <div class="loading_bar_fill"></div>
  346. </div>
  347. </div>
  348. </div>
  349. <!-- Additional body modules -->
  350.  
  351.  
  352. <script>
  353. var player;
  354.  
  355. function initPlayer() {
  356. return ysdk.getPlayer().then(_player => {
  357. player = _player;
  358.  
  359. return player;
  360. });
  361. }
  362.  
  363. initPlayer().then(_player => {
  364. if (_player.getMode() === 'lite') {
  365. // Игрок не авторизован.
  366. ysdk.auth.openAuthDialog().then(() => {
  367. // Игрок успешно авторизован
  368. initPlayer().catch(err => {
  369. // Ошибка при инициализации объекта Player.
  370. });
  371. }).catch(() => {
  372. // Игрок не авторизован.
  373. });
  374. }
  375. }).catch(err => {
  376. // Ошибка при инициализации объекта Player.
  377. });
  378. </script>
  379.  
  380.  
  381. //другой код
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement