Skip to content

openfort-xyz/firebase-extension-unity-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Firebase Extension abnd Openfort via Firestore

Firebase is Google's all-encompassing app development platform, providing game developers with an array of backend tools powered by Google Cloud.

Within Unity, we've integrated the Firebase SDK to facilitate backend functionalities. Coupled with the Google Play Games plugin for Unity, it ensures a secure and efficient login for Android users.

The integration is further enhanced with the Openfort Firebase extension, which incorporates the Openfort SDK. This enables Unity clients to directly leverage Openfort's blockchain capabilities, allowing for sophisticated blockchain interactions within the gaming environment.

Application Workflow

Openfort Firebase Extension workflow

Prerequisites

  • Sign in to dashboard.openfort.xyz and create a new project.

  • You need a Google Play Developer account.

  • You need a Google Cloud project.

  • Clone or download the repository and open it with Unity 2021.3. When opening the project, select Ignore on this popup:

    Alt text

    Once opened, you will see some reference errors. We will solve this in the next step by importing the Firebase SDK.

  • Follow the Firebase-Unity setup guide. On step 4, you just need to import FirebaseAuth and FirebaseFirestore packages:

    Alt text

    Do it one by one and disable ExternalDependencyManager folder before importing:

    Alt text

    Most reference errors should be solved by now. If UnityEditor.iOS.Extensions.Xcode error is still standing, select Firebase.Editor asset, disable Validate References and choose Apply:

    Alt text

  • Create a keystore Follow this guide to create a new keystore for the Unity project.

  • Find SHA1 certificate fingerprint You need to extract the certificate fingerprint from the created keystore. Follow this video tutorial on how to do it, it also covers the creation of the keystore.

    This is the command that you will need to run:

    keytool -list -v -keystore "path/to/your/keystore" -alias "your_key_alias"

Set up Firebase

Add Google sign-in provider

Go to the Firebase console, select your project and select Authentication:

Alt text

Select Get started:

Alt text

Select Google as a sign-in provider:

Alt text

Activate Enable toggle, choose a public-facing name and select Save:

Alt text

A popup will appear. Copy the Web client ID and the Web client secret somewhere safe and choose Done. You will see your Google provider enabled:

Alt text

Select the provider and choose Project Settings. Under Your apps section select Add fingerprint and add your SHA1 certificate fingerprint. Then choose Save:

Alt text

Alt text

Add Google Play sign-in provider

Select Add new provider and choose Google Play:

Alt text

Activate Enable toggle, enter the credentials you just saved and choose Save:

Alt text

Both Google and Google Play sign-in providers are ready:

Alt text

Install Openfort Extension

Go to the Firebase Extensions Hub and choose Install in Firebase console:

Alt text

Choose your project to continue:

Alt text

Set up your billing profile and follow the instructions until you need to insert the Openfort API Secret key and choose Create secret. Also set Cloud Firestore to Sync:

Alt text

Finally choose Install extension. After 3-5 minutes you will see the extension installed:

Alt text

Now select Get started and under How this extension works section find Configure Openfort webhooks. Copy the URL:

Alt text

Set up Openfort

Choose Add webhook:

Alt text

Paste the webhook URL you got from the Firebase extension and leave the Type as it is. Choose Add webhook:

Alt text

Choose Add contract:

Alt text

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

Alt text

Choose Add policy:

Alt text

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

Alt text

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

Alt text

Set up Google Play

Reminder: Use the same Google account you used for setting up your Firebase app.

Create a new app

Go to Play Console and create a new app. Enter app details (it's important you select Game), confirm policies and select Create app:

Alt text

Under Grow --> Play Games Services --> Setup and management --> Configuration, select Create new Play Games Services project and choose your Firebase project as the cloud project. Then select Use:

Alt text

Add credentials

Add Android OAuth client credential

Under Credentials section choose Add credential:

Alt text

Select Android:

Alt text

Scroll down and select Create OAuth client:

Alt text

Choose Create OAuth Client ID:

Alt text

This will open the Google Cloud console. Now select Android as Application type, enter a Name and fill the Package name with the Unity app package name (found in the Android Platform Player Settings):

Alt text

Alt text

Enter your SHA1 certificate fingerprint and choose CREATE:

Alt text

Now you can download the JSON and choose OK:

Alt text

Go back to the Google Play console, select Done and choose your newly created Android OAuth client. Then select Save changes:

Alt text

Add Game server/Web OAuth client credential

Go back to Configuration and select Add credential:

Alt text

Choose Game server, refresh OAuth clients, select Web client (auto created by Google Service) (it was created automatically during this process) and select Save changes:

Alt text

Finally copy the OAuth client ID:

Alt text

Set up Unity project

Reminder: Make sure Android is selected as a platform in Build settings.

Go to Window --> Google Play Games --> Setup --> Android setup:

Alt text

Paste the Game server OAuth client ID you just copied under Client ID:

Alt text

Go to the Google Play console and on your app's configuration select Get resources:

Alt text

Copy the Android (XML):

Alt text

In Unity, paste it in Resources Definition and then select Setup:

Alt text

Finally, go to the Firebase console and under your app configuration, download the google-services.json:

Alt text

Import it in your Unity project Assets folder to make sure every credential is up to date.

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 Firebase. Always remember to test every feature before deploying to guarantee a flawless player experience.

For a deeper understanding of the underlying processes, check out the tutorial video.

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