18
18
using System . Collections . Generic ;
19
19
using System . Threading . Tasks ;
20
20
using Firebase . Extensions ;
21
+ using Firebase . RemoteConfig ;
21
22
22
23
namespace Hamster
23
24
{
@@ -178,7 +179,7 @@ private void InitializeFirebaseAndStartGame()
178
179
if ( dependencyStatus == Firebase . DependencyStatus . Available ) {
179
180
// Create and hold a reference to your FirebaseApp,
180
181
app = Firebase . FirebaseApp . DefaultInstance ;
181
- InitializeCommonDataAndStartGame ( ) ;
182
+ SetRemoteConfigDefaults ( ) ;
182
183
} else {
183
184
UnityEngine . Debug . LogError (
184
185
$ "Could not resolve all Firebase dependencies: { dependencyStatus } \n " +
@@ -191,21 +192,61 @@ private void InitializeFirebaseAndStartGame()
191
192
// before starting the game.
192
193
private void SetRemoteConfigDefaults ( )
193
194
{
194
- throw new System . NotImplementedException ( ) ;
195
+ var defaults = new System . Collections . Generic . Dictionary < string , object > ( ) ;
196
+ defaults . Add (
197
+ Hamster . MapObjects . AccelerationTile . AccelerationTileForceKey ,
198
+ Hamster . MapObjects . AccelerationTile . AccelerationTileForceDefault ) ;
199
+ defaults . Add (
200
+ Hamster . States . MainMenu . SubtitleOverrideKey ,
201
+ Hamster . States . MainMenu . SubtitleOverrideDefault ) ;
202
+ var remoteConfig = FirebaseRemoteConfig . DefaultInstance ;
203
+ remoteConfig . SetDefaultsAsync ( defaults ) . ContinueWithOnMainThread (
204
+ previousTask =>
205
+ {
206
+ FetchRemoteConfig ( InitializeCommonDataAndStartGame ) ;
207
+ }
208
+ ) ;
195
209
}
196
210
197
211
// (Re)fetches Remote Config values and pass down the onFetchAndActivateSuccessful callback.
198
212
// Called during the initialization flow but can also be called indepedently.
199
213
public void FetchRemoteConfig ( System . Action onFetchAndActivateSuccessful )
200
214
{
201
- throw new System . NotImplementedException ( ) ;
215
+ if ( app == null )
216
+ {
217
+ Debug . LogError ( $ "Do not use Firebase until it is properly initialized by calling { nameof ( InitializeFirebaseAndStartGame ) } .") ;
218
+ return ;
219
+ }
220
+
221
+ Debug . Log ( "Fetching data..." ) ;
222
+ var remoteConfig = FirebaseRemoteConfig . DefaultInstance ;
223
+ remoteConfig . FetchAsync ( System . TimeSpan . Zero ) . ContinueWithOnMainThread (
224
+ previousTask=>
225
+ {
226
+ if ( ! previousTask . IsCompleted )
227
+ {
228
+ Debug . LogError ( $ "{ nameof ( remoteConfig . FetchAsync ) } incomplete: Status '{ previousTask . Status } '") ;
229
+ return ;
230
+ }
231
+ ActivateRetrievedRemoteConfigValues ( onFetchAndActivateSuccessful ) ;
232
+ } ) ;
202
233
}
203
234
204
235
// The final method in the initialization flow that will activate fetched values
205
236
// and on Success will call onFetchAndActivateSuccessful.
206
237
private void ActivateRetrievedRemoteConfigValues ( System . Action onFetchAndActivateSuccessful )
207
238
{
208
- throw new System . NotImplementedException ( ) ;
239
+ var remoteConfig = FirebaseRemoteConfig . DefaultInstance ;
240
+ var info = remoteConfig . Info ;
241
+ if ( info . LastFetchStatus == LastFetchStatus . Success )
242
+ {
243
+ remoteConfig . ActivateAsync ( ) . ContinueWithOnMainThread (
244
+ previousTask =>
245
+ {
246
+ Debug . Log ( $ "Remote data loaded and ready (last fetch time { info . FetchTime } ).") ;
247
+ onFetchAndActivateSuccessful ( ) ;
248
+ } ) ;
249
+ }
209
250
}
210
251
}
211
252
}
0 commit comments