Unity IAP (4.12.2) wrapper for simple usage
npm install extensions.unity.iap.storeopenupm add extensions.unity.iap.store
/Packages/manifest.json
json
{
"dependencies": {
"extensions.unity.iap.store": "4.12.2",
},
"scopedRegistries": [
{
"name": "package.openupm.com",
"url": "https://package.openupm.com",
"scopes": [
"extensions.unity",
"com.cysharp.unitask",
"com.neuecc.unirx"
]
}
]
}
`
How to setup
$3
Override at least abstract method. You should take of saving your data in persistent memory. There are basic methods required to implement in the example below.
`C#
using System;
using System.Collections.Generic;
using Sirenix.Serialization;
using UnityEngine;
using UniRx;
using Project.Store;
using BigInt = System.Numerics.BigInteger;
[CreateAssetMenu(fileName = "MyStore", menuName = "Store/MyStore")]
public class MyStore : StoreSO
{
[OdinSerialize, NonSerialized]
public ReactiveProperty balance = new ReactiveProperty();
public override IObservable OnBalanceChanged(string currency)
{
return balance.Select(x => new Price(currency, x));
}
public override BigInt GetBalance(string currency)
{
return balance.Value;
}
protected override void SpendBalance(string currency, BigInt amount)
{
balance.Value -= amount;
}
protected override void ApplyPurchase(List sellables)
{
// Apply purchase here
}
}
`
$3
Create instance and do setup. You can add as many currencies as needed. Also you can use it without currencies at all, if you just need to handle in-app purchases.
!Unity_4gPx4Wi804
$3
!Unity_uV6ioqFm1l
How to show sellable item(s) in UI
This system is quite independent, but you need to show sellable items for a user, to make ability for a user to buy them. There are multiple ways to do that.
- create prefab for drawing UI element which represent single item for selling. If you need you can use multiple prefabs for different reasons in different places
- add StoreSellableDrawer_UGUI component to the prefab
- bind all required elements to the component
!image
It can be used for showing single sellable item.
Adapters
Adapter generates multiples items, very easy to setup all of them from single place with small amount of setup steps.
- StoreCategoryAdapter - shows list of sellable items from specific category
- StoreCustomAdapter - shows custom list of sellable items
- Or create your own StoreAdapter, for that need to extand from StoreAdapter. Also you may create custom StoreSellableDrawer for any UI system in case if you don't use Unity UI.
!image
How to show player's current currencies balance in UI
CurrencyBalanceDrawer_UGUI_TMP show currency balance and refreshes it when it changed.
!image
How to show separate price of specific sellable item
That is easy. Just create any gameObject with Text component and add PriceDrawer on it.
!image
Other
- to execute Purchase action without sellable item drawer and/or adapter use SimplePurchaser
- to restore non-consumable in-app purchases use SimpleInAppPurchaseRestorer`