Time for action – saving and loading successful purchases
As entitlements such as full game unlocks are only purchased once and are expected to be part of a game forever, we need to save the record of our purchase when it's made and check if it exists every time the game is booted up. This is where we'll make use of the OUYA storage API that we mentioned in Chapter 6, Saving Data to Create Longer Games, because the data stored in it can exist even after the game is uninstalled and reinstalled. This way, a full game will still be unlocked even on a second installation. Perform the following steps to save and load successful purchases:
Add the following lines to your
OuyaPurchaseOnSuccess
callback function to store a value for the passed-in product:public void OuyaPurchaseOnSuccess(OuyaSDK.Product product) { OuyaSDK.OuyaJava.JavaPutGameData(product.name, product.identifier); }
We used two properties of the product variable, the name and the identifier, to set the key and value of the data...