using System.Collections; using System.Collections.Generic; using UnityEngine; public static class DataManager{ public const string API_Endpoint="http://109.237.27.65/stickpoge/api/"; public static string Username{get; private set;} public static bool LoggedIn {get{return PlayerPrefs.HasKey("username");}} public static int selectedPogeLevel{get;private set;} public static List pogePurchased {get { string p =PlayerPrefs.GetString("poge_purchased"); List l = new List(); if(p.Contains("silver")){ l.Add(0); } if(p.Contains("gold")){ l.Add(1); } if(p.Contains("diamond")){ l.Add(2); } return l; } } public static void PurchasePoge(string index){ PlayerPrefs.SetString("poge_purchased",PlayerPrefs.GetString("poge_purchased") + index); PlayerPrefs.Save(); } public static int total{get{ return (int)PlayerPrefs.GetFloat("Money"); } set{ PlayerPrefs.SetFloat("Money", value); PlayerPrefs.Save(); } } public static void LoadFromSave(){ Username = PlayerPrefs.GetString("username"); LoadSaveData(); } public static bool OnLoginDone(string username,string response){ int uid = -1; try{ uid = int.Parse(response); }catch{ Debug.LogError("Error in registering : " + response); } if(uid >=0){ Username = username +"#"+ uid; PlayerPrefs.SetString("username", Username); PlayerPrefs.Save(); LoadSaveData(); return true; } return false; } public static void LoadSaveData(){ if(PlayerPrefs.HasKey("poge")){ selectedPogeLevel = PlayerPrefs.GetInt("poge"); }else{ PlayerPrefs.SetInt("poge",0); PlayerPrefs.Save(); } if(PlayerPrefs.HasKey("poge_purchased")){ } } public static void SelectPoge(int i){ PlayerPrefs.SetInt("poge",i); PlayerPrefs.Save(); selectedPogeLevel = i; } }