Every project may have multiple custom currencies. For example "diamonds" and/or "cash". Aside from these typical game currencies, projects wishing to sell NFTs must integrate a specific currency. The internal name for this currency is "rgn-coin". When the "rgn-coin" is presented in the UI it can have any currency name, for example, "gems".
The "rgn-coin" can only be sold using in-app purchases. For more information, please refer to the Currency GDG.
Other typical currencies can be added and used in an expected manner - as rewards to the user's account, or sold for in-app purchases.
We suggest utilizing Unity's IAP Package to handle the in-app purchase process on Android and iOS.
Purchasergn-coin (IAP required)
Purchasing rgn-coin works a bit differently, it has its own API called PurchaseRGNCoinAsync(string iapUUID)
We recommend using the latest version of the Unity IAP plugin.
You will need to get the transactionId and receipt from the PurchaseEventArgs when the in app purchase is completed.
usingUnityEngine;usingRGN.Modules.Currency;usingUnityEngine.Purchasing;publicclassCurrenciesExamples:MonoBehaviour{publicPurchaseProcessingResultProcessPurchase(PurchaseEventArgspurchaseEvent){boolvalidPurchase=true;// Presume valid for platforms with no R.V.if(validPurchase){Debug.Log($"Product {purchaseEvent.purchasedProduct.definition.id} Purchased");stringtransactionId=purchaseEvent.purchasedProduct.transactionID;stringreceipt=purchaseEvent.purchasedProduct.receipt;PurchaseRGNCoinAsync(transactionId,receipt);}else{Debug.LogError($"Something happened when trying to purchase product {purchaseEvent.purchasedProduct.definition.id}");}returnPurchaseProcessingResult.Complete;}publicasyncvoidPurchaseRGNCoinAsync(stringtransactionId,stringreceipt){stringrgnProductId="4a13bcd3-ff64-43a4-8c13-e978d968f68c";// 10 rgn-coinawaitCurrencyModule.I.PurchaseRGNCoinAsync(rgnProductId,transactionId,receipt);}}
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Currency;
public class CurrenciesExamples : MonoBehaviour
{
public async void GetRgnCoinCurrenciesAsync()
{
List<Currency> currencies = await CurrencyModule.I.GetUserCurrenciesAsync();
Currency readyCurrency = currencies.Find(x => x.name.Equals("rgn-coin"));
Debug.Log($"User has {readyCurrency.quantity} rgn-coin");
}
}
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Currency;
public class CurrenciesExamples : MonoBehaviour
{
public async void AddSoftCurrenciesAsync()
{
Currency goldCurrency = new Currency
{
name = "gold",
quantity = 10
};
List<Currency> currenciesToAdd = new List<Currency> { goldCurrency };
await CurrencyModule.I.AddUserCurrenciesAsync(currenciesToAdd);
}
}
using System.Collections.Generic;
using UnityEngine;
using RGN.Modules.Currency;
public class CurrenciesExamples : MonoBehaviour
{
public async void GetSoftCurrenciesAsync()
{
List<Currency> currencies = await CurrencyModule.I.GetUserCurrenciesAsync();
Currency goldCurrency = currencies.Find(x => x.name.Equals("gold"));
Debug.Log($"User has {goldCurrency.quantity} gold");
}
}