Code Monkey home page Code Monkey logo

openfort-playfab-unity-sample's Introduction

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 integration, we use the Google Play Games plugin for Unity to handle authentication with PlayFab, ensuring a seamless and secure login experience for users on Android devices.

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

Integration workflow

Prerequisites

Set up Openfort

  1. This sample requires a contract to run. We use 0x38090d1636069c0ff1Af6bc1737Fb996B7f63AC0 (NFT contract deployed in 80001 Mumbai). You can use this for the guide:

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

    Now, add a rule so our contract uses this policy:

Deploy Azure Backend

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

Azure backend image

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

Function App image

In the terminal, run:

npm install

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

Next, choose your Function App:

Select Function App

Then, click on Deploy:

Deploy Confirmation

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

Functions List

Click on any function and select Get Function Url:

Get Function URL

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:

    Automation Selection

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

    Repeat this for all deployed functions.

  2. Install Google Add-on

    Navigate to Add-ons and choose Google:

    Google Add-on Selection

    Then, visit the Google Cloud APIs Credentials dashboard and click on the arrow icon next to your OAuth Web Application Client:

    OAuth Web Application Client

    Copy both the Client ID and Client Secret:

    Return to the PlayFab dashboard, paste these details into the Google OAuth Client ID and Google OAuth Client Secret fields, and click Install Google:

  3. Add PlayFab OAuth Redirect URL

    For this, go to the Google Cloud APIs Credentials dashboard. Here, select your Web application:

    Web Application Selection

    In the Authorized redirect URIs section, add the URL below and click Save:

    https://oauth.playfab.com/oauth2/google
    

Set up Azure Backend

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

  1. Add Openfort Environment Variables

    After adding these, your configuration panel should resemble the following. Click Save:

  2. Add PlayFab Environment Variables

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

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

    • Under Secret Keys, note down your Secret key:

      Secret Key

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

    • Under Configuration, select New application setting and input:

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

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

    Your configuration panel should now look like the following. Confirm your changes by clicking Save:

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:

  2. Configure Google Play Games SDK

    • Even if you've set up the Google Play Games SDK following the required tutorial, ensure that you've correctly configured all fields by navigating to Window --> Google Play Games --> Setup --> Android setup:

      Google Play Games Config 1

    By doing this, when the game runs on Android, it will utilize Google Play Games for user authentication via PlayFab. Otherwise, the default PlayFab authentication will be used.

Test in Editor

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

Game Scene

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

Minted NFT

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

Player Entry

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

Mint Transaction

Additionally, by choosing your Mumbai Account and viewing ERC-721 Token Txns, the transaction is further confirmed:

Transaction Confirm 2

Test on Android

Upon building and running the game on an Android device, the registration/login process is automated via Google Play Games, resulting in a streamlined user experience.

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.

For a deeper understanding of the underlying processes, stay tuned for the upcoming tutorial video. For assistance or queries, consider visiting our contact or support page.

openfort-playfab-unity-sample's People

Contributors

dpradell-dev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.