Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~ ~ Getting OUYA IAP to work in Unity ~ ~
- --- SDK ---
- first off, you need to be familiar with the OuyaSDK package, all that stuff is available here:
- https://devs.ouya.tv/developers/docs/unity
- and specifically here:
- http://www.youtube.com/watch?v=plqEuuilv6k
- don't forget to follow the ODK setup instructions first (I know, they are sucky but I can't explain them better) here:
- https://devs.ouya.tv/developers/docs/setup
- --- PREP ---
- You will need to create your game (you don't need to submit it yet):
- https://devs.ouya.tv/developers/games
- then on that same page, download the signing key (key.der) for the game and put it in:
- Assets/Plugins/Android/res/raw/key.der
- you will then need to make a product (or more) for your game's IAP:
- https://devs.ouya.tv/developers/products
- (the identifier is the string you will use to reference the product in your code, the name is what the player will see when purchasing the game)
- --- SET UP ---
- On your 'OuyaGameObject' component (remember, only ever have one in the game at a time!) enter your UUID in the DEVELOPER_ID string. you can find your UUID here:
- https://devs.ouya.tv/developers
- in the same component's Purchasables list, enter your product identifiers that you just set up for the game.
- --- LISTENERS ---
- you need a script to listen for IAP and related events, you can find this list of stuff on this page (scroll down past the videos, or ctrl+f "Scene Products Example")
- https://devs.ouya.tv/developers/docs/unity
- the docs don't tell you, but you need to make sure your script has the following line (without quotes) at the top of it to compile:
- "using System.Collections.Generic;"
- a quick overview of the important stuff:
- OuyaGetProductsOnSuccess() gives you a list of info about the products you ask for, if you are displaying a price in your game you should always pull it from this list, so you can change the price later and it doesn't break the game.
- OuyaPurchaseOnSuccess() is fired when the user makes a successful purchase, you should unlock the game right away when this fires.
- OuyaGetReceiptsOnSuccess() this passes a list of everything the user has purchased, when and for how much. you MUST use this to check if the player has purchased a product before offering to sell it to them again. ideally you should check this at the very start of your game. it's of course a requirement so people who have deleted the game and re-installed will have the game unlock immediately too.
- --- THE PROCESS ---
- first off, you *cannot* do any IAP activities in Start() or Awake() or the like, you must check if OuyaSDK.isIAPInitComplete() returns true first, and only THEN do your IAP stuff.
- to request the user's UUID, call:
- OuyaSDK.fetchGamerUUID()
- to request the list of available products, use:
- List<OuyaSDK.Purchasable> productIdentifierList = new List<OuyaSDK.Purchasable>();
- foreach (string productId in OuyaGameObject.Singleton.Purchasables){
- productIdentifierList.Add(new OuyaSDK.Purchasable(productId));
- }
- OuyaSDK.requestProductList(productIdentifierList);
- to request the list of receipts, use:
- OuyaSDK.requestReceiptList();
- --- TIPS ---
- 1) avoid ever showing the option to buy stuff the user has already bought, it's messy and confusing
- 2) you can check the receipt list on your game's startup every time if you like, but I like to store a playerprefs var to say if the game has been unlocked or not, this way the user can play offline.
- 3) sometimes the OUYA servers go down, there is no such thing as 100% uptime so don't wait forever for those listeners. if something is taking ages, give the player an option to skip all your IAP stuff and just play the free game
- 4) testing your IAP doesn't cost you any money, and you can remove test purchases from your dev account here:
- https://devs.ouya.tv/developers/purchases
- 5) Don't be an asshole. treat your players with respect and not like a pet you can train to give you money. the emphasis with OUYA is "Free-to-Try" and not "Free-to-Play". Do what you like of course, just check your conscience before you commit ;)
- - @S0phieH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement