#it loads firebase and everything from
1 messages · Page 1 of 1 (latest)
look in the second class i sent
public async UniTask GetInitialData() => _dataSnapshot = await _databaseReference.GetValueAsync();
sorry it wasn't formatted hard to see
suffice it to say not even discord is formatting this well
private async UniTaskVoid LoadFirebaseAndGame()
{
Application.targetFrameRate = 120;
await FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(async task =>
{
if (task.Exception == null)
{
FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(false);
await _databaseManager.GetInitialData();
ScenesLoader.Instance.LoadGame();
Destroy(gameObject);
}
else
{
_canvas.gameObject.SetActive(true);
}
});
}
like this?
public class DatabaseManager : MonoBehaviour, IDatabase
{
private DatabaseReference _databaseReference;
private DataSnapshot _dataSnapshot;
private void Awake() => _databaseReference = FirebaseDatabase.DefaultInstance.RootReference.Child(SystemInfo.deviceUniqueIdentifier);
public async UniTask GetInitialData() => _dataSnapshot = await _databaseReference.GetValueAsync();
public object GetValueFromDatabase(string path) => _dataSnapshot.Child(path)?.GetValue(true);
public void SetValueToDatabase(string path, object value) => _databaseReference.Child(path).SetValueAsync(value);
so did you author this code or did a chatbot? it looks like you authored it
i am just checking
why are you using the deviceuniqueidentifier?
as a child?
its an idle game i want to publish so i want everyone to have its own stats
idk about ios but on editor its unique
probably
its my first time doing it
i wanted to read all the data once and put it in a datasnapshot, only then load the next scene and have everything read from that datasnapshot
to reduce reads from the database
does it make sense?
add unirx. then:
private async UniTask<IReactiveProperty<int>> GetScoreReactive(string userScorePath) {
await FirebaseApp.CheckAndFixDependenciesAsync().ToUniTask();
// you will want persistence
FirebaseDatabase.DefaultInstance.SetPersistenceEnabled(true);
var root = FirebaseDatabase.DefaultInstance.RootReference;
var lastSeenScore = (int)(await root.Child(userScorePath).GetValueAsync()).Value;
var score = new ReactiveIntProperty(lastSeenScore);
// whenever you write to the score, save throttled to the database
// todo: application quit is probably more complicated than this
score
.Sample(
// save the latest score every 5 seconds or when the user quits
Observable.Timer(TimeSpan.FromSeconds(5f))
.Merge(Observable.OnceApplicationQuit())
)
.Subscribe(async (latestScore) => {
await root.Child(userScorePath).SetValueAsync(latestScore);
})
.AddTo(this);
return score;
}
that's it.
@split oriole does this make sense?