PLAY SDK Documentation
v0.12.0 (Obsolete)
v0.12.0 (Obsolete)
  • 🛠️ENVIRONMENT SETUP
    • Overview
    • PLAY Sample Package
  • 🖥️SDK Integration Guides
    • Getting Started
      • Unity
        • Tech Requirements
        • Step 1 - Import packages
        • Step 2 - Import credentials
        • Step 3 - Environments
        • Step 4 - Initialization
      • Unreal
        • Tech Requirements
        • Step 1 - Import packages
        • Step 2 - Configure credentials
        • Step 3 - Environments
        • Step 4 - Initialization
    • Authentication
      • Unity
      • Unreal
    • User Profile
      • Unity
      • Unreal
    • Virtual Items
      • Unity
      • Unreal
    • Inventory
      • Unity
      • Unreal
    • Store
      • Unity
      • Unreal
    • Currency (IAP)
      • Unity
      • Unreal
    • Achievements
      • Unity
      • Unreal
    • Game Progress
      • Unity
      • Unreal
    • Leaderboards
      • Unity
      • Unreal
    • Matchmaking
      • Unity
      • Unreal
    • Wallets
      • Unity
      • Unreal
    • Analytics
      • Unity
      • Unreal
    • Notifications
      • Unity
      • Unreal
    • Module Requests
  • 🎲Game Design Guides
    • Overview
    • User Authentication
    • User Profile
    • Game (Progression + Rewards)
    • Virtual Items
    • Currency (IAP)
    • Store
    • Inventory
    • Achievements
    • NFT Purchase Flow & Wallets
    • Limited-Time Offers
    • NFT Passes
  • 📌Links
    • PLAY Whitepaper
    • PLAY Postman API Doc
    • PLAY Dev Dashboard
    • PLAY Example Repository Dev
    • PLAY Example Repository Prod
    • Report an Issue
    • Discord dev-chat
    • Telegram Community Channel
    • Social Links
Powered by GitBook
On this page
  • Introduction
  • Guest Login/Logout
  • Subscribe Authentication Changed event
  • Email Login/Logout

Was this helpful?

Export as PDF
  1. SDK Integration Guides
  2. Authentication

Unity

Unity integration

Introduction

To interact with the PLAY API, you will need to be authenticated. This will allow you to store and retrieve additional user data in the PLAY ecosystem.

Guest Login/Logout

If the Auto Guest Login option in RGNUnityInitilizer.cs is checked, logging out from email will automatically sign you back in as guest.

Subscribe Authentication Changed event

using RGN;
using RGN.Modules.SignIn;
using UnityEngine;

public class AuthenticationChangedController : MonoBehaviour
{
    private void OnEnable()
    {
        RGNCore.I.AuthenticationChanged += OnAuthenticationChangedAsync;
    }
    private void OnDisable()
    {
        RGNCore.I.AuthenticationChanged -= OnAuthenticationChangedAsync;
    }

    private async void OnAuthenticationChangedAsync(AuthState authState)
    {
        switch (authState.LoginState)
        {
            case EnumLoginState.Success:
                Debug.Log("User is logged in");
                // You can start retrieving some data here
                break;
            case EnumLoginState.NotLoggedIn:
                Debug.Log("User is not logged in");
                break;
            case EnumLoginState.Error:
                Debug.LogError("On Auth error: " + authState.LoginState +
                    ", error: " + authState.LoginResult);
                break;
            default:
                Debug.LogError("Unhandled Login State: " + authState.LoginState);
                break;
        }
    }
}

Email Login/Logout

using RGN.Modules.SignIn;

public class EmailLoginLogout : MonoBehaviour
{
    public void EmailSignIn()
    {
        // This call will open a web form
        // Handle the result in RGNCore.I.AuthenticationChanged event callback
        EmailSignInModule.I.TryToSignIn();
    }
    public void EmailSignOut()
    {
        EmailSignInModule.I.SignOut();
    }
}

Was this helpful?

🖥️