Firebase inside Unity3d!
Welcome to Firebase (www.firebase.com) on Unity3d plugin, which supports:
- iOS
- Android
- The Unity Editor Player (currently works on Mac and Windows)
- Read about Firebase at www.firebase.com
- Clone this git repo, then form Unity open the Unity project in the
empty-project
folder - Open the
MainScene
and the exampleTestScript.cs
to start coding against Firebase!
You will find the API is very similar to the Java/iOS versions except that:
-
You create a new Firebase reference with:
IFirebase ref = Firebase.CreateNew("https://your-project-id.firebaseIO.com");
This gives you the proper platform-dependent implementation.
-
Certain parts of the API have been made C#-idiomatic with C# properties and events. For example, instead of getKey, you'll find a
Key
property.IFirebase root; IFirebase foo; void Awake() { root = Firebase.CreateNew("https://your-project-id.firebaseIO.com"); foo = ref.Child("foo"); foo.Child (DateTime.Now.ToString ("yyyy-MM-dd-HH-mm-ss-zzz")).SetValue ("Awake()"); } void OnEnable() { foo.ChildAdded += FooChildAdded; } void OnDisable() { foo.ChildAdded -= FooChildAdded; } void FooChildAdded (object sender, ChangedEventArgs e) { Debug.Log("FooChildAdded: " + e.DataSnapshot.Key); }
-
You are not receiving events, its very likely you allowed your Firebase reference to GC.
Instead of this:
new Firebase("mypath").ValueChanged += (...) => { .... };
do this:
classMember = new Firebase("mypath"); //holds a reference until the behavior is released classMember.ValueChanged += (...) => {...} ;
-
iOS: XCode fails to link. Please follow instructions located at: https://www.firebase.com/docs/ios/alternate-setup.html You will need to do this again if you do a full build/replace from Unity, but an incremental build will keep these settings.
-
Mac: The plugin does not appear to be working at all for the player, but works for iOS and Android
It could be that you have not installed the Java6 legacy runtime https://support.apple.com/kb/DL1572?locale=en_US It may also be that the plugin cannot locate Java on your machine. To patch the Java location, open the Fireproxy.bundle, cd into Contents/MacOS and run this command:
install_name_tool -change "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/server/libjvm.dylib" << newpath >> FirebaseProxy
where
newpath
is the location oflibjvm.dylib
under Java6. -
Windows: The plugin does not work in the player (or you get a nullref/crash) but works for iOS and Android. Make sure you have installed the 64bit version of Java and that you've updated your
PATH
environment variable to include the path tojvm.dll
. Note that the error you see will be something to the effect ofcould not locate Firebaseproxy.dll
. This happens because FirebaseProxy.dll depends on jvm.dll which could not be located.