Streaks #

Read more about the Streak system in Hiro here.

Initializing the streaks system #

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

1
2
var streaksSystem = new StreaksSystem(logger, nakamaSystem);
systems.Add(streaksSystem);

Subscribing to changes in the streaks system #

You can listen for changes in the streak 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<StreaksSystem>.Create(streaksSystem, system => {
  Instance.Logger.Info($"Streaks system updated.");

  // Update UI or handle changes here...
});

Refreshing the streaks system #

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

1
await streaksSystem.RefreshAsync();

Listing streaks #

You can list the current streaks for the user:

1
2
3
4
foreach (var (key, streak) in streaksSystem.Streaks)
{
    Debug.Log($"{key}: {streak.CurrentStreakValue}");
}

Claiming Streaks Rewards #

Players can claim streak rewards using the ClaimAsync method, passing the streak IDs.

1
await streaksSystem.ClaimAsync(new List<string> { "daily_login", "weekly_win" });

Resetting Streaks #

To reset specific streaks for a player, use the ResetAsync method:

1
await streaksSystem.ResetAsync(new List<string> { "daily_login", "weekly_win" });

Updating Streaks #

You can manually update streaks for a player by passing a dictionary of streak names and new values:

1
2
3
4
5
6
7
var streaksToUpdate = new Dictionary<string, long>
{
    { "daily_login", 10 },
    { "weekly_win", 3 }
};

await streaksSystem.UpdateAsync(streaksToUpdate);