public void Save() { sv.reward = reward; sv.itemCaseId = rewardItem[0]; sv.itemItemId = rewardItem[1]; //sv.bots = new string[bot.Length]; //sv.it = new string[it.Length]; sv.start[0] = start.Year; sv.start[1] = start.Month; sv.start[2] = start.Day; sv.start[3] = start.Hour; sv.start[4] = start.Minute; sv.start[5] = start.Second; sv.arrIcon = JsonHelper.ToJson <int>(arrIcon); sv.lastWinner = lastWinner; sv.isFinished = isFinished; sv.botCount = botCount; sv.tickets = tickets; sv.bots = JsonHelper.ToJson <BOT>(bot); LotteryItemS[] it2 = new LotteryItemS[it.Length]; for (int i = 0; i < it.Length; i++) { it2[i] = new LotteryItemS(); it2[i].id = it[i].id; it2[i].isBusy = it[i].isBusy; it2[i].NameOfBusy = it[i].NameOfBusy; it2[i].icon = it[i].icon; } sv.it = JsonHelper.ToJson <LotteryItemS>(it2); string json = JsonUtility.ToJson(sv); string name = id.ToString() + "lottery"; PlayerPrefs.SetString(name, JsonUtility.ToJson(sv)); }
public void LoadLottery() { string name = id.ToString() + "lottery"; if (PlayerPrefs.HasKey(name)) { sv = JsonUtility.FromJson <SaveLottery>(PlayerPrefs.GetString(name)); start = new System.DateTime(sv.start[0], sv.start[1], sv.start[2], sv.start[3], sv.start[4], sv.start[5]); lastWinner = sv.lastWinner; if ((DateTime.Now - start).TotalMinutes > (lotteryTime)) { reward = sv.reward; tickets = sv.tickets; arrIcon = JsonHelper.FromJson <int>(sv.arrIcon); rewardItem[0] = sv.itemCaseId; rewardItem[1] = sv.itemItemId; botCount = sv.botCount; //sv.bots = new string[bot.Length]; //sv.it = new string[it.Length]; bot = JsonHelper.FromJson <BOT>(sv.bots); for (int i = 0; i < bot.Length; i++) { bot[i].icon = g.botIcon[arrIcon[i]]; bot[i].color = g.color[i + 3]; } LotteryItemS[] it2 = new LotteryItemS[it.Length]; it2 = JsonHelper.FromJson <LotteryItemS>(sv.it); for (int i = 0; i < it.Length; i++) { it[i].id = it2[i].id; it[i].isBusy = it2[i].isBusy; it[i].NameOfBusy = it2[i].NameOfBusy; if (it[i].isBusy) { for (int j = 0; j < bot.Length; j++) { if (bot[j].name == it2[i].NameOfBusy) { //it[i].icon.sprite = bot[j].icon; it[i].transform.GetChild(0).gameObject.SetActive(false); it[i].transform.GetChild(1).gameObject.SetActive(true); it[i].transform.GetChild(1).GetComponent <Image>().sprite = bot[j].icon; it[i].GetComponent <Image>().color = bot[j].color; } } if (g.deviceID == it2[i].NameOfBusy) { it[i].GetComponent <Image>().color = g.color[1]; } } } isFinished = sv.isFinished; //showWinner(); winner.transform.GetChild(0).GetComponent <Text>().text = lastWinner; winner.SetActive(true); timer.transform.parent.gameObject.GetComponent <Button>().interactable = false; block.SetActive(true); if ((DateTime.Now - start).TotalMinutes > (lotteryTime + waitTime)) { double delta = (DateTime.Now - start).TotalMinutes - (lotteryTime + waitTime); timer.transform.parent.gameObject.GetComponent <Button>().interactable = true; block.SetActive(false); startLottery(); int seconds = UnityEngine.Random.Range(0, (int)(delta * 60)); start.Subtract(new DateTime(0, 0, 0, seconds / 3600, seconds / 60, seconds % 60)); buyTickets(); } } else { reward = sv.reward; tickets = sv.tickets; arrIcon = JsonHelper.FromJson <int>(sv.arrIcon); rewardItem[0] = sv.itemCaseId; rewardItem[1] = sv.itemItemId; botCount = sv.botCount; //sv.bots = new string[bot.Length]; //sv.it = new string[it.Length]; isFinished = sv.isFinished; bot = JsonHelper.FromJson <BOT>(sv.bots); for (int i = 0; i < bot.Length; i++) { bot[i].icon = g.botIcon[arrIcon[i]]; bot[i].color = g.color[i + 3]; } LotteryItemS[] it2 = new LotteryItemS[it.Length]; it2 = JsonHelper.FromJson <LotteryItemS>(sv.it); for (int i = 0; i < it.Length; i++) { it[i].id = it2[i].id; it[i].isBusy = it2[i].isBusy; it[i].NameOfBusy = it2[i].NameOfBusy; if (it[i].isBusy) { for (int j = 0; j < bot.Length; j++) { if (bot[j].name == it2[i].NameOfBusy) { //it[i].icon.sprite = bot[j].icon; it[i].transform.GetChild(0).gameObject.SetActive(false); it[i].transform.GetChild(1).gameObject.SetActive(true); it[i].transform.GetChild(1).GetComponent <Image>().sprite = bot[j].icon; it[i].GetComponent <Image>().color = bot[j].color; } } if (g.deviceID == it2[i].NameOfBusy) { it[i].GetComponent <Image>().color = g.color[1]; } } } tickets = countTickets(); buyTickets(); for (int i = 0; i < botCount; i++) { StartCoroutine(BotActive(bot[i])); } winner.SetActive(false); } } else { startLottery(); } updateCover(); }