관리 메뉴

caLAB

[유니티 개발] Firebase 데이터 getData(), setData() 본문

Unity/유니티 개발

[유니티 개발] Firebase 데이터 getData(), setData()

도이(doi) 2022. 5. 11. 15:26
728x90
using Firebase.Database;
using Firebase.Extensions;
using UnityEngine;

public class getRealtimeDBdata : MonoBehaviour
{
    private DatabaseReference reference;

    private void Start()
    {
        reference = FirebaseDatabase.DefaultInstance.RootReference;

        SetData();
        GetData();
    }

    public void SetData()
    {
        int test = 5;
        reference.Child("0").Child("ch_Birth").SetValueAsync(test);
    }

    public void GetData()
    {
        var assetAddress = reference.Child("3").Child("asset_address").GetValueAsync();
        assetAddress.ContinueWithOnMainThread(assetAddress =>
        {
            if (assetAddress.IsCompleted && assetAddress != null)
                {
                    DataSnapshot snapshot = assetAddress.Result;
                    Debug.Log(snapshot.Value.ToString());
                }
        });
    }
}
728x90
반응형
Comments