Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using System;
  5. [System.Serializable]
  6. public class UpDataShop
  7. {
  8.     public Text upName;
  9.     public Text upPrise;
  10.     public int Prise;
  11.     public int upModule;
  12.     public int prisePlus;
  13.     public Button But;
  14. }
  15. public class GameScript : MonoBehaviour {
  16.     [Header("Стандарт")]
  17.     int score = 0;
  18.     int module = 0;
  19.     int workerCount = 0;
  20.     int workersLvl = 1;
  21.     public Text scoreText;
  22.     [Header("Магазин"), Space(10)]
  23.     public UpDataShop[] Shop;
  24.     public GameObject shopPanel;
  25.  
  26.     private Save SaveGame = new Save();
  27.     void Awake()
  28.     {
  29.         if (PlayerPrefs.HasKey("Saves"))
  30.         {
  31.           SaveGame = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("Saves"));
  32.              score = SaveGame.scores;
  33.              module = SaveGame.modules;
  34.              workerCount =  SaveGame.workerCounts;
  35.              workersLvl = SaveGame.workersLvls;
  36.             for (int i = 0; i < Shop.Length; i++)
  37.             {
  38.             Shop[i].Prise = SaveGame.Prises[i];
  39.              Shop[i].upModule = SaveGame.upModules[i];
  40.                Shop[i].prisePlus = SaveGame.prisePluss[i];
  41.             }
  42.             DateTime dt = new DateTime(SaveGame.Date[0]);
  43.             TimeSpan ts = DateTime.Now - dt;
  44.  
  45.         }
  46.        
  47.            
  48.  
  49.     }
  50.  
  51.     void OnApplicationQuit()
  52.         {
  53.         SaveGame.Prises = new int[Shop.Length];
  54.         SaveGame.upModules = new int[Shop.Length];
  55.         SaveGame.prisePluss = new int[Shop.Length];
  56.         for (int i = 0; i < Shop.Length; i++)
  57.         {
  58.             SaveGame.Prises[i] = Shop[i].Prise;
  59.             SaveGame.upModules[i] = Shop[i].upModule;
  60.             SaveGame.prisePluss[i] = Shop[i].prisePlus;
  61.         }
  62.         SaveGame.scores = score;
  63.         SaveGame.modules = module;
  64.         SaveGame.workerCounts = workerCount;
  65.         SaveGame.workersLvls = workersLvl;
  66.         PlayerPrefs.SetString("Saves", JsonUtility.ToJson(SaveGame));
  67.  
  68.  
  69.         SaveGame.Date[0] = DateTime.Now.Second;
  70.         }
  71. }
  72. [System.Serializable]
  73. public class Save
  74. {
  75.     public int scores;
  76.     public int modules;
  77.     public int workerCounts;
  78.     public int workersLvls;
  79.  
  80.     public int[] Prises;
  81.     public int[] upModules;
  82.     public int[] prisePluss;
  83.  
  84.     public int[] Date;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement