Unity
Unity integration
Introduction
Achievements can be used to reward the player following some specific actions in your game. He can be rewarded with currencies, virtual items, progression or leaderboard score.
Get game achievements
using UnityEngine;
using RGN.Modules.Achievement;
using System.Collections.Generic;
public class AchievementExamples : MonoBehaviour
{
private async void GetAllGameAchievements()
{
// Retrieves the 10 first achievements setup for my game
List<AchievementData> achievements = await AchievementsModule.I.GetForCurrentAppAsync(10);
foreach (var achievement in achievements)
{
Debug.Log($"Achievement name : {achievement.name} \n" +
$"Description : {achievement.description}");
}
}
}
Get user achievements
This function returns the completed and on going achievements for the user.
using UnityEngine;
using RGN.Modules.Achievement;
using System.Collections.Generic;
public class AchievementExamples : MonoBehaviour
{
private async void GetUserAchievementsAsync()
{
List<AchievementWithUserData> achievements = await AchievementsModule.I.GetForCurrentAppWithUserDataAsync(10);
foreach (var achievement in achievements)
{
UserAchievement userAchievement = achievement.GetUserAchievement();
Debug.Log($"Achievement name : {achievement.name} \n" +
$"Achievement progression : {userAchievement.value}/{achievement.valueToReach}");
}
}
}
Trigger achievement by id
using UnityEngine;
using RGN.Modules.Achievement;
public class AchievementExamples : MonoBehaviour
{
private async void CompleteAchievementAsync()
{
await AchievementsModule.I.TriggerByIdAsync("myAchievementId");
// This will increase the achievement progression by 1
// An additionnal parameter can be passed to increase the progress amount
}
}
Trigger achievement by request name
The request name can be set in the developer dashboard when creating the achievement.
using UnityEngine;
using RGN.Modules.Achievement;
public class AchievementExamples : MonoBehaviour
{
private async void CompleteAchievementAsync()
{
await AchievementsModule.I.TriggerByRequestNameAsync("myRequestName");
// This will increase the achievement progression by 1
// An additionnal parameter can be passed to increase the progress amount
}
}
Claim achievement by id
If the achievement is not set to be automatically claimed when completed, you can claim it in game to show to the player the rewards he received.
using UnityEngine;
using RGN.Modules.Achievement;
using System.Collections.Generic;
public class AchievementExamples : MonoBehaviour
{
private async void ClaimAchievementAsync()
{
var result = await AchievementsModule.I.ClaimByIdAsync("achievementId");
List<AchievementReward> rewards = result.rewards;
foreach (var reward in rewards)
{
Debug.Log($"Reward name : {reward.name} \n" +
$"Reward type : {reward.type} \n" +
$"Reward quantity : {reward.quantity}");
}
}
}
Claim achievement by request name
If the achievement is not set to be automatically claimed when completed, you can claim it in game to show to the player the rewards he received.
The request name can be set in the developer dashboard when creating the achievement.
using UnityEngine;
using RGN.Modules.Achievement;
using System.Collections.Generic;
public class AchievementExamples : MonoBehaviour
{
private async void ClaimAchievementAsync()
{
var result = await AchievementsModule.I.ClaimByRequestNameAsync("myRequestName");
List<AchievementReward> rewards = result.rewards;
foreach (var reward in rewards)
{
Debug.Log($"Reward name : {reward.name} \n" +
$"Reward type : {reward.type} \n" +
$"Reward quantity : {reward.quantity}");
}
}
}
Was this helpful?