PJ/Assets/scripts/DebugSettings.cs

224 lines
4.8 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Networking;
public class DebugSettings : MonoBehaviour
{
private int money;
private int moneys;
private GameObject player;
private GameObject Player;
private GameObject Blayer;
private Move move;
private int Id;
private int C;
private List<int> Ach;
private Sprite[] US;
private Sprite[] BS;
private List<int> Skins;
private SpriteRenderer SpR;
void LoadA()
{
if (PlayerPrefs.HasKey("HaveA"))
{
string json = PlayerPrefs.GetString("HaveA");
Ach = JsonUtility.FromJson<Serialization<int>>(json).List;
}
}
void SaveA()
{
string json = JsonUtility.ToJson(new Serialization<int>(Ach));
PlayerPrefs.SetString("HaveA", json);
PlayerPrefs.Save();
}
void LoadS()
{
if (PlayerPrefs.HasKey("HaveS"))
{
string json = PlayerPrefs.GetString("HaveS");
Skins = JsonUtility.FromJson<Serialization<int>>(json).List;
}
else
{
Debug.Log(Skins);
}
}
void SaveS()
{
string json = JsonUtility.ToJson(new Serialization<int>(Skins));
PlayerPrefs.SetString("HaveS", 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 Start()
{
SpR = GetComponent<SpriteRenderer>();
}
public void SetMoney(string Smoney)
{
money = int.Parse(Smoney);
}
public void AddMoney(string m)
{
moneys = PlayerPrefs.GetInt(m);
moneys += money;
PlayerPrefs.SetInt(m, moneys);
}
public void RemoveMoney(string m)
{
moneys = PlayerPrefs.GetInt(m);
moneys -= money;
PlayerPrefs.SetInt(m, moneys);
}
public void Lock()
{
DontDestroyOnLoad(gameObject);
}
public void FindPlayer()
{
player = GameObject.Find("player");
Player = GameObject.Find("Player");
Blayer = GameObject.Find("BodyPlayer");
move = player.GetComponent<Move>();
}
public void SetSpeed(string speed)
{
move.NormalSpeed = int.Parse(speed);
}
public void SetJump(string jump)
{
move.jumpforce = int.Parse(jump);
}
public void SetID(string ID)
{
Id = int.Parse(ID);
}
public void GiveAchievement()
{
LoadA();
Ach.Add(Id);
SaveA();
}
public void RemoveAchievement()
{
LoadA();
Ach.Remove(Id);
SaveA();
}
public void SetSkin()
{
BS = Blayer.GetComponent<SkinOnPlayer>().Skin;
US = player.GetComponentInChildren<SkinOnPlayer>().Skin;
Blayer.GetComponent<SpriteRenderer>().sprite = BS[Id];
Player.GetComponentInChildren<SpriteRenderer>().sprite = US[Id];
}
public void GiveSkin()
{
LoadS();
Skins.Add(Id);
SaveS();
}
public void RemoveSkin()
{
LoadS();
Skins.Remove(Id);
SaveS();
}
public void OpenScene()
{
SceneManager.LoadScene(Id);
}
public void SetC(string Count)
{
C = int.Parse(Count);
}
public void Verif()
{
PlayerPrefs.SetInt("LevelComplete", C);
}
public void VerifL()
{
PlayerPrefs.SetInt("CompleteLeftL", C);
}
public void VerifC()
{
PlayerPrefs.SetInt("CompleteCenterL", C);
}
public void VerifR()
{
PlayerPrefs.SetInt("CompleteRightL", C);
}
public void SetDamage()
{
PlayerPrefs.SetInt("SwordID", C);;
}
public void SetArm()
{
PlayerPrefs.SetInt("HeadID", C);;
}
public void SetHealt()
{
player.GetComponent<Move>().Lives = C;
}
public void UpdateDataBase()
{
StartCoroutine(UpdateDB());
}
private IEnumerator UpdateDB()
{
string baseUrl = "http://mc1.live-on.pro:64096/api/levels/";
WWWForm form = new WWWForm();
using (UnityWebRequest www = UnityWebRequest.Post(baseUrl + "updatedb", form))
{
yield return www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
Debug.Log("База данных обновлена" + www.downloadHandler.text);
}
}
}