πŸ”₯ Trail Firebase

Use Firebase services with Unity and WebGL

Trail Firebase is a Unity package that enables the use of Firebase when building games for WebGL.

Firebase is an excellent game back-end service. Sadly, Firebase does not provide support for WebGL games natively. Luckily, Trail has you covered with a Unity package for your mobile game that allows for partial Firebase-WebGL-Unity integration.

Trail Firebase wraps around the Firebase API and checks if the game is running in-browser. If the game is running on WebGL, the normal import Firebase calls are simply replaced by Trail Firebase; making integrating Firebase with WebGL easy!

Implemented services

AnalyticsRealtime DatabaseRemote Config
βœ…βœ…*βœ…
*Partially implemented

Unimplemented features

AdMobAuthenticationCloud FirestoreCloud FunctionsCloud MessagingCloud StorageCrashlyticsDynamic Links
β›”β›”β›”β›”β›”β›”β›”β›”

Realtime Database

  • Queries
  • Transactions

How to use Trail Firebase

Step 2: Add the Firebase configuration file

Obtain the app project configuration, and save it to StreamingAssets/google-services-web.json.

{
  "apiKey": "api-key",
  "authDomain": "project-id.firebaseapp.com",
  "databaseURL": "https://project-id.firebaseio.com",
  "projectId": "project-id",
  "storageBucket": "project-id.appspot.com",
  "messagingSenderId": "sender-id",
  "appId": "app-id",
  "measurementId": "G-measurement-id"
}

Step 3: Initialize the Firebase API

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
    var status = task.Result;
    if (status == DependencyStatus.Available)
    {
        Debug.Log("Success initialize firebase app");
    }
    else
    {
        Debug.LogError($"Failed to initialize firebase app: {status}");
    }
});

Step 4: Access Firebase in your game

The API is the same as the official Firebase Unity SDK, which means that you only have to add import the correct
namespaces based on which platform you're building for.

#if UNITY_WEBGL && !UNITY_EDITOR
using Trail.Firebase;
using Trail.Firebase.Analytics;
using Trail.Firebase.Extensions;
#else
using Firebase;
using Firebase.Analytics;
using Firebase.Extensions;
#endif

....

void OnLevelUp(int newLevel)
{
    FirebaseAnalytics.LogEvent(FirebaseAnalytics.EventLevelUp, FirebaseAnalytics.ParameterLevel, newLevel);
}

πŸ“˜

Just like Firebase!

Once Trail Firebase is implemented you can use firebase just like you would without Trail (according to the Google Firebase documentation), as long as you use the features that Trail has manage to enable for the web.