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.

AchievementData
  • id (string): Unique id for this achievement.

  • requestName (string): Name use to call the achievement by a user friendly name.

  • name (string): Name of the achievement.

  • description (string): Description of the achievement.

  • rewards (List<Reward>): List of rewards when this achievement is finish and claimed. See Achievement Reward Data for more informations.

  • setBy (string): Let you know who can trigger this achievement (server or client).

  • isClaimable (bool): Let you know if the achievement is ready to be claimed.

  • valueToReach (int): Value to reach in order to claim this achievement.

  • completedAchievementsToUnlock (List<string>): List of other achievements required to unlock this one.

  • repeatable (bool): Let you know if this achievement can the triggered and claimed multiple time.

  • repeatNoMoreOftenThanCron (string): Let you set a period where this achievement can be repeated (daily, weekly, monthly). Can be set using cron setting.

  • startTime (long): The start time of this achievement. Cannot be triggered before this date.

  • endTime (long): The end time of this achievement. Cannot be triggered after this date.

  • resetTimeLimitEvery (string): Reset the start and end time based on a cron setting.

Achievement Reward Data structure
  • type

    • The reward type : currency, progression, item_by_id, setLeaderboardScore, addLeaderboardScore.

  • name

    • The name of the reward.

  • quantity

    • The quantity of the reward that will be given to the user upon completing the achievement.

      • For "item_by_id" and "currency", it represents the number of items or coins rewarded.

      • For "progression", it represents the increment value for the user's progression.

      • For "setLeaderboardScore", it represents the score that will be set for the current user to the leaderboard

      • For "addLeaderboardScore", it represents the score that will be added for the current user to the leaderboard

  • appIds

    • List of project id where the rewards will be given.

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