A user-friendly Unity Editor Window for debugging a Firebase Realtime Database project.
The idea for this tool started after my third or fourth Unity + Firebase project. I'd been getting frustrated with having to write long debug logs every time I wanted to check interactions with Firebase's Realtime Database. So in short, I decided to learn about Unity Editor Extensions, which I had wanted to do for a long time, and scratch my own usability itch in the process.
Alright, let's get up and running.
- FirebaseDatabase.unitypackage from the Firebase SDK
- GoogleService-Info.plist file somewhere in the project
- A working internet connection
If you haven't already done this, here is a link to the general Unity setup and the Realtime Database instructions.
You can download FirebaseDebugger from the Unity Asset Store here.
Almost all of the setup for this tool is done programmatically, so the only thing you're responsible for is going to Tools > FBDebugger > Setup
And assigning your GoogleService-Info.plist to the Firebase Manager GameObject that is created for you in the Inspector.
The setup menu item will only be active if Unity is NOT in Play Mode, and the setup hasn't already been completed. I've done my best to create a sort of setup 'happy-path', so if you try and do anything out of order or in the wrong editor mode don't worry, there will be message dialogs to guide you back on track.
I wanted to make this as intuitive and easy as possible, so that's really all the setup there is.
If you need some tips, can't figure something out, or just want to send us some feedback about the tool, just use the big Help button in the bottom right corner of the Editor Window.
You can send any constructive criticism, requests, or really anything not filled with vitriol to hferrone@paradigmshiftdev.com
After the setup is complete, you can open the debug window in Play Mode by hitting the F key OR Tools > FBDebugger > Show Debugger
The Firebase Manager GameObject is already set up with a Singleton script that handles all the Firebase functionality, so you don't have to worry about initializing the debugger if you switch scenes.
On startup the debugger will automatically display all data at the project root, and will close itself when you exit Play Mode to keep the Firebase SDK happy and your console error-free.
Getting into your data is pretty simple. Enter the key, or nested keys, in the Child Nodes array and hit Query. This will construct a Database Reference and return all its data up to single key-value pairs.
In the example screenshots below, I can access a single players data by entering my parent node players and a user key.
For this first release only one sorting and filtering option can be applied to a given reference. In the next releases this will be expanded to incorporate multiple filtering options to mirror what Firebase supports.
By default there are no options selected, but you can use the dropdowns to target specific data, and where applicable enter sorting/filtering values. In the following example, I've sorted by exp and limited the query to the first three entries.
The data mapping option will let you test if you're unpacking your snapshots correctly, and will also give you a handy list of all the snapshot keys by default.
Any class that you want to map Firebase snapshots to will need to be derived from GenericMappable. GenericMappable is a simple abstract class that inherits from ScriptableObject.
public abstract class GenericMappable : ScriptableObject
{
public List<string> Keys = new List<string>();
public abstract void Map(Dictionary<string, object> withDictionary);
public virtual void ParseKeys(Dictionary<string, object> withDictionary)
{
foreach(KeyValuePair<string, object> entry in withDictionary)
Keys.Add(entry.Key);
}
}
You will need to implement the Map method to comply with GenericMappable, which is where you'd put in any snapshot unpacking logic you're working with.
For the example below I've unpacked the email, score, and exp fields with the following code:
public class TestMapClass : GenericMappable
{
public string email;
public int score;
public int level;
public override void Map(Dictionary<string, object> withDictionary)
{
if (withDictionary.ContainsKey("email"))
{
email = withDictionary["email"].ToString();
score = Convert.ToInt32(withDictionary["score"]);
level = Convert.ToInt32(withDictionary["exp"]);
}
}
}
With the result:
- Add in multiple filtering option functionality
- Add save/load/edit settings feature using Scriptable Objects
- Create custom editor for mapping class display
- Refactor debug area into TreeView
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.
This project uses SemVer for versioning. For the versions available, see the tags on this repository.
- Harrison Ferrone (hferrone) - Initial planning, design, and implementation
You can also see the complete list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Extending Unity with Editor Scripting by Angelo Tadres
- Property list parser by Chris Danielson