Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

Commit ef6101d

Browse files
author
Pim de Witte
committed
Merge pull request #1 from PimDeWitte/feature-enhancements
Feature enhancements
2 parents c27a27a + 52ba927 commit ef6101d

File tree

8 files changed

+95
-2
lines changed

8 files changed

+95
-2
lines changed

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ You will find the API is very similar to the Java/iOS versions except that:
4949
```
5050

5151
## Troubleshooting
52-
* You are not receiving events, its very likely you allowed your Firebase reference to GC.
52+
* If you are not receiving events, it can either be because your event response call contains an exception, or because Garbage Collection is removing the references to your firebase. You can solve this by storing the firebase objects in variables.
53+
54+
First, make sure you are referencing objects correctly.
5355

5456
Instead of this:
5557
```C#
@@ -61,6 +63,77 @@ You will find the API is very similar to the Java/iOS versions except that:
6163
classMember = new Firebase("mypath"); //holds a reference until the behavior is released
6264
classMember.ValueChanged += (...) => {...} ;
6365
```
66+
67+
But beware, if you are going to access child objects you need to store these in variables too, otherwise GC will delete the reference as well. So instead of this:
68+
```C#
69+
classMember = new Firebase("mypath"); //holds a reference until the behavior is released
70+
classMember.Child("somechild").ValueChanged += (...) => {...} ;
71+
```
72+
73+
do this
74+
75+
```C#
76+
IFirebase fb;
77+
IFirebase sampleChild;
78+
void someFunction() {
79+
fb = new Firebase("mypath"); //holds a reference until the behavior is released
80+
sampleChild = fb.Child("somechild"); // holds another child reference so GC doens't remove the reference to the child
81+
sampleChild.ValueChanged += (...) => {...} ;
82+
}
83+
```
84+
85+
If you are referencing objects correctly, you will likely need to re-open your Unity project because your event response function contained an error. At this moment an error in the event response function causes Firebase Unity to stop working during your entire Unity Editor session. You can debug this by catching the exception on the highest level, re-opening your Unity project, and running your scene again. You can now see the error and fix it. Note that you will need to re-open your project on every attempt until we fix this bug. After you have resolved your exception, your firebase event should be received normally again.
86+
87+
For example:
88+
```C#
89+
IFirebase fb;
90+
IFirebase sampleChild;
91+
void someFunction() {
92+
try {
93+
fb = new Firebase("mypath"); //holds a reference until the behavior is released
94+
sampleChild = fb.Child("somechild"); // holds another child reference so GC doens't remove the reference to the child
95+
sampleChild.ValueChanged += (...) => {...} ;
96+
someBadFunction();
97+
} catch(Exception e) {
98+
Debug.Log("Firebase Event Exception:");
99+
Debug.Log(e);
100+
}
101+
}
102+
```
103+
104+
* Threading: Unity does not allow game object modifications from any thread other than the Main thread. Firebase operates on a separate thread for performance reasons, and so you can not directly edit game objects from your firebase event responses. You can solve this by adding a Queue with actions to be fulfilled on the main thread. Create a new script inside Unity, add it to the game object you just added to the scene. Then insert this code.
105+
106+
```C#
107+
using UnityEngine;
108+
using System.Collections;
109+
using System.Collections.Generic;
110+
using System;
111+
112+
public class ExampleMainThreadQueue : MonoBehaviour {
113+
114+
public readonly static Queue<Action> ExecuteOnMainThread = new Queue<Action>();
115+
116+
public void Update()
117+
{
118+
// dispatch stuff on main thread
119+
while (ExecuteOnMainThread.Count > 0)
120+
{
121+
ExecuteOnMainThread.Dequeue().Invoke();
122+
}
123+
}
124+
}
125+
126+
```
127+
128+
You can now execute function on the main thread using coroutines.
129+
130+
```C#
131+
ExampleMainThreadQueue.ExecuteOnMainThread.Enqueue(() => {
132+
StartCoroutine(somecoroutine);
133+
} );
134+
```
135+
136+
64137
* iOS: XCode fails to link. Please follow instructions located at: https://www.firebase.com/docs/ios/alternate-setup.html You will need to do this again if you do a full build/replace from Unity, but an incremental build will keep these settings.
65138
* Mac: The plugin does not appear to be working at all for the player, but works for iOS and Android<p/>
66139
It could be that you have not installed the Java6 legacy runtime https://support.apple.com/kb/DL1572?locale=en_US

empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public void SetValue (IDictionary<string, object> value) {
106106
GetJavaObject().Call ("setValue", jsonObject);
107107
}
108108

109+
110+
public void SetJson (string jsonString) {
111+
AndroidJavaObject jsonObject = GetObjectMapper ().Call<AndroidJavaObject> ("readValue", jsonString, GetObjectClass ());
112+
GetJavaObject().Call ("setValue", jsonObject);
113+
}
114+
109115
public void SetValue (float value, string priority, Action<FirebaseError, IFirebase> listener)
110116
{
111117
GetJavaObject().Call ("setValue", new AndroidJavaObject ("java.lang.Float", value), priority, new CompletionListener(listener));

empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public void SetValue (string value)
148148
_FirebaseSetString (GetEditorObject (), value);
149149
}
150150

151+
152+
public void SetJsonValue (string json)
153+
{
154+
_FirebaseSetJson (GetEditorObject (), json);
155+
}
156+
151157
public void SetValue (IDictionary<string, object> value) {
152158
string jsonString = MiniJSON.Json.Serialize (value);
153159
_FirebaseSetJson (GetEditorObject (), jsonString);

empty-project/Assets/Plugins/Firebase/IFirebase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public interface IFirebase : IQuery
2828

2929
IFirebase Push ();
3030
void SetValue (string value);
31+
void SetJsonValue (string json);
3132
void SetValue (float value);
3233
void SetValue (IDictionary<string, object> value);
3334
void SetPriority (string priority);

empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ public void SetValue (string value)
163163
_FirebaseSetString (GetiOSObject (), value);
164164
}
165165

166+
public void SetJsonValue (string jsonString)
167+
{
168+
Debug.Log (jsonString);
169+
_FirebaseSetJson (GetiOSObject (), jsonString);
170+
}
171+
166172
public void SetValue (IDictionary<string, object> value) {
167173
string jsonString = MiniJSON.Json.Serialize (value);
168174
_FirebaseSetJson (GetiOSObject (), jsonString);

empty-project/Assets/TestScript.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void Start () {
3636
Debug.Log ("Child removed!");
3737
};
3838

39-
//firebase.SetValue ("working?");
39+
firebase.SetValue ("SetValue working?");
40+
firebase.SetJsonValue("{\"example_child\":{\"child_working\" : true}}");
4041
}
4142

4243
// Update is called once per frame
0 Bytes
Binary file not shown.

firebase.unitypackage

-2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)