Skip to content

Commit 88f72c5

Browse files
committed
Added new calls for UGC and restructured classes
1 parent bc5068e commit 88f72c5

24 files changed

+183
-153
lines changed

Assets/LootLocker/Admin/Editor/LootLockerSDKAdminManager.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,26 @@ static bool LoadConfig()
4343
public static void DebugMessage(string message, bool IsError = false)
4444
{
4545
#if UNITY_EDITOR
46-
if (IsError)
47-
Debug.LogError(message);
48-
else
49-
Debug.Log(message);
46+
#if UNITY_EDITOR
47+
if (LootLockerAdminConfig.current != null && LootLockerAdminConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.All)
48+
{
49+
if (IsError)
50+
Debug.LogError(message);
51+
else
52+
Debug.Log(message);
53+
}
54+
else if (LootLockerAdminConfig.current != null && LootLockerAdminConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.ErrorOnly)
55+
{
56+
if (IsError)
57+
Debug.LogError(message);
58+
}
59+
else if (LootLockerAdminConfig.current != null && LootLockerAdminConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.NormalOnly)
60+
{
61+
if (!IsError)
62+
Debug.LogError(message);
63+
}
64+
#endif
65+
5066
#endif
5167
}
5268

Assets/LootLocker/Common/BaseServerAPI.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UnityEngine.SceneManagement;
99
using UnityEngine.Events;
1010
using System.Net;
11+
using LootLockerRequests;
1112

1213
namespace enums
1314
{
@@ -67,7 +68,7 @@ IEnumerator coroutine()
6768
//Build the URL that we will hit based on the specified endpoint, query params, etc
6869
string url = BuildURL(request.endpoint, request.queryParams);
6970
#if UNITY_EDITOR
70-
Debug.Log("ServerRequest URL: " + url);
71+
LootLockerSDKManager.DebugMessage("ServerRequest URL: " + url);
7172
#endif
7273

7374
using (UnityWebRequest webRequest = CreateWebRequest(url, request))
@@ -83,7 +84,7 @@ IEnumerator coroutine()
8384
yield return null;
8485
if (Time.time - startTime >= maxTimeOut)
8586
{
86-
Debug.LogError("ERROR: Exceeded maxTimeOut waiting for a response from " + request.httpMethod.ToString() + " " + url);
87+
LootLockerSDKManager.DebugMessage("ERROR: Exceeded maxTimeOut waiting for a response from " + request.httpMethod.ToString() + " " + url);
8788
yield break;
8889
}
8990
}
@@ -97,17 +98,14 @@ IEnumerator coroutine()
9798
try
9899
{
99100
#if UNITY_EDITOR
100-
Debug.Log("Server Response: " + request.httpMethod + " " + request.endpoint + " completed in " + (Time.time - startTime).ToString("n4") + " secs.\nResponse: " + webRequest.downloadHandler.text);
101+
LootLockerSDKManager.DebugMessage("Server Response: " + request.httpMethod + " " + request.endpoint + " completed in " + (Time.time - startTime).ToString("n4") + " secs.\nResponse: " + webRequest.downloadHandler.text);
101102
#endif
102103
}
103104
catch
104105
{
105-
Debug.LogError(request);
106-
Debug.LogError(request.httpMethod);
107-
Debug.LogError(request.endpoint);
108-
Debug.LogError(webRequest);
109-
Debug.LogError(webRequest.downloadHandler);
110-
Debug.LogError(webRequest.downloadHandler.text);
106+
LootLockerSDKManager.DebugMessage(request.httpMethod.ToString(),true);
107+
LootLockerSDKManager.DebugMessage(request.endpoint,true);
108+
LootLockerSDKManager.DebugMessage(webRequest.downloadHandler.text,true);
111109
}
112110

113111
LootLockerResponse response = new LootLockerResponse();
@@ -153,8 +151,8 @@ IEnumerator coroutine()
153151
response.Error = "Service Unavailable -- We're either offline for maintenance, or an error that should be solvable by calling again later was triggered.";
154152
break;
155153
}
156-
#if UNITY_EDIROR
157-
Debug.Log("Response code: " + webRequest.responseCode);
154+
#if UNITY_EDITOR
155+
LootLockerSDKManager.DebugMessage("Response code: " + webRequest.responseCode);
158156
#endif
159157
if (webRequest.responseCode != 401)
160158
{
@@ -229,7 +227,7 @@ protected IEnumerator DoDownloadTexture2D(string url, System.Action<Texture2D> O
229227

230228
if (texture == null)
231229
{
232-
Debug.LogError("Texture download failed for: " + url);
230+
LootLockerSDKManager.DebugMessage("Texture download failed for: " + url,true);
233231
}
234232

235233
OnComplete?.Invoke(texture);
@@ -278,8 +276,8 @@ UnityWebRequest CreateWebRequest(string url, ServerRequest request)
278276
else
279277
{
280278
string json = (request.payload != null && request.payload.Count > 0) ? JsonConvert.SerializeObject(request.payload) : request.jsonPayload;
281-
#if UNITY_EDIROR
282-
Debug.Log("REQUEST BODY = " + json);
279+
#if UNITY_EDITOR
280+
LootLockerSDKManager.DebugMessage("REQUEST BODY = " + json);
283281
#endif
284282
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(string.IsNullOrEmpty(json) ? "{}" : json);
285283
webRequest = UnityWebRequest.Put(url, bytes);

Assets/LootLocker/Common/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class LootLockerEndPoints : ScriptableObject
8989
[Header("UGC")]
9090
public EndPointClass creatingAnAssetCandidate;
9191
public EndPointClass updatingAnAssetCandidate;
92+
public EndPointClass gettingASingleAssetCandidate;
9293
public EndPointClass deletingAnAssetCandidate;
9394
public EndPointClass listingAssetCandidates;
9495
public EndPointClass addingFilesToAssetCandidates;

Assets/LootLocker/Common/LootLockerGenericConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public enum platformType { android, ios, Steam, Windows }
3636
[HideInInspector]
3737
public string userUrl = "https://api.lootlocker.io/game";
3838

39+
public enum DebugLevel { All, ErrorOnly, NormalOnly, Off}
40+
41+
public DebugLevel currentDebugLevel;
42+
43+
3944
public void UpdateToken(string token, string deviceid)
4045
{
4146
this.deviceID = deviceid;

Assets/LootLocker/Common/LootlockerCommon.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public class Filter
7575
}
7676

7777

78-
public class Asset
78+
public class Asset: LootLockerResponse
7979
{
80+
public bool success;
8081
public int id { get; set; }
8182
public string name { get; set; }
8283
public bool active { get; set; }
@@ -99,13 +100,13 @@ public class Asset
99100
public bool popular { get; set; }
100101
public int popularity_score { get; set; }
101102
public bool unique_instance { get; set; }
102-
//public string external_identifiers { get; set; }
103103
public Rental_Options[] rental_options { get; set; }
104104
public Filter[] filters { get; set; }
105105
public Variation[] variations { get; set; }
106106
public bool featured { get; set; }
107107
public bool context_locked { get; set; }
108108
public bool initially_purchasable { get; set; }
109+
public File[] files { get; set; }
109110
}
110111

111112
public class File

Assets/LootLocker/Common/ServerRequest.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using Newtonsoft.Json;
55
using enums;
6+
using LootLockerRequests;
67

78
// using LootLockerAdmin;
89
// using LootLockerAdminRequests;
@@ -30,6 +31,7 @@ public enum HTTPMethod
3031
[System.Serializable]
3132
public class LootLockerResponse
3233
{
34+
3335
/// <summary>
3436
/// TRUE if http error OR server returns an error status
3537
/// </summary>
@@ -114,7 +116,7 @@ public static void CallAPI(string endPoint, HTTPMethod httpMethod, Dictionary<st
114116
public static void CallAPI(string endPoint, HTTPMethod httpMethod, string body = null, Action<LootLockerResponse> onComplete = null, bool useAuthToken = true, enums.CallerRole callerRole = enums.CallerRole.User)
115117
{
116118
#if UNITY_EDITOR
117-
Debug.Log("Caller Type: " + callerRole.ToString());
119+
LootLockerSDKManager.DebugMessage("Caller Type: " + callerRole.ToString());
118120
#endif
119121

120122
Dictionary<string, string> headers = new Dictionary<string, string>();
@@ -180,7 +182,7 @@ public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, by
180182

181183
if (this.payload != null && isNonPayloadMethod)
182184
{
183-
Debug.LogWarning("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
185+
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
184186
}
185187
}
186188
public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, byte[] upload = null, string uploadName = null, string uploadType = null, string body = null, Dictionary<string, string> extraHeaders = null, Dictionary<string, string> queryParams = null, bool useAuthToken = true, enums.CallerRole callerRole = enums.CallerRole.User)
@@ -201,7 +203,7 @@ public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, by
201203

202204
if (this.payload != null && isNonPayloadMethod)
203205
{
204-
Debug.LogWarning("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
206+
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
205207
}
206208
}
207209
public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, Dictionary<string, object> payload = null, Dictionary<string, string> extraHeaders = null, Dictionary<string, string> queryParams = null, bool useAuthToken = true, enums.CallerRole callerRole = enums.CallerRole.User)
@@ -221,7 +223,7 @@ public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, Di
221223
this.form = null;
222224
if (this.payload != null && isNonPayloadMethod)
223225
{
224-
Debug.LogWarning("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
226+
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
225227
}
226228
}
227229
public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, string payload = null, Dictionary<string, string> extraHeaders = null, Dictionary<string, string> queryParams = null, bool useAuthToken = true, enums.CallerRole callerRole = enums.CallerRole.User)
@@ -241,7 +243,7 @@ public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, st
241243
this.form = null;
242244
if (!string.IsNullOrEmpty(jsonPayload) && isNonPayloadMethod)
243245
{
244-
Debug.LogWarning("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
246+
LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint);
245247
}
246248
}
247249
#endregion
@@ -251,9 +253,6 @@ public ServerRequest(string endpoint, HTTPMethod httpMethod = HTTPMethod.GET, st
251253
/// </summary>
252254
public void Send(System.Action<LootLockerResponse> OnServerResponse)
253255
{
254-
#if UNITY_EDITOR
255-
Debug.Log("Sending Request: " + httpMethod.ToString() + " " + endpoint + " -- queryParams: " + jsonPayload);
256-
#endif
257256
BaseServerAPI.I.SendRequest(this, (response) =>
258257
{
259258
OnServerResponse?.Invoke(response);

Assets/LootLocker/Game/GameServerAPI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override void RefreshTokenAndCompleteCall(ServerRequest cacheServerReq
2828
{
2929
if (activeConfig != null && activeConfig.platform == LootLockerGenericConfig.platformType.Steam)
3030
{
31-
Debug.LogError("Token has expired, And token refresh not supported in Steam calls");
31+
LootLockerSDKManager.DebugMessage("Token has expired, And token refresh not supported in Steam calls", true);
3232
LootLockerResponse res = new LootLockerResponse();
3333
res.statusCode = 401;
3434
res.Error = "Token Expired";
@@ -53,7 +53,7 @@ protected override void RefreshTokenAndCompleteCall(ServerRequest cacheServerReq
5353
}
5454
else
5555
{
56-
Debug.LogError("Session refresh failed");
56+
LootLockerSDKManager.DebugMessage("Session refresh failed",true);
5757
LootLockerResponse res = new LootLockerResponse();
5858
res.statusCode = 401;
5959
res.Error = "Token Expired";
@@ -63,7 +63,7 @@ protected override void RefreshTokenAndCompleteCall(ServerRequest cacheServerReq
6363
}
6464
else
6565
{
66-
Debug.LogError("Session refresh failed");
66+
LootLockerSDKManager.DebugMessage("Session refresh failed",true);
6767
LootLockerResponse res = new LootLockerResponse();
6868
res.statusCode = 401;
6969
res.Error = "Token Expired";

Assets/LootLocker/Game/LootLockerSDKManager.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,23 @@ public static bool CheckInitialized()
7070
public static void DebugMessage(string message, bool IsError = false)
7171
{
7272
#if UNITY_EDITOR
73-
if (IsError)
74-
Debug.LogError(message);
75-
else
76-
Debug.Log(message);
73+
if(LootLockerConfig.current!=null && LootLockerConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.All)
74+
{
75+
if (IsError)
76+
Debug.LogError(message);
77+
else
78+
Debug.Log(message);
79+
}
80+
else if (LootLockerConfig.current != null && LootLockerConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.ErrorOnly)
81+
{
82+
if (IsError)
83+
Debug.LogError(message);
84+
}
85+
else if (LootLockerConfig.current != null && LootLockerConfig.current.currentDebugLevel == LootLockerGenericConfig.DebugLevel.NormalOnly)
86+
{
87+
if (!IsError)
88+
Debug.LogError(message);
89+
}
7790
#endif
7891
}
7992

@@ -380,7 +393,7 @@ public void ResetAssetCalls()
380393
AssetRequest.lastId = 0;
381394
}
382395

383-
public static void GetAssetInformation(string assetId, Action<AssetInformationResponse> onComplete)
396+
public static void GetAssetInformation(string assetId, Action<Asset> onComplete)
384397
{
385398
if (!CheckInitialized()) return;
386399
LootLockerGetRequest data = new LootLockerGetRequest();
@@ -606,6 +619,14 @@ public static void DeletingAnAssetCandidate(int assetId, Action<UserGenerateCont
606619
LootLockerAPIManager.DeletingAnAssetCandidate(data, onComplete);
607620
}
608621

622+
public static void GettingASingleAssetCandidate(int assetId, Action<UserGenerateContentResponse> onComplete)
623+
{
624+
if (!CheckInitialized()) return;
625+
LootLockerGetRequest data = new LootLockerGetRequest();
626+
data.getRequests.Add(assetId.ToString());
627+
LootLockerAPIManager.GettingASingleAssetCandidate(data, onComplete);
628+
}
629+
609630
public static void ListingAssetCandidates(Action<ListingAssetCandidatesResponse> onComplete)
610631
{
611632
if (!CheckInitialized()) return;

Assets/LootLocker/Game/Requests/AssetRequest.cs

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,6 @@ public class Context
2525
public object dependent_asset_id { get; set; }
2626
}
2727

28-
public class AssetInformationResponse : LootLockerResponse
29-
{
30-
public int id { get; set; }
31-
public string name { get; set; }
32-
public bool active { get; set; }
33-
public bool purchasable { get; set; }
34-
public string type { get; set; }
35-
public int price { get; set; }
36-
public object sales_price { get; set; }
37-
public object display_price { get; set; }
38-
public string context { get; set; }
39-
public object unlocks_context { get; set; }
40-
public bool detachable { get; set; }
41-
public string updated { get; set; }
42-
public object marked_new { get; set; }
43-
public int default_variation_id { get; set; }
44-
public Default_Loadouts_Info default_loadouts { get; set; }
45-
public string description { get; set; }
46-
public object links { get; set; }
47-
public object[] storage { get; set; }
48-
public object rarity { get; set; }
49-
public bool popular { get; set; }
50-
public int popularity_score { get; set; }
51-
public object package_contents { get; set; }
52-
public bool unique_instance { get; set; }
53-
public object external_identifiers { get; set; }
54-
public object rental_options { get; set; }
55-
public object[] filters { get; set; }
56-
public Variation_Info[] variations { get; set; }
57-
public bool featured { get; set; }
58-
public bool success { get; set; }
59-
}
60-
6128
public class FavouritesListResponse : LootLockerResponse
6229
{
6330
public bool success { get; set; }
@@ -194,20 +161,20 @@ public void ResetAssetCalls()
194161
AssetRequest.lastId = 0;
195162
}
196163

197-
public static void GetAssetInformation(LootLockerGetRequest data, Action<AssetInformationResponse> onComplete)
164+
public static void GetAssetInformation(LootLockerGetRequest data, Action<Asset> onComplete)
198165
{
199166
EndPointClass endPoint = LootLockerEndPoints.current.gettingAssetInformationForOneorMoreAssets;
200167

201168
string getVariable = string.Format(endPoint.endPoint, data.getRequests[0]);
202169

203170
ServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, onComplete: (serverResponse) =>
204171
{
205-
AssetInformationResponse response = new AssetInformationResponse();
172+
Asset response = new Asset();
206173
if (string.IsNullOrEmpty(serverResponse.Error))
207174
{
208175
LootLockerSDKManager.DebugMessage(serverResponse.text);
209176
//we get info for one or more assets so the passed asset info should be for only one of them and the whole json is not parsed correctly
210-
response = JsonConvert.DeserializeObject<AssetInformationResponse>(serverResponse.text);
177+
response = JsonConvert.DeserializeObject<Asset>(serverResponse.text);
211178
response.text = serverResponse.text;
212179
onComplete?.Invoke(response);
213180
}

0 commit comments

Comments
 (0)