Skip to content

openfort-xyz/playfab-unity-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Openfort-PlayFab Integration in Unity

Overview

PlayFab is a backend service provided by Microsoft for game developers, offering tools for live game management, all powered by Azure's cloud infrastructure.

In this sample we use PlayFab's email & password authentication method to register a new user or log in with an existing one. Once authenticaded we use PlayFab's user identity token to create a self-custodial account using Embedded Smart Accounts.

Moreover, by integrating the Openfort SDK into Azure Functions, we establish a seamless connection to PlayFab. Unity clients using the PlayFab Unity SDK can tap into these functions, accessing the full range of Openfort features within the game environment.

Application Workflow

Openfort PlayFab integration workflow

Prerequisites

Set up Openfort

  1. Add your PlayFab title and choose Save:

    PlayFab provider
  2. In order to create secure self-custodial accounts for our players, we need to create Shield Keys:

    playfab_integration_1_a_fd65cb50f3

    After the creation, it's very important you save Shield Encryption Share Key, you will need it later:

    playfab_integration_1_b_b57537dc82
  3. This sample requires a contract to run. We use 0x51216BFCf37A1D2002A9F3290fe5037C744a6438 (NFT contract deployed in Sepolia - 11155111). You can use the same to ease up things:

    playfab_integration_1_95cbd5e3b9
  4. We aim to cover gas fees for users. Set a new gas policy:

    playfab_integration_2_dc0ec65caa

    Now, add a rule to make our contract benefit from it:

    playfab_integration_3_8c21c821c5

Deploy Azure Backend

Open azure-backend with VS Code and sign in to Azure:

playfab_integration_4_7deea77cf3

Ensure your Function App (here, it's "openfort-playfab") is listed:

playfab_integration_5_6d5e73b886

In the terminal, run:

npm install

In the explorer, right-click on a function and select Deploy to Function App:

playfab_integration_6_ffc63d55ed

Next, choose your Function App:

playfab_integration_7_977d0a46c8

Then, click on Deploy:

playfab_integration_8_1119fa1634

Navigate to your Azure Portal and open your Function App. You should see all the functions listed:

playfab_integration_9_fb12c55de4

Click on any function and select Get Function Url:

playfab_integration_10_c4ebde5781

Subsequently, add this URL (along with all others) to PlayFab to enable access to our Azure Functions from within PlayFab.

Set up PlayFab Title

  1. Register Azure Functions

    Visit the PlayFab developer dashboard, choose your title, and click on Automation:

    playfab_integration_11_5615028c17

    Our functions are already registered. To do the same, click Register function and provide the function name along with its URL:

    playfab_integration_12_644b97fdaf

    Repeat this for all deployed functions.

Set up Azure Backend

Our Azure backend requires environment variables from both PlayFab and Openfort. Let's configure them.

  1. Add Openfort Environment Variables

    • Navigate to the Azure Portal and select your Function App.
    • Under Settings --> Environment variables, click Add:
    playfab_integration_13_c828ed6ed8
  2. Add PlayFab Environment Variables

    • Visit the PlayFab developer dashboard, select your title, and navigate to Settings wheel --> Title settings:

      playfab_integration_14_5bc8927522
    • In the API Features section, copy your Title ID:

      playfab_integration_15_711115c4a8
    • Under Secret Keys, note down your Secret key:

      playfab_integration_16_56663676c7
    • Return to the Azure Portal and choose your Function App.

    • Under Settings --> Environment variables, click Add:

      • Name: PLAYFAB_TITLE_ID
      • Value: [Your Title ID]
    • Add another application setting:

      • Name: PLAYFAB_SECRET_KEY
      • Value: [Your Secret Key]

After adding all the environment variables, your configuration panel should look like the following. Confirm your changes by clicking Save:

playfab_integration_17_6748a73edf

Set up Unity Client

This Unity sample project is already equipped with:

To begin, open unity-client with Unity:

  1. Configure PlayFab SDK

    • Navigate to the Project tab.
    • Search for PlayFabSharedSettings and input your PlayFab Title ID:
    playfab_integration_18_591d3cad7d
  2. Configure Openfort SDK

    • Open the Login scene and add the API Publishable Key and the Shield Publishable Key to the OpenfortController config section:
    playfab_integration_19_24bc025e75

Test in Editor

Play Login scene, opt for Register, provide an email and password, then click Register again. This scene should appear:

playfab_integration_20_f934393700

Select Mint. After a brief period, you should see a representation of your newly minted NFT:

playfab_integration_21_8213efd860

In the Openfort Players dashboard, a new player entry should be visible. On selecting this player:

playfab_integration_22_1b307cda7e

You'll notice that a mint transaction has been successfully processed:

playfab_integration_23_eca707b92d

Additionally, by choosing your Sepolia Wallet Address, the explorer will open and by selecting NFT Transfers tab you'll see the transaction is further confirmed:

playfab_integration_24_f29150e8b8
playfab_integration_25_8aa4b7ec6a

Conclusion

Upon completing the above steps, your Unity game will be fully integrated with Openfort and PlayFab. Always remember to test every feature before deploying to guarantee a flawless player experience.

Get support

If you found a bug or want to suggest a new [feature/use case/sample], please file an issue.

If you have questions, comments, or need help with code, we're here to help:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages