Simple IAP System  5.3
Public Member Functions | Static Public Member Functions | Public Attributes | Events | List of all members
DBManager

Stores IAP related data such as all purchases, selected items and ingame currency. Makes use of the JSON format and simple encryption. You should only modify below values once (if necessary at all), thus they aren't public. More...

Inheritance diagram for DBManager:

Public Member Functions

void Init ()
 Initialization called by IAPManager in Awake(). More...
 

Static Public Member Functions

static DBManager GetInstance ()
 Returns a static reference to this script. More...
 
static int GetPurchase (string productID)
 Returns the purchase amount of a product. More...
 
static bool IsPurchased (string productID)
 Convenience method for checking whether a product is purchased or not. More...
 
static void SetPurchase (string productID, int amount=1)
 Sets a product id to purchased state. By default, the purchase amount is 1. Usually you would not want to call this directly except when granting products for free. More...
 
static int AddPurchase (string productID, int amount)
 This will increase the purchase amount by product id and return the new value. Negative values are clamped to 1. More...
 
static void ConsumePurchase (string productID, int amount=0)
 Consumes a product. If amount is not passed in, it is removed from purchased state completely. This should be used with caution. Also used for virtual product costs, expired subscriptions or fake purchases. More...
 
static JSONNode GetPlayerData (string keyID)
 Returns a player data node for a specific id. More...
 
static bool IsPlayerData (string keyID)
 Convenience method for checking whether player data exists or not. More...
 
static void SetPlayerData (string keyID, JSONData data)
 Used for storing your own player-related data on the device. JSONData supports all primitive data types. More...
 
static int AddPlayerData (string keyID, int amount)
 This will increment the player-related data value defined by id and return the new value. Can only work for integer compatible data. Negative values are clamped to 1. More...
 
static void ConsumePlayerData (string keyID, int amount=0)
 Consumes or removes a player data node for a specific id and saves the modified data on the device. Can only work for integer compatible data. If amount is not passed in, it is removed from player data completely. More...
 
static int GetCurrency (string currencyID)
 Returns the amount of funds for a specific currency. More...
 
static void SetCurrency (string currencyID, int amount)
 Overwrites and/or sets the total amount of funds for a specific currency. More...
 
static int AddCurrency (string currencyID, int amount)
 Increases the amount of funds for a specific currency and return the new value. More...
 
static int ConsumeCurrency (string currencyID, int amount)
 Convenience method for decreasing amount of funds for a specific currency and return the new value. More...
 
static bool IsRequirementMet (IAPRequirement req)
 Returns whether a requirement has been met. More...
 
static bool CanPurchaseVirtual (IAPProduct product)
 This method checks user's currency and product inventory for a virtual purchase. Returns true if the user owns all resources necessary to afford the new product. More...
 
static void PurchaseVirtual (IAPProduct product)
 Substracts costs for purchasing a virtual product. Granting it happens in the IAPManager. More...
 
static List< string > GetAllPurchased (bool withUpgrades=false)
 Returns list that holds all purchased product ids. By default, for upgradeable products this only returns the current active one. More...
 
static Dictionary< string, int > GetCurrencies ()
 Returns a dictionary of all currencies (name and currently owned amount). More...
 
static Dictionary< string, List< string > > GetAllSelected ()
 Returns a dictionary that holds all group names with selected product ids. More...
 
static List< string > GetSelectedGroup (string groupName)
 Returns all selected products within a specific group. More...
 
static bool SetSelected (string productID, bool single)
 Sets a product id to selected state. If single is true, other ids in the same group get deselected. single = false allows for multi selection. Returns a boolean that indicates whether it was a new selection. More...
 
static bool IsSelected (string id)
 Returns whether a product has been selected. More...
 
static void SetDeselected (string productID)
 Sets a product id to deselected state. More...
 
static string Read ()
 Returns the local data in string format. More...
 
static void Save (string key="")
 Save modified data to the device. Optionally supports encryption. More...
 
static void Overwrite (string otherData)
 Overwrite the current storage with another JSON representation. E.g. after downloading data from a remote server. More...
 
static string GetJSON (string key)
 Returns the desired JSON data node as a string. In case of content, free products are excluded. More...
 
static void Clear (string data)
 Remove data defined by section key. E.g. content, selected or currency. Should be used for testing purposes only. More...
 
static void ClearAll ()
 Removes all data storage set in this project. Should be used for testing purposes only. More...
 
static string GetDeviceId ()
 Reads fixed unique device ID where supported. Could be used to generate unique ID for this user on a cloud service. More...
 

Public Attributes

const string prefsKey = "SIS_data"
 The name of the datafile key on the device. More...
 
const string oldPrefsKey = "data"
 The old, deprecated name of the datafile key on the device. Do not use anymore. More...
 
const string persistentFileExt = ".dat"
 The file extension of the persistentDataPath file. More...
 
StorageTarget storageTarget = StorageTarget.PlayerPrefs
 Should purchase data only be saved on disk or in device memory only? Warning: with Memory selected and if you do not use some cloud save provider and login system (like PlayFab), your user's purchases will only exist throughout the current game session. More...
 
EncryptionType encryptionType = EncryptionType.Internal
 The type of encryption that should be applied on disk or device memory. More...
 
bool encrypt = false
 Used on encryption type = Internal. Whether encryption is enabled. More...
 
string obfuscKey
 Used on encryption type = Internal. 56+8 bit key for encrypting the JSON string: 8 characters, do not use code characters (=.,? etc) and play-test that your key actually works! on Windows Phone this key must be exactly 16 characters (128 bit) long. SAVE THIS KEY SOMEWHERE ON YOUR END, SO IT DOES NOT GET LOST ON UPDATES More...
 
const string currencyKey = "Currency"
 
const string contentKey = "Content"
 
const string selectedKey = "Selected"
 
const string playerKey = "Player"
 

Events

static Action< string > dataUpdateEvent
 Fired when a data save/update on the device happens, delivering the updated key, when available. More...
 
static Action< string > itemSelectedEvent
 Fired when selecting a shop item, delivering its product ID. More...
 
static Action< string > itemDeselectedEvent
 Fired when deselecting a shop item, delivering its product ID. More...
 

Detailed Description

Stores IAP related data such as all purchases, selected items and ingame currency. Makes use of the JSON format and simple encryption. You should only modify below values once (if necessary at all), thus they aren't public.

Member Function Documentation

static int AddCurrency ( string  currencyID,
int  amount 
)
static

Increases the amount of funds for a specific currency and return the new value.

static int AddPlayerData ( string  keyID,
int  amount 
)
static

This will increment the player-related data value defined by id and return the new value. Can only work for integer compatible data. Negative values are clamped to 1.

static int AddPurchase ( string  productID,
int  amount 
)
static

This will increase the purchase amount by product id and return the new value. Negative values are clamped to 1.

static bool CanPurchaseVirtual ( IAPProduct  product)
static

This method checks user's currency and product inventory for a virtual purchase. Returns true if the user owns all resources necessary to afford the new product.

static void Clear ( string  data)
static

Remove data defined by section key. E.g. content, selected or currency. Should be used for testing purposes only.

static void ClearAll ( )
static

Removes all data storage set in this project. Should be used for testing purposes only.

static int ConsumeCurrency ( string  currencyID,
int  amount 
)
static

Convenience method for decreasing amount of funds for a specific currency and return the new value.

static void ConsumePlayerData ( string  keyID,
int  amount = 0 
)
static

Consumes or removes a player data node for a specific id and saves the modified data on the device. Can only work for integer compatible data. If amount is not passed in, it is removed from player data completely.

static void ConsumePurchase ( string  productID,
int  amount = 0 
)
static

Consumes a product. If amount is not passed in, it is removed from purchased state completely. This should be used with caution. Also used for virtual product costs, expired subscriptions or fake purchases.

static List<string> GetAllPurchased ( bool  withUpgrades = false)
static

Returns list that holds all purchased product ids. By default, for upgradeable products this only returns the current active one.

static Dictionary<string, List<string> > GetAllSelected ( )
static

Returns a dictionary that holds all group names with selected product ids.

static Dictionary<string, int> GetCurrencies ( )
static

Returns a dictionary of all currencies (name and currently owned amount).

static int GetCurrency ( string  currencyID)
static

Returns the amount of funds for a specific currency.

static string GetDeviceId ( )
static

Reads fixed unique device ID where supported. Could be used to generate unique ID for this user on a cloud service.

static DBManager GetInstance ( )
static

Returns a static reference to this script.

static string GetJSON ( string  key)
static

Returns the desired JSON data node as a string. In case of content, free products are excluded.

static JSONNode GetPlayerData ( string  keyID)
static

Returns a player data node for a specific id.

static int GetPurchase ( string  productID)
static

Returns the purchase amount of a product.

static List<string> GetSelectedGroup ( string  groupName)
static

Returns all selected products within a specific group.

void Init ( )

Initialization called by IAPManager in Awake().

static bool IsPlayerData ( string  keyID)
static

Convenience method for checking whether player data exists or not.

static bool IsPurchased ( string  productID)
static

Convenience method for checking whether a product is purchased or not.

static bool IsRequirementMet ( IAPRequirement  req)
static

Returns whether a requirement has been met.

static bool IsSelected ( string  id)
static

Returns whether a product has been selected.

static void Overwrite ( string  otherData)
static

Overwrite the current storage with another JSON representation. E.g. after downloading data from a remote server.

static void PurchaseVirtual ( IAPProduct  product)
static

Substracts costs for purchasing a virtual product. Granting it happens in the IAPManager.

static string Read ( )
static

Returns the local data in string format.

static void Save ( string  key = "")
static

Save modified data to the device. Optionally supports encryption.

static void SetCurrency ( string  currencyID,
int  amount 
)
static

Overwrites and/or sets the total amount of funds for a specific currency.

static void SetDeselected ( string  productID)
static

Sets a product id to deselected state.

static void SetPlayerData ( string  keyID,
JSONData  data 
)
static

Used for storing your own player-related data on the device. JSONData supports all primitive data types.

static void SetPurchase ( string  productID,
int  amount = 1 
)
static

Sets a product id to purchased state. By default, the purchase amount is 1. Usually you would not want to call this directly except when granting products for free.

static bool SetSelected ( string  productID,
bool  single 
)
static

Sets a product id to selected state. If single is true, other ids in the same group get deselected. single = false allows for multi selection. Returns a boolean that indicates whether it was a new selection.

Member Data Documentation

const string contentKey = "Content"
const string currencyKey = "Currency"
bool encrypt = false

Used on encryption type = Internal. Whether encryption is enabled.

The type of encryption that should be applied on disk or device memory.

string obfuscKey

Used on encryption type = Internal. 56+8 bit key for encrypting the JSON string: 8 characters, do not use code characters (=.,? etc) and play-test that your key actually works! on Windows Phone this key must be exactly 16 characters (128 bit) long. SAVE THIS KEY SOMEWHERE ON YOUR END, SO IT DOES NOT GET LOST ON UPDATES

const string oldPrefsKey = "data"

The old, deprecated name of the datafile key on the device. Do not use anymore.

const string persistentFileExt = ".dat"

The file extension of the persistentDataPath file.

const string playerKey = "Player"
const string prefsKey = "SIS_data"

The name of the datafile key on the device.

const string selectedKey = "Selected"

Should purchase data only be saved on disk or in device memory only? Warning: with Memory selected and if you do not use some cloud save provider and login system (like PlayFab), your user's purchases will only exist throughout the current game session.

Event Documentation

Action<string> dataUpdateEvent
static

Fired when a data save/update on the device happens, delivering the updated key, when available.

Action<string> itemDeselectedEvent
static

Fired when deselecting a shop item, delivering its product ID.

Action<string> itemSelectedEvent
static

Fired when selecting a shop item, delivering its product ID.