2themoon/Assets/Scripts/DataManager.cs
2023-01-25 03:59:38 +05:30

52 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class DataManager{
public const string API_Endpoint="https://pogechart.io/api/";
private static string username;
public static string Username{get{
if(PlayerPrefs.HasKey("username")){
return PlayerPrefs.GetString("username");
}else{
return "";
}
}
set{
PlayerPrefs.SetString("username",value);
PlayerPrefs.Save();
}}
public static bool LoggedIn {get{return PlayerPrefs.HasKey("username");}}
public static int best{
get{
return (int)PlayerPrefs.GetFloat("best");
}
set{
PlayerPrefs.SetFloat("best", value);
PlayerPrefs.Save();
}
}
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();
return true;
}
return false;
}
}