Skip to content

Commit

Permalink
Added cloud firestore support. Fixed realtime database JSON post
Browse files Browse the repository at this point in the history
  • Loading branch information
rotolonico committed Sep 13, 2021
1 parent 50ae05b commit fd6f138
Show file tree
Hide file tree
Showing 37 changed files with 8,733 additions and 692 deletions.
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions .idea/.idea.FirebaseWebGL/.idea/aws.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 36 additions & 32 deletions .idea/.idea.FirebaseWebGL/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/.idea.FirebaseWebGL/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.FirebaseWebGL/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/.idea.FirebaseWebGL/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/.idea.FirebaseWebGL/.idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.FirebaseWebGL/.idea/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/.DS_Store
Binary file not shown.
Binary file added Assets/FirebaseWebGL/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/FirebaseWebGL/Examples/Firestore.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions Assets/FirebaseWebGL/Examples/Firestore/FirestoreExampleHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using FirebaseWebGL.Examples.Utils;
using FirebaseWebGL.Scripts.FirebaseBridge;
using FirebaseWebGL.Scripts.Objects;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace FirebaseWebGL.Examples.Firestore
{
public class FirestoreExampleHandler : MonoBehaviour
{
public TMP_InputField collectionPathInputField;
public TMP_InputField documentIdInputField;
public TMP_InputField valueInputField;

public TMP_InputField fieldIdInputField;
public Toggle includeMetadataUpdatesToggle;
public TMP_InputField incrementInputField;

public TextMeshProUGUI outputText;

private void Start()
{
if (Application.platform != RuntimePlatform.WebGLPlayer)
DisplayError("The code is not running on a WebGL build; as such, the Javascript functions will not be recognized.");
}

public void GetDocument() =>
FirebaseFirestore.GetDocument(collectionPathInputField.text, documentIdInputField.text, gameObject.name, "DisplayData", "DisplayErrorObject");

public void GetDocumentsInCollection() =>
FirebaseFirestore.GetDocumentsInCollection(collectionPathInputField.text, gameObject.name, "DisplayData", "DisplayErrorObject");

public void SetDocument() => FirebaseFirestore.SetDocument(collectionPathInputField.text, documentIdInputField.text, valueInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void AddDocument() => FirebaseFirestore.AddDocument(collectionPathInputField.text, valueInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void UpdateDocument() => FirebaseFirestore.UpdateDocument(collectionPathInputField.text, documentIdInputField.text, valueInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void DeleteDocument() => FirebaseFirestore.DeleteDocument(collectionPathInputField.text, documentIdInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void DeleteField() => FirebaseFirestore.DeleteField(collectionPathInputField.text, documentIdInputField.text, fieldIdInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void AddElementInArrayField() => FirebaseFirestore.AddElementInArrayField(collectionPathInputField.text, documentIdInputField.text, fieldIdInputField.text, valueInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void RemoveElementInArrayField() => FirebaseFirestore.RemoveElementInArrayField(collectionPathInputField.text, documentIdInputField.text, fieldIdInputField.text, valueInputField.text, gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void IncrementFieldValue() => FirebaseFirestore.IncrementFieldValue(collectionPathInputField.text, documentIdInputField.text, fieldIdInputField.text, int.Parse(incrementInputField.text), gameObject.name,
"DisplayInfo", "DisplayErrorObject");

public void ListenForDocumentChange() =>
FirebaseFirestore.ListenForDocumentChange(collectionPathInputField.text, documentIdInputField.text, includeMetadataUpdatesToggle.isOn, gameObject.name, "DisplayData", "DisplayErrorObject");

public void StopListeningForDocumentChange() => FirebaseFirestore.StopListeningForDocumentChange(collectionPathInputField.text, documentIdInputField.text, gameObject.name, "DisplayInfo", "DisplayErrorObject");

public void ListenForCollectionChange() =>
FirebaseFirestore.ListenForCollectionChange(collectionPathInputField.text, includeMetadataUpdatesToggle.isOn, gameObject.name, "DisplayData", "DisplayErrorObject");

public void StopListeningForCollectionChange() => FirebaseFirestore.StopListeningForCollectionChange(collectionPathInputField.text, gameObject.name, "DisplayInfo", "DisplayErrorObject");

public void DisplayData(string data)
{
outputText.color = outputText.color == Color.green ? Color.blue : Color.green;
outputText.text = data;
Debug.Log(data);
}

public void DisplayInfo(string info)
{
outputText.color = Color.white;
outputText.text = info;
Debug.Log(info);
}

public void DisplayErrorObject(string error)
{
var parsedError = StringSerializationAPI.Deserialize(typeof(FirebaseError), error) as FirebaseError;
DisplayError(parsedError.message);
}

public void DisplayError(string error)
{
outputText.color = Color.red;
outputText.text = error;
Debug.LogError(error);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd6f138

Please sign in to comment.