-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFirestormApp.cs
78 lines (71 loc) · 2.5 KB
/
FirestormApp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Firebase;
using Firebase.Auth;
using UnityEngine;
namespace E7.Firebase
{
public static class Firestorm
{
internal const string assetMenuName = nameof(Firebase) + "/";
internal const string restApiBaseUrl = "https://firestore.googleapis.com/v1beta1";
/// <summary>
/// Start building the collection-document path here.
/// </summary>
public static FirestormCollectionReference Collection(string name) => new FirestormCollectionReference(name);
//Prevents garbage collection bug
private static FirebaseApp appInstance;
private static FirebaseAuth authInstance;
public static void CreateEditModeInstance()
{
if (Application.isPlaying == false)
{
DisposeEditModeInstance();
appInstance = FirebaseApp.Create(FirebaseApp.DefaultInstance.Options, $"TestInstance {UnityEngine.Random.Range(10000, 99999)}");
}
}
public static void DisposeEditModeInstance()
{
if (Application.isPlaying == false)
{
//Somehow this crashes Unity lol... the network is left running in the other thread it seems.
appInstance?.Dispose();
}
}
public static FirebaseApp AppInstance
{
get
{
if (Application.isPlaying)
{
appInstance = FirebaseApp.DefaultInstance;
return appInstance;
}
else
{
//Firebase said you should not use default instance in editor (edit mode test also)
//https://firebase.google.com/docs/unity/setup#desktop_workflow
if (appInstance == null)
{
throw new FirestormException($"You forgot to call CreateEditModeInstance before running in edit mode");
}
return appInstance;
}
}
}
public static FirebaseAuth AuthInstance
{
get
{
if (Application.isPlaying)
{
authInstance = FirebaseAuth.DefaultInstance;
return authInstance;
}
else
{
authInstance = FirebaseAuth.GetAuth(AppInstance);
return authInstance;
}
}
}
}
}