Created
May 12, 2015 15:43
-
-
Save suakig/1d96b4cc9b498b60fc03 to your computer and use it in GitHub Desktop.
DeleGateAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class DeleGateAction | |
{ | |
private const string COIN_KEY = "Coin"; | |
public static Action<int> OnCoinChange = delegate {}; | |
public static int Get() | |
{ | |
return PlayerPrefs.GetInt (COIN_KEY, 0); | |
} | |
public static bool Add(int coin) | |
{ | |
if (coin < 0) { | |
return false; | |
} | |
CoinChange (Get () + coin); | |
return true; | |
} | |
public static bool Sub(int coin) | |
{ | |
if (coin < 0) { | |
return false; | |
} | |
if (Get () - coin < 0) { | |
return false; | |
} | |
CoinChange (Get () - coin); | |
return true; | |
} | |
private static void CoinChange(int coin) | |
{ | |
PlayerPrefs.SetInt (COIN_KEY, coin); | |
PlayerPrefs.Save (); | |
OnCoinChange (PlayerPrefs.GetInt (COIN_KEY, 0)); | |
} | |
public static void CoinChange() | |
{ | |
OnCoinChange (PlayerPrefs.GetInt (COIN_KEY, 0)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment