Skip to content

Instantly share code, notes, and snippets.

@gluschenko
Last active August 29, 2015 14:09
Show Gist options
  • Save gluschenko/ecf1a90615b1de22e52b to your computer and use it in GitHub Desktop.
Save gluschenko/ecf1a90615b1de22e52b to your computer and use it in GitHub Desktop.
using UnityEngine;
using System;
using System.Collections.Generic;
public class WebData : MonoBehaviour
{
public bool isLoaded;
protected bool isUPP;
//Profile
public string ViewerId = "";
public string Name = "";
public string Avatar = "";
public string City = "";
public string Friends = "";
public int Money = 0;
public string Store = "";
public int HighScore = 0;
public string GlobalScores = "";
public void Start()
{
if (Application.loadedLevel == 0)Application.ExternalCall("CallWeb");
else LoadPlayerPrefs();
}
public void Update()
{
if(Application.loadedLevel == 0){ UpdatePlayerPrefs(); if(isLoaded)Application.LoadLevel(1); }
}
public void UpdatePlayerPrefs()
{
PlayerPrefs.SetString("ViewerId", ViewerId);
PlayerPrefs.SetString("Name", Name);
PlayerPrefs.SetString("Avatar", Avatar);
PlayerPrefs.SetString("City", City);
PlayerPrefs.SetString("Friends", Friends);
PlayerPrefs.SetInt("Money", Money);
PlayerPrefs.SetString("Store", Store);
PlayerPrefs.SetInt("HighScore", HighScore);
PlayerPrefs.SetString("GlobalScores", GlobalScores);
}
public void LoadPlayerPrefs()
{
ViewerId = PlayerPrefs.GetString("ViewerId", "");
Name = PlayerPrefs.GetString("Name", "");
Avatar = PlayerPrefs.GetString("Avatar", "");
City = PlayerPrefs.GetString("City", "");
Friends = PlayerPrefs.GetString("Friends", "");
Money = PlayerPrefs.GetInt("Money", 0);
Store = PlayerPrefs.GetString("Store", "");
HighScore = PlayerPrefs.GetInt("HighScore", 0);
GlobalScores = PlayerPrefs.GetString("GlobalScores", "");
if (!isLoaded)isUPP = true;
}
public void SetWebData(string Data)
{
string[] DataArray = Data.Split(new char[] { '&' });
///
ViewerId = DataArray[0];
Name = DataArray[1];
Avatar = DataArray[2];
City = DataArray[3];
Friends = DataArray[4];
Money = int.Parse(DataArray[5]);
Store = DataArray[6];
HighScore = int.Parse(DataArray[7]);
GlobalScores = DataArray[8];
///
isLoaded = true;
}
public void SetMoney(string number)
{
int num = int.Parse(number);
Money += num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment