You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PlumberUltimateAds/Assets/Scripts/CurrencyController.cs

68 lines
1.2 KiB
C#

2 months ago
/*
http://www.cgsoso.com/forum-211-1.html
CG Unity3d Unity3d VIP
CGSOSO CG
daily assets update for try.
U should buy the asset from home store if u use it in your project!
*/
using System;
using UnityEngine;
public class CurrencyController
{
public const string CURRENCY = "ruby";
public const int DEFAULT_CURRENCY = 10;
public static Action onBalanceChanged;
public static Action<int> onBallanceIncreased;
public static int GetBalance()
{
return PlayerPrefs.GetInt("ruby", 10);
}
public static void SetBalance(int value)
{
PlayerPrefs.SetInt("ruby", value);
PlayerPrefs.Save();
}
public static void CreditBalance(int value)
{
int balance = GetBalance();
SetBalance(balance + value);
if (onBalanceChanged != null)
{
onBalanceChanged();
}
if (onBallanceIncreased != null)
{
onBallanceIncreased(value);
}
}
public static bool DebitBalance(int value)
{
int balance = GetBalance();
if (balance < value)
{
return false;
}
SetBalance(balance - value);
if (onBalanceChanged != null)
{
onBalanceChanged();
}
return true;
}
}