Unlockables #

Read more about the Unlockables system in Hiro here.

Initializing the unlockables system #

The unlockables system relies on the Nakama System which must be passed in as dependency 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 appropriate interface.

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
15
16
17
18
19
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 consumableKvp in unlockable.Cost.Consumables)
    {
        Debug.Log($"{consumableKvp.Key}: {consumableKvp.Value}");
    }
    
    foreach (var collectable in unlockable.Cost.Collectables)
    {
        Debug.Log(collectable);
    }
}

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 reward = unlockablesSystem.ClaimAsync("<instanceId>");

Debug.Log("Collected reward:");

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

foreach (var consumableKvp in reward.Consumables)
{
    Debug.Log($"{consumableKvp.Key}: {consumableKvp.Value}");
}

foreach (var collectable in reward.Collectables)
{
    Debug.Log(collectable);
}

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}");