unity firebase realtime database tutorial

Unity Firebase Realtime Database Tutorial

This Unity Firebase Realtime Database Tutorial is designed to help developers integrate Firebase’s dynamic, cloud-hosted database into Unity applications. It covers everything from setting up Firebase and linking it to your Unity project to performing real-time data operations. Through this tutorial, you’ll gain hands-on experience with Firebase’s powerful features, such as live data syncing, data structuring, and real-time updates. By following the step-by-step instructions, you’ll learn how to efficiently manage and manipulate data in your Unity games or applications, ensuring that your users always have access to the most current information. Ideal for both beginner and intermediate developers, this tutorial provides practical insights and techniques to enhance your Unity projects with Firebase’s robust backend services.

LINE OF CODE: keytool -list -v -keystore test.keystore -alias test

FULL UNITY FIREBASE TUTORIAL SCRIPT

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Firebase.Database;

[Serializable]
public class dataToSave 
{
    public string userName;
    public int currentLevel;
    public int totalCoins;
    public int highScore;// & so on....

}
public class RealtimeDataSaver : MonoBehaviour
{
    public dataToSave dts;
    public string userId;
    DatabaseReference dbRef;

    private void Awake()
    {
        dbRef = FirebaseDatabase.DefaultInstance.RootReference;
    }

    public void SaveDataFn() 
    {
        string json = JsonUtility.ToJson(dts);
        dbRef.Child("users").Child(userId).SetRawJsonValueAsync(json);
    }

    public void LoadDataFn()
    {
        StartCoroutine(LoadDataEnum());
    }

    IEnumerator LoadDataEnum() 
    {
        var serverData = dbRef.Child("users").Child(userId).GetValueAsync();
        yield return new WaitUntil(predicate: () => serverData.IsCompleted);

        print("Process Completed");

        DataSnapshot snapshot = serverData.Result;
        string jsonData = snapshot.GetRawJsonValue();

        if (jsonData != null)
        {
            print("Matching Data Found!!!");

            dts = JsonUtility.FromJson<dataToSave>(jsonData);
        }
        else {
            print("No Matching Data Found");
        }
    
    }
}

***CHECK VIDEO TUTORIAL***

Leave a Reply

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping