Unlockables #

Read more about the Unlockables system in Hiro here.

Initializing the unlockables system #

The unlockables system relies on the Nakama System and an ILogger, both must be passed in as dependencies via the constructor.

1
2
var unlockablesSystem = new UnlockablesSystem(logger, nakamaSystem);
systems.Add(unlockablesSystem);

Subscribing to changes in the unlockables system #

You can listen for changes in the unlockables system so that you can respond appropriately, such as updating the UI, by implementing the IObserver pattern, or use the SystemObserver<T> type which handles it for you.

1
2
3
4
5
var disposer = SystemObserver<UnlockablesSystem>.Create(unlockablesSystem, system => {
    Instance.Logger.Info($"System updated.");

    // Update UI elements etc as necessary here...
});

Refreshing the unlockables system #

To ensure the unlockables system has the latest information from Nakama you can refresh it.

1
await unlockablesSystem.RefreshAsync();

Listing available unlockables #

You can list available unlockables.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
foreach (var unlockable in unlockablesSystem.Unlockables)
{
    Debug.Log($"{unlockable.Name} - {unlockable.Description}. Cost:");

    foreach (var currencyKvp in unlockable.Cost.Currencies)
    {
        Debug.Log($"{currencyKvp.Key}: {currencyKvp.Value}");
    }
    
    foreach (var itemKvp in unlockable.Cost.Items)
    {
        Debug.Log($"{itemKvp.Key}: {itemKvp.Value}");
    }
}

Claiming an unlockable reward #

You can claim an unlockable reward.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
var unlockablesReward = await unlockablesSystem.ClaimAsync("<instanceId>");

Debug.Log("Collected reward:");

foreach (var currencyKvp in unlockablesReward.Reward.Currencies)
{
    Debug.Log($"{currencyKvp.Key}: {currencyKvp.Value}");
}

foreach (var consumableKvp in unlockablesReward.Reward.Items)
{
    Debug.Log($"{consumableKvp.Key}: {consumableKvp.Value}");
}

foreach (var energyKvp in unlockablesReward.Reward.Energies)
{
    Debug.Log($"{energyKvp.Key}: {energyKvp.Value}");
}

Purchasing a slot #

You can purchase an additional unlockable slot.

1
await unlockablesSystem.PurchaseSlotAsync();

Purchasing an unlock #

You can purchase an unlock of a slot.

1
await unlockablesSystem.PurchaseUnlockAsync("<instanceId>");

Begin unlocking a slot #

You can begin unlocking a slot.

1
await unlockablesSystem.UnlockStartAsync("<instanceId>");

Creating an unlockable #

You can create an unlockable.

1
await unlockablesSystem.CreateAsync();

Inspecting the overflow slot #

You can inspect the overflow slot.

1
Debug.Log($"{unlockablesSystem.Overflow.Name} - {unlockablesSystem.Overflow.Description}");