Skip to content

Commit ab95e1e

Browse files
author
Mikkel Sørensen
committed
Implement automatic refreshing when calling our api
1 parent 4b95200 commit ab95e1e

14 files changed

+121
-100
lines changed
28 KB
Loading

Runtime/Editor/Icons/hector-transparent-100.png.meta renamed to Runtime/Editor/Icons/Hector_512x512g.png.meta

Lines changed: 2 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-181 KB
Binary file not shown.

Runtime/Editor/StoredUser.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.IO;
44
using UnityEditor;
55
using UnityEngine;
6-
6+
#if (UNITY_EDITOR)
77
public class StoredUser : ScriptableObject
88
{
9+
10+
911
[HideInInspector]
1012
public User user = null;
1113

@@ -18,7 +20,6 @@ private void Deserialize()
1820
{
1921
user = LootLockerJson.DeserializeObject<User>(serializedUser);
2022
}
21-
2223
}
2324

2425
private void Serialize()
@@ -37,25 +38,27 @@ private static StoredUser Get()
3738
{
3839
return _current;
3940
}
40-
_current = Resources.Load<StoredUser>("Config/LootLockerUser");
41+
_current = Resources.Load<StoredUser>("/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser");
4142

4243
#if UNITY_EDITOR
4344

4445
if (_current == null)
4546
{
4647
StoredUser newUser = CreateInstance<StoredUser>();
4748

48-
string dir = Application.dataPath + "/LootLockerSDK/Resources/Config";
49+
string dir = Application.dataPath + "/LootLockerSDK/Runtime/Editor/Resources/Config";
4950

5051
// If directory does not exist, create it
5152
if (!Directory.Exists(dir))
5253
{
5354
Directory.CreateDirectory(dir);
5455
}
55-
string configAssetPath = "Assets/LootLockerSDK/Resources/Config/LootLockerUser.asset";
56+
string configAssetPath = "Assets/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser.asset";
5657
AssetDatabase.CreateAsset(newUser, configAssetPath);
5758
EditorApplication.delayCall += AssetDatabase.SaveAssets;
5859
AssetDatabase.Refresh();
60+
61+
_current = newUser;
5962
}
6063
#endif
6164
_current.Deserialize();
@@ -77,6 +80,26 @@ public static StoredUser current
7780
}
7881
}
7982

83+
public bool RemoveUser()
84+
{
85+
_current.serializedUser = null;
86+
_current.user = null;
87+
_current = null;
88+
string configAssetPath = Application.dataPath + "/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser.asset";
89+
string configAssetMetaPath = Application.dataPath + "/LootLockerSDK/Runtime/Editor/Resources/Config/LootLockerUser.asset.meta";
90+
91+
if (Directory.Exists(configAssetPath))
92+
{
93+
File.Delete(configAssetPath);
94+
}
95+
if (Directory.Exists(configAssetMetaPath))
96+
{
97+
File.Delete(configAssetMetaPath);
98+
}
99+
AssetDatabase.Refresh();
100+
101+
return true;
102+
}
80103
public static bool CreateNewUser(User _user)
81104
{
82105
current.user = _user;
@@ -85,3 +108,4 @@ public static bool CreateNewUser(User _user)
85108
}
86109

87110
}
111+
#endif

Runtime/Editor/StoredUser.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Editor/VisualElements.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Editor/VisualElements/LootLocker MFA/LootLockerMFA.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using UnityEditor;
22
using UnityEngine;
33
using UnityEngine.UIElements;
4-
using LootLocker.Admin;
54
using LootLocker;
6-
#if UNITY_2021_3_OR_NEWER
5+
#if UNITY_2021_3_OR_NEWER && UNITY_EDITOR
6+
using LootLocker.Admin;
7+
78
public class LootLockerMFA : EditorWindow
89
{
910
[SerializeField]
@@ -36,6 +37,8 @@ public void CreateGUI()
3637

3738
public void RunMFA(EventBase e)
3839
{
40+
EditorApplication.update = OnEditorUpdate;
41+
3942
LootLockerAdminManager.MFAAuthenticate(EditorPrefs.GetString("LootLocker.mfaKey"), i_secretcode.value, (onComplete) =>
4043
{
4144
if (onComplete.success)
@@ -49,7 +52,15 @@ public void RunMFA(EventBase e)
4952
EditorPrefs.DeleteKey("LootLocker.mfaKey");
5053
Close();
5154
}
55+
EditorApplication.update -= OnEditorUpdate;
56+
5257
});
5358
}
59+
60+
private void OnEditorUpdate()
61+
{
62+
EditorApplication.QueuePlayerLoopUpdate();
63+
}
64+
5465
}
5566
#endif

Runtime/Editor/VisualElements/LootLocker MFA/LootLockerMFA.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ui:VisualElement style="flex-grow: 1; align-items: auto; align-self: auto; justify-content: flex-start;">
33
<ui:Label tabindex="-1" text="Verification" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" focusable="true" style="align-self: center; font-size: 24px; margin-top: 20px;" />
44
<ui:VisualElement style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); align-self: center; margin-top: 20px; padding-left: 90px; padding-right: 90px; padding-bottom: 0; height: 60px;">
5-
<ui:Label tabindex="-1" text="Authentication Code:" parse-escape-sequences="true" display-tooltip-when-elided="true" name="InputHeader" style="align-self: flex-start; color: rgb(164, 164, 164); margin-top: 2px; margin-right: 2px; align-items: flex-start; padding-right: 4px; width: auto; max-width: 300px; margin-bottom: 5px; justify-content: flex-start; -unity-font: url(&apos;project://database/Assets/LootLockerSDK/Runtime/Editor/Fonts/CircularStd-Book.ttf?fileID=12800000&amp;guid=71915b8f359a7e7429b11ca3970c3f24&amp;type=3#CircularStd-Book&apos;); -unity-font-style: normal;" />
5+
<ui:Label tabindex="-1" text="Authentication Code:" parse-escape-sequences="true" display-tooltip-when-elided="true" name="InputHeader" style="align-self: flex-start; color: rgb(164, 164, 164); margin-top: 2px; margin-right: 2px; align-items: flex-start; padding-right: 4px; width: auto; max-width: 300px; margin-bottom: 5px; justify-content: flex-start; -unity-font-style: normal;" />
66
<ui:TextField picking-mode="Ignore" name="inputmfa" keyboard-type="EmailAddress" value="000000" style="margin-right: 0; margin-left: 0; margin-bottom: 5px; align-self: auto; justify-content: flex-start; max-height: 60px; max-width: 100%; width: auto; min-width: 100%; min-height: 20px; height: 35px; font-size: 16px; -unity-text-align: upper-left; text-overflow: clip; flex-grow: 1;" />
77
</ui:VisualElement>
88
<ui:Button text="Send" parse-escape-sequences="true" display-tooltip-when-elided="true" name="btnsend" style="align-self: center; margin-top: 10px; width: 80px; height: 40px; font-size: 18px;" />

Runtime/Editor/VisualElements/LootLocker MainWindow/LootLockerMainWindow.cs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using UnityEditor;
22
using UnityEngine;
33
using UnityEngine.UIElements;
4-
using LootLocker.Admin;
54
using LootLocker.Extension.Requests;
65
using LootLocker;
76
using System.Linq;
8-
#if UNITY_2021_3_OR_NEWER
7+
#if UNITY_EDITOR && UNITY_2021_3_OR_NEWER
8+
using LootLocker.Admin;
99

1010
public class LootLockerMainWindow : EditorWindow
1111
{
@@ -29,7 +29,6 @@ public enum ContentType
2929
}
3030

3131
Page currentPage;
32-
ContentType currentContent;
3332

3433
private User activeUser;
3534
private Organisation activeOrganisation;
@@ -39,35 +38,28 @@ public enum ContentType
3938
[SerializeField]
4039
private VisualTreeAsset m_VisualTreeAsset = default;
4140

42-
private VisualElement tabWindow;
43-
44-
private ScrollView optionList;
45-
46-
private Label listHeader, gameTitle, userName;
47-
48-
private Label activeWindowLabel;
41+
private VisualElement tabWindow, root;
42+
43+
private StyleSheet sheet;
4944

45+
private Label listHeader, gameTitle, userName, activeWindowLabel;
5046

5147
private DropdownField keyEnvironment, gameEnvironment;
5248

5349
private TextField keyName;
5450

55-
private ScrollView keyList;
56-
57-
private Button createKeyButton;
58-
59-
60-
61-
62-
bool writeUpdates = false;
63-
64-
private VisualElement root;
65-
66-
private Button returnBtn;
51+
private ScrollView keyList, optionList;
6752

68-
StyleSheet sheet;
53+
private Button createKeyButton, returnBtn;
54+
55+
[MenuItem("LootLocker/Logout", priority = 10)]
56+
public static void Logout()
57+
{
58+
EditorPrefs.DeleteAll();
59+
StoredUser.current.RemoveUser();
60+
}
6961

70-
[MenuItem("LootLocker/Settings")]
62+
[MenuItem("LootLocker/Settings", priority = 1)]
7163
public static void OpenMenu()
7264
{
7365

@@ -81,7 +73,6 @@ public static void OpenMenu()
8173
else
8274
{
8375
LootLockerWizard.LoadLogin();
84-
8576
}
8677

8778
}
@@ -116,12 +107,10 @@ public void LoadLootLockerMainMenu(User user)
116107
if (user.organisations.Length <= 1 || hasOrganisationBeenConfigured)
117108
{
118109
PopulateList(ContentType.Games);
119-
currentContent = ContentType.Games;
120110
}
121111
else
122112
{
123113
PopulateList(ContentType.Organisations);
124-
currentContent = ContentType.Organisations;
125114
}
126115
}
127116

@@ -167,16 +156,12 @@ public void CreateGUI()
167156
root.styleSheets.Add(sheet);
168157
}
169158

159+
160+
170161
private void Update()
171162
{
172163
returnBtn.style.display = currentPage == Page.OrganisationPage ? DisplayStyle.None : DisplayStyle.Flex;
173164

174-
if (writeUpdates)
175-
{
176-
keyList.Clear();
177-
OpenMenu();
178-
writeUpdates = false;
179-
}
180165
}
181166

182167
void Return(EventBase e)
@@ -222,7 +207,7 @@ private void OpenAPIKeyTab()
222207
activeWindowLabel.style.display = DisplayStyle.Flex;
223208
activeWindowLabel.text = " - API Keys";
224209

225-
writeUpdates = true;
210+
EditorApplication.update += OnEditorUpdate;
226211
LootLockerAdminManager.GetAllKeys(activeGame.id.ToString(), (onComplete) =>
227212
{
228213
if (onComplete.success)
@@ -232,6 +217,7 @@ private void OpenAPIKeyTab()
232217
CreateAPIKeyTemplate(key);
233218
}
234219
}
220+
EditorApplication.update -= OnEditorUpdate;
235221
});
236222
}
237223

@@ -243,6 +229,8 @@ public void CreateKey()
243229
{
244230
gameEnv = activeGame.development.id;
245231
}
232+
233+
EditorApplication.update += OnEditorUpdate;
246234

247235
LootLockerAdminManager.GenerateKey(gameEnv.ToString(), keyName.value, keyEnvironment.value.ToLower(), (onComplete) =>
248236
{
@@ -251,9 +239,14 @@ public void CreateKey()
251239
CreateAPIKeyTemplate(onComplete);
252240
Repaint();
253241
}
242+
EditorApplication.update -= OnEditorUpdate;
254243
});
255244
}
256245

246+
void OnEditorUpdate()
247+
{
248+
EditorApplication.QueuePlayerLoopUpdate();
249+
}
257250

258251
public void ApplyKeyClicked(EventBase e)
259252
{
@@ -490,6 +483,8 @@ public void GameButtonClicked(EventBase e)
490483

491484
public void GetUserRole()
492485
{
486+
EditorApplication.update += OnEditorUpdate;
487+
493488
LootLockerAdminManager.GetUserRole(activeUser.id.ToString(), (onComplete) =>
494489
{
495490
if (onComplete.success)
@@ -499,6 +494,8 @@ public void GetUserRole()
499494
userName.text += "\n" + " - " + perm;
500495
}
501496
}
497+
EditorApplication.update -= OnEditorUpdate;
498+
502499
});
503500
}
504501
}

0 commit comments

Comments
 (0)