【发布时间】:2021-01-22 17:10:25
【问题描述】:
我正在使用带有 Firebase SDK 的 Unity,使用 Firebase 的 Auth 和 Firestore 实用程序。
我可以从我的客户端对我的 Firestore 数据库进行各种操作,所以现在我正在尝试实现一些客户端挂钩,所以当 Firestore 中的某些内容发生变化时,客户端将执行一个动作。
我构建这些侦听器的方式受到Firebase Documentation 的启发,这是我在发生变化时将侦听器设置为 Firestore 集合的方法示例:
//db == FirebaseFirestore.DefaultInstance;
public ListenerRegistration SetListenerToAllCollectionDocuments(string collectionID, Query query = null, Action OnSomeDocumentChange = null)
{
try
{
Query colRef = query ?? db.Collection(collectionID);
ListenerRegistration listener = colRef.Listen(colQuerySnapshot =>
{
Debug.Log("Listen changes on collection:" + collectionID);
OnSomeDocumentChange();
});
return listener;
}
catch (Exception e)
{
Debug.Log(e);
}
return null;
}
那我可以这样称呼它:
ListenerRegistration listener = Database.SetListenerToAllCollectionDocuments("users", null, () => { Debug.Log("Something Change"); });
如果我想禁用监听器参考。
到目前为止一切顺利,现在问题来了:
当数据库中的某些内容发生更改时,此侦听器会被正确调用,但是当我在设置侦听器时第一次调用方法 SetListenerToAllCollectionDocuments(); 时会调用 ALSO。
这应该是预期的行为吗?
在我看来,这应该只在 firestore 上的某些内容发生变化时调用,而不是在我创建侦听器时调用。我做错了什么?谢谢。
【问题讨论】:
-
您在链接上看到了吗:“C# 客户端库中尚不支持”
标签: c# firebase unity3d google-cloud-firestore listener