PJ/Assets/scripts/Settings.cs

178 lines
4.5 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using System.Linq;
public class Settings : MonoBehaviour
{
public Text DieCount;
public Text WinCount;
public Text MaxMoney;
public Text EnDes;
public UnityEngine.UI.Toggle VBT;
public UnityEngine.UI.Slider MV;
public string EC;
public List<string> Codes;
public Achievements achievements;
List<int> UC;
public Sprite[] Icon;
public UnityEngine.UI.Toggle[] SetToggle;
[SerializeField] UnityEngine.UI.Toggle[] Toggles;
public void ButonSize(int size)
{
PlayerPrefs.SetInt("ButtonSize", size);
}
void Start()
{
Toggles[0].isOn = Screen.fullScreen;
bool[] TT;
if (PlayerPrefs.HasKey("TT"))
{
TT = Currencies.Load("TT").ToArray().Select(n => n != 0).ToArray();
}
else {TT = Enumerable.Repeat(true, SetToggle.Length).ToArray(); }
for(int i = 0; i < SetToggle.Length; i++)
{
SetToggle[i].isOn = TT[i];
}
}
//void LoadA()
//{
// if (PlayerPrefs.HasKey("HaveA"))
//{
// string json = PlayerPrefs.GetString("HaveA");
//UC = JsonUtility.FromJson<Serialization<int>>(json).List;
//}
//}
//void SaveA()
//{
// string json = JsonUtility.ToJson(new Serialization<int>(UC));
// PlayerPrefs.SetString("HaveA", json);
// PlayerPrefs.Save();
//}
//[System.Serializable]
//private class Serialization<T>
//{
// public List<T> List;
//public Serialization(List<T> list)
//{
// this.List = list;
//}
//public List<T> ToList()
//{
// return List;
//}
//}
private void OnEnable()
{
int DieCountInt = PlayerPrefs.GetInt("CountDie");
DieCount.text = DieCountInt.ToString();
int WintCountInt = PlayerPrefs.GetInt("CountWin");
WinCount.text = WintCountInt.ToString();
int MaxMoneyInt = PlayerPrefs.GetInt("MaxMoney");
MaxMoney.text = MaxMoneyInt.ToString();
int EnemiesKilled = PlayerPrefs.GetInt("EnemiesKilled");
EnDes.text = EnemiesKilled.ToString();
MV.value = PlayerPrefs.GetFloat("MV");
print(PlayerPrefs.GetFloat("MV"));
int LC = PlayerPrefs.GetInt("LevelComplete");
if (!PlayerPrefs.HasKey("VB"))
{
PlayerPrefs.SetInt("VB", 1);
PlayerPrefs.Save();
}
if (!PlayerPrefs.HasKey("MV"))
{
PlayerPrefs.SetFloat("MV", 100);
PlayerPrefs.Save();
}
MV.value = PlayerPrefs.GetFloat("MV");
VBT.isOn = PlayerPrefs.GetInt("VB") == 1;
}
public void VB(Boolean VBn)
{
//<2F><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if (VBT.isOn)
{
PlayerPrefs.SetInt("VB", 1);
}
else
{
PlayerPrefs.SetInt("VB", 0);
}
PlayerPrefs.Save();
print("use");
}
public void MVS(float MVV)
{
if (!PlayerPrefs.HasKey("MV"))
{
PlayerPrefs.SetFloat("MV", 100);
}
else
{
PlayerPrefs.SetFloat("MV", MVV);
}
PlayerPrefs.Save();
print("Change");
}
public void Enter(string Code)
{
EC = Code;
}
public void FS()
{
Screen.fullScreen = Toggles[0].isOn;
}
public void TryCode()
{
if (Codes.Contains(EC) )//&& !UC.Contains(Codes.IndexOf(EC)))
{
switch (Codes.IndexOf(EC))
{
case 0:
achievements.GetAchievements(15);
break;
case 1:
int money = PlayerPrefs.GetInt("Moneys");
PlayerPrefs.SetInt("Moneys", money + 500);
break;
case 2:
int metall = PlayerPrefs.GetInt("Metall");
PlayerPrefs.SetInt("Metall", metall + 5);
break;
case 3:
break;
}
UC.Add(Codes.IndexOf(EC));
}
}
public void SetIcon(int i)
{
//ы
}
}