Hi,
In the getting started guide, the suggested workflow is to retrieve the RMPs from Economy and display them to the user. What’s the API call to do this? I’ve looked through the API guide but couldn’t spot anything obvious.
Thanks
Mick
Hi,
In the getting started guide, the suggested workflow is to retrieve the RMPs from Economy and display them to the user. What’s the API call to do this? I’ve looked through the API guide but couldn’t spot anything obvious.
Thanks
Mick
Hi Mick,
The API call to do this is “GetRealMoneyPurchasesAsync”.
This call will return a List of type RealMoneyPurchaseDefinition. You can find more details about the data type on this page in the documentation.
OK. I’ll open my eyes next time.
GetRealMoneyPurchasesAsync
I hope I’m not still being stupid (it happens a lot), but i’ve add the Unity.Services.Economy namespace to a class, and it can’t find the GetRealMoneyPurchasesAsync method. I’ve opened the library in the object browser in visual studio and I can’t see the method in there either.
I’m using
“com.unity.services.economy”: “1.0.0-pre.6”
Thanks
Mick
using Unity.Services.Economy;
var stuff = Economy.Configuration.GetRealMoneyPurchasesAsync();
Here’s a really basic example for getting RealMoneyPurchases (make sure that options.SetEnvironmentName is set to the environment where your RMPs are published):
using System.Collections.Generic;
using UnityEngine;
using Unity.Services.Economy;
using Unity.Services.Economy.Model;
using Unity.Services.Core;
using Unity.Services.Authentication;
using Unity.Services.Core.Environments;
public class EconomyActions : MonoBehaviour
{
async void Awake()
{
var options = new InitializationOptions();
options.SetEnvironmentName("development");
await UnityServices.InitializeAsync(options);
AuthenticationService.Instance.SignedIn += delegate
{
Debug.Log("All signed in and ready to go!");
Debug.Log($"Player ID is {AuthenticationService.Instance.PlayerId}");
Debug.Log($"Access Token is {AuthenticationService.Instance.AccessToken}");
};
await AuthenticationService.Instance.SignInAnonymouslyAsync();
FetchRealMoneyPurchases();
}
public async void FetchRealMoneyPurchases()
{
if (!IsAuthenticationSignedIn())
{
return;
}
List<RealMoneyPurchaseDefinition> realMoneyPurchases = await Economy.Configuration.GetRealMoneyPurchasesAsync();
if (realMoneyPurchases.Count == 0)
{
Debug.Log("No Purchases");
}
else
{
foreach (var rmp in realMoneyPurchases)
{
Debug.Log($"RMP {rmp.Name}: {rmp.Id}");
}
}
}
static bool IsAuthenticationSignedIn()
{
if (!AuthenticationService.Instance.IsSignedIn)
{
Debug.Log("Wait until sign in is done");
return false;
}
return true;
}
}
Hi Mick,
I’m delighted to see that you managed to retrieve your Real Money Purchase items from the store.
Thanks for sharing your code and experince with us. Your code looks good and I can confirm it works