Unity

User Profile Data Types

There are 3 user profile data types you can get from the backend.

UserData

using System;

namespace RGN.Modules.UserProfile
{
    [Serializable]
    public class UserData
    {
        public string userId;
        public string email;
        public string displayName;
        public UserProfilePicture profilePicture;
        public string bio;
    }
}

UserProfileData

using System;
using System.Collections.Generic;
using RGN.Utility;

namespace RGN.Modules.UserProfile
{
    [Serializable]
    public class UserProfileData : UserData
    {
        public string lastAppPackageName;
        public bool invisibleStatus;
        public List<Currency.Currency> currencies;

        public UserProfileData()
        {
            currencies = new List<Currency.Currency>();
        }

        public int GetRGNCoinBalance();
        public int GetCustomCoinBalance(string currencyName);
    }
}

Get the user full profile data

You can see from the code snippets that UserProfileData inherits UserData. It means the UserProfileData contains all fields from the base class. So, in case you need the full profile with user currencies information, you can get it by calling:

await UserProfileModule.I.GetFullUserProfileAsync<UserProfileData>(userId);

Load User Profile

using RGN;
using RGN.Modules.UserProfile;
using UnityEngine;

public class UserProfileExample : MonoBehaviour
{
    public async void LoadUserProfileDataAsync()
    {
        string userId = RGNCore.I.MasterAppUser.UserId;
        UserProfileData userProfileData = await UserProfileModule.I.GetFullUserProfileAsync<UserProfileData>();
        Debug.Log($"Display name : {userProfileData.displayName} \n" +
            $"Bio : {userProfileData.bio} \n" +
            $"Email : {userProfileData.email} \n");
    }
}

Update UserName/Display Name

using UnityEngine;
using RGN.Modules.UserProfile;

public class UserProfileExamples : MonoBehaviour
{
    private async void UpdateDisplayName()
    {
        string newDisplayName = await UserProfileModule.I.SetDisplayNameAsync("New display name");
        Debug.Log($"Display name : {newDisplayName}");
    }
}

Update User Bio

using UnityEngine;
using RGN.Modules.UserProfile;

public class UserProfileExamples : MonoBehaviour
{
    private async void UpdateUserBio()
    {
        string newBio = await UserProfileModule.I.SetBioAsync("This is my user description");
        Debug.Log($"Bio : {newBio}");
    }
}

Retrieve User Currencies

using UnityEngine;
using System.Collections.Generic;
using RGN.Modules.UserProfile;
using RGN.Modules.Currency;

public class UserProfileExamples : MonoBehaviour
{
    private async void GetUserCurrencies()
    {
        List<Currency> currencies = await UserProfileModule.I.GetUserCurrenciesAsync();
        foreach (Currency currency in currencies)
        {
            Debug.Log($"Type : {currency.name} Quantity : {currency.quantity}");
        }
    }
}

"rgn-coin" Currency