User Profile

Integration Guide

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 currrencies information, you can get it by calling:

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

Load User Profile

using System.IO;
using RGN;
using RGN.Model;
using RGN.Modules.GameProgress;
using RGN.Modules.UserProfile;
using UnityEngine;

namespace SomeNamespace
{
    internal sealed class LoadUserProfile
    {
        public async void LoadUserProfileDataAsync()
        {
            string userId = RGNCore.I.MasterAppUser.UserId;
            GameUserFullProfileData currentUserData =
                await UserProfileModule.I.GetFullUserProfileAsync<GameUserFullProfileData>(userId);
        }
        public async void DownloadAndCacheUserAvatarAsync()
        {
            string userId = RGNCore.I.MasterAppUser.UserId;
            byte[] bytes = await UserProfileModule.I.DownloadAvatarImageAsync(userId, ImageSize.Small);
            if (bytes != null)
            {
                Texture2D avatar = new Texture2D(1, 1);
                avatar.LoadImage(bytes);
                avatar.Apply();
                string avatarSavePath = Path.Combine(Application.dataPath, "user_avatars", userId + ".png");
                File.WriteAllBytes(avatarSavePath, bytes);
            }
        }
    }
}

Update User Avatar Image

using RGN.Modules.UserProfile;
using UnityEngine;

namespace SomeNamespace
{
    internal sealed class UpdateUserAvatarImage
    {
        public async void UpdateUserAvatarAsync(UnityEngine.Texture2D avatarTexture)
        {
            byte[] bytes = avatarTexture.EncodeToPNG();
            bool success = await UserProfileModule.I.UploadAvatarImageAsync(bytes);
        }
    }
}

Update UserName/Display Name

using RGN.Modules.UserProfile;

namespace SomeNamespace
{
    internal sealed class UpdateUserName
    {
        public async void UpdateDisplayNameAsync(string displayName)
        {
            await UserProfileModule.I.SetDisplayNameAsync(displayName);
        }
    }
}

Update User Bio

using RGN.Modules.UserProfile;

namespace SomeNamespace
{
    internal sealed class UpdateUserBio
    {
        public async void UpdateBioAsync(string bio)
        {
            await UserProfileModule.I.SetBioAsync(bio);
        }
    }
}

Retrieve User Currencies

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

namespace SomeNamespace
{
    internal sealed class RetrieveUserCurrencies
    {
        public async void GetUserCurrenciesAsync()
        {
            List<Currency> currencies = await UserProfileModule.I.GetUserCurrenciesAsync();
            foreach (Currency currency in currencies)
            {
                UnityEngine.Debug.Log(currency.name + currency.quantity);
            }
        }
    }
}

rgn-coin Currency

Last updated