Unity/Firebase/Realtimedatabase/基本
提供: 初心者エンジニアの簡易メモ
2021年9月19日 (日) 10:50時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「 ==サンプル== SampleScene.cs <pre> using System.Collections; using System.Collections.Generic; using UnityEngine; using Firebase; using Firebase.Database; using Fire...」)
サンプル
SampleScene.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.Database;
using Firebase.Unity.Editor;
public class SampleScene : MonoBehaviour
{
void Start()
{
// Get the root reference location of the database.
DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
// 書き込み
FirebaseDatabase.DefaultInstance.GetReference("users")
.Child("name")
.SetValueAsync("taro");
// 読み込み
FirebaseDatabase.DefaultInstance.GetReference("users")
.Child("name")
.GetValueAsync().ContinueWithOnMainThread(task =>
{
if (task.IsFaulted)
{
Debug.LogError("not found users");
}
else if (task.IsCompleted)
{
DataSnapshot snapShot = task.Result;
Debug.Log(snapShot.Value);
}
});
}
}
参考:https://firebase.google.com/docs/database/unity/retrieve-data?hl=ja
