Subscribing to changes in the achievements system
#
You can listen for changes in the achievements 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
vardisposer=SystemObserver<AchievementsSystem>.Create(achievementsSystem,system=>{Instance.Logger.Info($"System updated.");// Update UI elements etc as necessary here...});
foreach(varachievementinachievementsSystem.GetAchievements()){Debug.Log($"Achievement {achievement.Name} ({achievement.Category})");Debug.Log(achievement.Description);if(achievement.HasReward()){Debug.Log("Reward available on completion");}if(achievement.SubAchievements.Any()){Debug.Log($"{achievement.SubAchievements.Count} sub-achievements.");}}
You can also list all repeatable achievements for the user.
You can claim rewards for an achievement. You can also specify whether you would like to claim any available total rewards (e.g. if the user has completed all sub-achievements) If you are granting rewards to the player from completing an achievement, you should refresh the EconomySystem here to get the updated state.
1
2
3
4
5
6
varclaimTotalReward=true;awaitachievementsSystem.ClaimAchievementsAsync(new[]{"<achievementId1>","<achievementId2>}",claimTotalReward);// Get updated economy after rewards have been grantedawaiteconomySystem.RefreshAsync();