-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteConfigEditor.cs
More file actions
111 lines (90 loc) · 3.74 KB
/
RemoteConfigEditor.cs
File metadata and controls
111 lines (90 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#if UNITY_EDITOR
using System;
using Firebase;
using UnityEditor;
using UnityEngine;
using Firebase.RemoteConfig;
using System.Threading.Tasks;
namespace RimuruDev
{
public sealed class RemoteConfigEditor : EditorWindow
{
private string log;
private bool firebaseInitialized;
[MenuItem("RimuruDev Tools/Firebase RemoteConfig Editor")]
private static void ShowWindow() =>
GetWindow<RemoteConfigEditor>("RemoteConfig Editor");
private async void OnEnable()
{
try
{
var result = await FirebaseApp.CheckAndFixDependenciesAsync();
if (result == DependencyStatus.Available)
{
firebaseInitialized = true;
log += "\nFirebase initialized in Editor";
}
else
{
log += $"\nCould not resolve Firebase dependencies: {result}";
}
}
catch (Exception e)
{
Debug.LogError($"TODO: handle exception");
}
}
private void OnGUI()
{
GUILayout.Label("Remote Config Editor", EditorStyles.boldLabel);
GUILayout.Label(log, EditorStyles.wordWrappedLabel);
EditorGUI.BeginDisabledGroup(!firebaseInitialized);
if (GUILayout.Button("Print RemoteConfig Cache"))
FirebaseRemoteConfigHelper.PrintRemoteConfigCache();
if (GUILayout.Button("Restart Firebase and Fetch Remote Config"))
_ = RestartFirebaseAndFetchAsync();
EditorGUI.EndDisabledGroup();
}
private async Task RestartFirebaseAndFetchAsync()
{
try
{
FirebaseRemoteConfigHelper.PrintRemoteConfigCache();
FirebaseRemoteConfigHelper.ClearRemoteConfigCache();
FirebaseAppHelper.DisposeAllFirebaseApps();
// NOTE: Ну я на всякий пожарный подожду, мало ли не успеет прогреться :D
await Task.Delay(500);
var result = await FirebaseApp.CheckAndFixDependenciesAsync();
if (result != DependencyStatus.Available)
{
log += $"\nCould not reinitialize Firebase: {result}";
Repaint();
return;
}
firebaseInitialized = true;
log += "\nFirebase reinitialized in Editor";
// NOTE: Прогрев перед подтягиванием свежачка с сервачка :3
var config = FirebaseRemoteConfig.DefaultInstance;
var settings = config.ConfigSettings;
settings.MinimumFetchIntervalInMilliseconds = 0;
settings.FetchTimeoutInMilliseconds = 30000;
await config.SetConfigSettingsAsync(settings);
await config.EnsureInitializedAsync();
// NOTE: Получаем свежачок, и кайфуем.
await config.FetchAsync(TimeSpan.Zero);
await config.ActivateAsync();
// NOTE: Мега лень париться с StringBuilder, один-фиг редактор.
log += $"\nFetch succeeded! Time: {config.Info.FetchTime}";
log += $"\nAll values count: {config.AllValues.Count}";
foreach (var pair in config.AllValues)
log += $"\n[ Key: {pair.Key} | Value: {pair.Value.StringValue} ]";
}
catch (Exception e)
{
log += $"\nRestart/Fetch failed: {e}";
}
Repaint();
}
}
}
#endif