Skip to content

Commit b37922a

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Make LootLockerServerApi resettable for attribution handler
1 parent e2ce182 commit b37922a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Runtime/Client/LootLockerServerApi.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class LootLockerServerApi : MonoBehaviour
2121
private const int MaxRetries = 3;
2222
private int _tries;
2323

24-
public static LootLockerServerApi GetInstance()
24+
public static void Instantiate()
2525
{
2626
if (_instance == null)
2727
{
@@ -30,10 +30,9 @@ public static LootLockerServerApi GetInstance()
3030
if (Application.isPlaying)
3131
DontDestroyOnLoad(_instance.gameObject);
3232
}
33-
return _instance;
3433
}
3534

36-
private static void DestroyInstance()
35+
public static void Reset()
3736
{
3837
if (_instance == null) return;
3938
Destroy(_instance.gameObject);
@@ -44,13 +43,18 @@ private static void DestroyInstance()
4443
[InitializeOnEnterPlayMode]
4544
static void OnEnterPlaymodeInEditor(EnterPlayModeOptions options)
4645
{
47-
DestroyInstance();
46+
Reset();
4847
}
4948
#endif
5049

5150
public static void SendRequest(LootLockerServerRequest request, Action<LootLockerResponse> OnServerResponse = null)
5251
{
53-
GetInstance()._SendRequest(request, OnServerResponse);
52+
if (_instance == null)
53+
{
54+
Instantiate();
55+
}
56+
57+
_instance._SendRequest(request, OnServerResponse);
5458
}
5559

5660
private void _SendRequest(LootLockerServerRequest request, Action<LootLockerResponse> OnServerResponse = null)

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static string GetCurrentPlatform()
3535
static bool initialized;
3636
static bool Init()
3737
{
38-
LootLockerServerApi.GetInstance();
38+
LootLockerServerApi.Instantiate();
3939
return LoadConfig();
4040
}
4141

@@ -48,7 +48,7 @@ static bool Init()
4848
/// <returns>True if initialized successfully, false otherwise</returns>
4949
public static bool Init(string apiKey, string gameVersion, string domainKey)
5050
{
51-
LootLockerServerApi.GetInstance();
51+
LootLockerServerApi.Instantiate();
5252
return LootLockerConfig.CreateNewSettings(apiKey, gameVersion, domainKey);
5353
}
5454

0 commit comments

Comments
 (0)