「Unity/Firebase/Realtimedatabase/基本」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→サンプル) |
|||
| (同じ利用者による、間の1版が非表示) | |||
| 行26: | 行26: | ||
FirebaseDatabase.DefaultInstance.GetReference("users") | FirebaseDatabase.DefaultInstance.GetReference("users") | ||
.Child("name") | .Child("name") | ||
| − | .GetValueAsync(). | + | .GetValueAsync().ContinueWith(task => |
{ | { | ||
if (task.IsFaulted) | if (task.IsFaulted) | ||
| 行36: | 行36: | ||
DataSnapshot snapShot = task.Result; | DataSnapshot snapShot = task.Result; | ||
Debug.Log(snapShot.Value); | Debug.Log(snapShot.Value); | ||
| − | + | } | |
}); | }); | ||
| 行45: | 行45: | ||
参考:http://siguma-sig.hatenablog.com/entry/2018/09/30/213822 | 参考:http://siguma-sig.hatenablog.com/entry/2018/09/30/213822 | ||
| − | |||
==階層== | ==階層== | ||
2021年9月29日 (水) 00:50時点における最新版
サンプル
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().ContinueWith(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
参考:http://siguma-sig.hatenablog.com/entry/2018/09/30/213822
階層
/で区切ったり、
.Child("na/me")
Childでつなげたり。
.Child("na").Child("me")
keyを生成
userに存在しないキーを生成
string key = FirebaseDatabase.DefaultInstance.GetReference("user").Push().Key;
