From f57d6086dad50d1ad773e6066e3873242d21b4dc Mon Sep 17 00:00:00 2001 From: Patrick Martin Date: Mon, 5 Apr 2021 17:15:52 -0600 Subject: [PATCH 1/2] Updated calls to RemoteConfig and RealtimeDatabase so the project now compiles RemoteConfig moved to RemoteConfigDeprecated instances of Firebase.Unity.Editor removed --- Firebase_Leaderboard/Demo/DemoUIController.cs | 18 ++++++------- .../Scripts/LeaderboardController.cs | 27 ------------------- .../Scripts/RemoteConfigSyncBehaviour.cs | 2 +- Scripts/FirebaseInitializer.cs | 10 +++---- 4 files changed, 14 insertions(+), 43 deletions(-) diff --git a/Firebase_Leaderboard/Demo/DemoUIController.cs b/Firebase_Leaderboard/Demo/DemoUIController.cs index 0191bab..f095b59 100644 --- a/Firebase_Leaderboard/Demo/DemoUIController.cs +++ b/Firebase_Leaderboard/Demo/DemoUIController.cs @@ -14,23 +14,21 @@ You may obtain a copy of the License at limitations under the License. **/ -using Firebase; -using Firebase.Database; using Firebase.Unity; -using Firebase.Unity.Editor; + using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using UnityEngine; using UnityEngine.UI; -namespace Firebase.Leaderboard.Demo { - /// - /// This class controls the UI in the demo scene, responding to events and updating - /// elements of the UI as events occur. - /// - public class DemoUIController : MonoBehaviour { +namespace Firebase.Leaderboard.Demo +{ + /// + /// This class controls the UI in the demo scene, responding to events and updating + /// elements of the UI as events occur. + /// + public class DemoUIController : MonoBehaviour { /// /// When adding batch scores, occasionally populate the UserIDInput and ScoreInput /// with one of the scores generated. For display purposes only. diff --git a/Firebase_Leaderboard/Scripts/LeaderboardController.cs b/Firebase_Leaderboard/Scripts/LeaderboardController.cs index 3d1c459..b144137 100644 --- a/Firebase_Leaderboard/Scripts/LeaderboardController.cs +++ b/Firebase_Leaderboard/Scripts/LeaderboardController.cs @@ -16,7 +16,6 @@ limitations under the License. using Firebase.Database; using Firebase.Unity; -using Firebase.Unity.Editor; using System; using System.Collections; using System.Collections.Generic; @@ -36,23 +35,6 @@ public class LeaderboardController : MonoBehaviour { /// public bool EditorAuth = true; - /// - /// Location of Editor P12 file. This must be in a base folder called "Editor Default - /// Resources." See instructions at - /// https://firebase.google.com/docs/database/unity/start#optional_editor_setup_for_restricted_access. - /// - public string EditorP12FileName; - - /// - /// Service account email used for Editor authentication after generating the P12 key file. - /// - public string EditorServiceAccountEmail; - - /// - /// Password created along with P12 key file in authentication process. - /// - public string EditorP12Password; - /// /// Subscribe to be notified when the database has been initialized. /// @@ -251,15 +233,6 @@ private void Update() { if (!initialized) { if (readyToInitialize) { FirebaseApp app = FirebaseApp.DefaultInstance; - if (EditorAuth) { - app.SetEditorP12FileName(EditorP12FileName); - app.SetEditorServiceAccountEmail(EditorServiceAccountEmail); - app.SetEditorP12Password(EditorP12Password); - } - - if (app.Options.DatabaseUrl != null) { - app.SetEditorDatabaseUrl(app.Options.DatabaseUrl); - } dbref = FirebaseDatabase.DefaultInstance.RootReference; initialized = true; diff --git a/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs b/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs index 14aec23..1417ddb 100644 --- a/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs +++ b/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs @@ -141,7 +141,7 @@ public IEnumerator SyncFieldsCR() { var sourceObject = kv.Key; var targets = kv.Value; foreach (var target in targets) { - var value = FirebaseRemoteConfig.GetValue(target.FullKeyString); + var value = FirebaseRemoteConfigDeprecated.GetValue(target.FullKeyString); if (value.Source == ValueSource.RemoteValue) { if (target.Field.GetValue(sourceObject)?.ToString() == value.StringValue) { continue; diff --git a/Scripts/FirebaseInitializer.cs b/Scripts/FirebaseInitializer.cs index 14a2d54..c62ac3c 100644 --- a/Scripts/FirebaseInitializer.cs +++ b/Scripts/FirebaseInitializer.cs @@ -74,9 +74,9 @@ public static void RemoteConfigActivateFetched(Action callback, bool forceRefres } if (!fetching) { #if UNITY_EDITOR - var settings = FirebaseRemoteConfig.Settings; + var settings = FirebaseRemoteConfigDeprecated.Settings; settings.IsDeveloperMode = true; - FirebaseRemoteConfig.Settings = settings; + FirebaseRemoteConfigDeprecated.Settings = settings; #endif // Get the default values from the current SyncTargets. var syncObjects = Resources.FindObjectsOfTypeAll(); @@ -87,12 +87,12 @@ public static void RemoteConfigActivateFetched(Action callback, bool forceRefres } Initialize(status => { - FirebaseRemoteConfig.SetDefaults(defaultValues); - FirebaseRemoteConfig.FetchAsync(TimeSpan.Zero).ContinueWith(task => { + FirebaseRemoteConfigDeprecated.SetDefaults(defaultValues); + FirebaseRemoteConfigDeprecated.FetchAsync(TimeSpan.Zero).ContinueWith(task => { lock (activateFetchCallbacks) { fetching = false; activateFetched = true; - var newlyActivated = FirebaseRemoteConfig.ActivateFetched(); + var newlyActivated = FirebaseRemoteConfigDeprecated.ActivateFetched(); CallActivateFetchedCallbacks(); } }); From 36bf8227aa8c4ad17a20b5fd898b00890a7e3990 Mon Sep 17 00:00:00 2001 From: Patrick Martin Date: Mon, 12 Apr 2021 17:10:09 -0600 Subject: [PATCH 2/2] Moved remote config to the new api (instance based) In FirebaseInitializer, removed the fetching variable. It seemed to only matter if fetching was ever set to true, and it never was. --- .../Scripts/RemoteConfigSyncBehaviour.cs | 5 ++- Scripts/FirebaseInitializer.cs | 42 ++++++++----------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs b/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs index 1417ddb..0618d59 100644 --- a/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs +++ b/Firebase_RemoteConfig/Scripts/RemoteConfigSyncBehaviour.cs @@ -137,11 +137,14 @@ public IEnumerator SyncFieldsCR() { Debug.LogWarning($"No sync targets found for {name}"); yield break; } + + var remoteConfig = FirebaseRemoteConfig.DefaultInstance; + foreach (var kv in flattenedTargets) { var sourceObject = kv.Key; var targets = kv.Value; foreach (var target in targets) { - var value = FirebaseRemoteConfigDeprecated.GetValue(target.FullKeyString); + var value = remoteConfig.GetValue(target.FullKeyString); if (value.Source == ValueSource.RemoteValue) { if (target.Field.GetValue(sourceObject)?.ToString() == value.StringValue) { continue; diff --git a/Scripts/FirebaseInitializer.cs b/Scripts/FirebaseInitializer.cs index c62ac3c..44adbd4 100644 --- a/Scripts/FirebaseInitializer.cs +++ b/Scripts/FirebaseInitializer.cs @@ -32,7 +32,6 @@ public static class FirebaseInitializer { private static List activateFetchCallbacks = new List(); private static DependencyStatus dependencyStatus; private static bool initialized = false; - private static bool fetching = false; private static bool activateFetched = false; /// @@ -72,32 +71,27 @@ public static void RemoteConfigActivateFetched(Action callback, bool forceRefres } else { activateFetchCallbacks.Add(callback); } - if (!fetching) { -#if UNITY_EDITOR - var settings = FirebaseRemoteConfigDeprecated.Settings; - settings.IsDeveloperMode = true; - FirebaseRemoteConfigDeprecated.Settings = settings; -#endif - // Get the default values from the current SyncTargets. - var syncObjects = Resources.FindObjectsOfTypeAll(); - var syncTargets = SyncTargetManager.FindTargets(syncObjects).GetFlattenedTargets(); - var defaultValues = new Dictionary(); - foreach (var target in syncTargets.Values) { - defaultValues[target.FullKeyString] = target.Value; - } + + // Get the default values from the current SyncTargets. + var syncObjects = Resources.FindObjectsOfTypeAll(); + var syncTargets = SyncTargetManager.FindTargets(syncObjects).GetFlattenedTargets(); + var defaultValues = new Dictionary(); + foreach (var target in syncTargets.Values) { + defaultValues[target.FullKeyString] = target.Value; + } - Initialize(status => { - FirebaseRemoteConfigDeprecated.SetDefaults(defaultValues); - FirebaseRemoteConfigDeprecated.FetchAsync(TimeSpan.Zero).ContinueWith(task => { + Initialize(status => { + var remoteConfig = FirebaseRemoteConfig.DefaultInstance; + remoteConfig.SetDefaultsAsync(defaultValues) + .ContinueWith(_=>{ + remoteConfig.FetchAndActivateAsync().ContinueWith(_=>{ lock (activateFetchCallbacks) { - fetching = false; - activateFetched = true; - var newlyActivated = FirebaseRemoteConfigDeprecated.ActivateFetched(); - CallActivateFetchedCallbacks(); - } + activateFetched = true; + CallActivateFetchedCallbacks(); + } + }); }); - }); - } + }); } }