Store WIP
This commit is contained in:
86
Assets/Scripts/DataManager.cs
Normal file
86
Assets/Scripts/DataManager.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class DataManager{
|
||||
public const string API_Endpoint="http://vmi1005083.contaboserver.net/pogebird/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<int> pogePurchased {get {
|
||||
string p =PlayerPrefs.GetString("poge_purchased");
|
||||
List<int> l = new List<int>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user