Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/webgl.git
Firebase for WebGL

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **Firebase for WebGL** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/webgl.git
```

[![pkglnk](https://www.pkglnk.dev/badge/webgl.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/webgl)

Dependencies (1)

README

Firebase for Unity WebGL

Naive implementation of the most popular Firebase modules for Web apps and games made by Unity Engine.
Google does not provide support for the Unity WebGL plugin, so I've decided to do it by myself.

logo

Features

  • An easy-to-setup via one Firebase settings file, no additional actions required!
  • An easy-to-use API similar to the official Firebase plugin for Unity (iOS/Android) with small differences.
  • Ready to work through third-party web platforms.
  • Based on Firebase JS SDK 12.9.0 version

Which Firebase modules were included?

  • App
  • App-Check (limitations: no support for Custom Providers, ReCAPTCHA v3 and ReCAPTCHA Enterprise only)
  • Auth (limitations: no support for persistence and resolvers)
  • Analytics
  • Functions
  • Installations
  • Messaging (limitations: no support for Service Worker 'onBackgroundMessage')
  • Performance
  • Remote Config
  • Storage

Why were these modules missed?

As I see the situation, next modules are not used very often in games (for hypercasual/casual games it doesn't needed at all, for midcore/hardcode games usually used self-hosted backends)

  • AI
  • Database
  • Firestore

If I wrong, feel free to ping me and I will add these modules in the package as soon as possible.

What's inside?

  • [Runtime] Just few *.cs and *.jslib files
  • [Editor] HtmlAgilityPack.dll as a dependency

Installation

via Unity Package Manager

The latest version can be installed via package manager using following git URL:

https://github.com/am1goo/FirebaseWebGL-Unity.git#0.9.11

Extensions

How to use

Create a Firebase App

private FirebaseWebGL.FirebaseApp app;

void Awake()
{
    app = FirebaseWebGL.FirebaseApp.DefaultInstance();
}

Every installed module must first be initialized

IEnumerator Start()
{
    if (app.Analytics != null)
    {
        bool? isInitialized;
        app.Analytics.Initialize((callback) =>
        {
            if (callback.success == false)
            {
                Debug.LogError($"Initialize: {callback.error}");
                yield break;
            }
            isInitialized = callback.result;
        });
        yield return new WaitUntil(() => initialized != null);
        Debug.Log($"Initialized: {isInitialized}");
    }
}

Do what you want as same as you do it in official plugin (or kind of similar way)

...
    app.Analytics.LogEvent("my event");
...

Troubleshooting

CORS policies

You will probably experience difficulties loading additional scripts from Google servers. To resolve, ask your IT or web-platform support to add following domains to CORS policies:

fcmregistrations.googleapis.com
firebase.googleapis.com
firebaseappcheck.googleapis.com
firebaseinstallations.googleapis.com
firebaselogging.googleapis.com
firebaseremoteconfig.googleapis.com
firebasestorage.googleapis.com
firebasevertexai.googleapis.com
firestore.googleapis.com
identitytoolkit.googleapis.com

Different configurations

By default, to use Firebase functionality, the settings file should be located at specified path Resources/FirebaseSettings.asset.
If you want to override this behaviour, you may define FIREBASE_WEBGL_SETTINGS_PATH environment argument during the build process.

It can be useful in case where you want to have different configurations for various web platforms (Crazy Games, Poki, Playhop and others).

Tested in

  • Unity 2020.3.x

Contribute

Contribution in any form is very welcome. Bugs, feature requests or feedback can be reported in form of Issues.

Comments

No comments yet. Be the first!