Skip to content

Commit 3791b72

Browse files
committed
Added new assets list support
1 parent 88f72c5 commit 3791b72

File tree

7 files changed

+121
-15
lines changed

7 files changed

+121
-15
lines changed

Assets/LootLocker/Common/LootLockerEndPoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class LootLockerEndPoints : ScriptableObject
6464
[Header("Assets")]
6565
public EndPointClass gettingContexts;
6666
public EndPointClass gettingAssetListWithCount;
67+
public EndPointClass gettingAssetListOriginal;
6768
public EndPointClass gettingAssetListWithAfterAndCount;
6869
public EndPointClass getAssetsById;
6970
public EndPointClass gettingAllAssets;

Assets/LootLocker/Common/LootlockerCommon.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
using System.Linq;
88
using UnityEngine.UI;
99

10+
namespace Enums
11+
{
12+
public enum AssetFilter { purchasable , nonpurchasable , rentable, nonrentable, popular , nonpopular, none }
13+
}
14+
1015
namespace LootLocker
1116
{
1217
public class Links
@@ -94,7 +99,6 @@ public class Asset: LootLockerResponse
9499
public int default_variation_id { get; set; }
95100
public string description { get; set; }
96101
public Links links { get; set; }
97-
98102
public LootLockerStorage[] storage { get; set; }
99103
public Rarity rarity { get; set; }
100104
public bool popular { get; set; }
@@ -107,6 +111,13 @@ public class Asset: LootLockerResponse
107111
public bool context_locked { get; set; }
108112
public bool initially_purchasable { get; set; }
109113
public File[] files { get; set; }
114+
public LootLockerAssetCandidate asset_candidate { get; set; }
115+
}
116+
117+
public class LootLockerAssetCandidate
118+
{
119+
public int created_by_player_id;
120+
public string created_by_player_uid;
110121
}
111122

112123
public class File

Assets/LootLocker/Game/LootLockerSDKManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,18 @@ public static void GetContext(Action<ContextResponse> onComplete)
364364
LootLockerAPIManager.GetContext(onComplete);
365365
}
366366

367+
public static void GetAssetsOriginal(int assetCount, Action<AssetResponse> onComplete, int? idOfLastAsset = null, Enums.AssetFilter filter = Enums.AssetFilter.none)
368+
{
369+
if (!CheckInitialized()) return;
370+
LootLockerAPIManager.GetAssetsOriginal(onComplete, assetCount, idOfLastAsset, filter);
371+
}
372+
367373
public static void GetAssetListWithCount(int assetCount, Action<AssetResponse> onComplete)
368374
{
369375
if (!CheckInitialized()) return;
370376
LootLockerGetRequest data = new LootLockerGetRequest();
371377
data.getRequests.Add(assetCount.ToString());
372-
LootLockerAPIManager.GetAssetListWithCount(data, onComplete);// GetContext(LootLockerGetRequest data, Action<ContextResponse> onComplete)
378+
LootLockerAPIManager.GetAssetListWithCount(data, onComplete);
373379
}
374380

375381
public static void GetAssetNextList(int assetCount, Action<AssetResponse> onComplete)

Assets/LootLocker/Game/Requests/AssetRequest.cs

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,69 @@ public static void GetContext(Action<ContextResponse> onComplete)
4747
if (string.IsNullOrEmpty(serverResponse.Error))
4848
{
4949
LootLockerSDKManager.DebugMessage(serverResponse.text);
50-
Debug.Log("Server Response Text: " + serverResponse.text);
5150
response = JsonConvert.DeserializeObject<ContextResponse>(serverResponse.text);
52-
//you are checking the wrong response. that is null because you have not assigned anything to it
53-
//data you are looking for is in serverResponse.text
54-
//if you want the response.text to have the value you need, you need to assign it here
5551
response.text = serverResponse.text;
56-
Debug.Log("Response is: " + serverResponse.text);
52+
onComplete?.Invoke(response);
53+
}
54+
else
55+
{
56+
response.message = serverResponse.message;
57+
response.Error = serverResponse.Error;
58+
onComplete?.Invoke(response);
59+
}
60+
}, true);
61+
}
62+
63+
public static void GetAssetsOriginal(Action<AssetResponse> onComplete, int assetCount, int? idOfLastAsset = null, Enums.AssetFilter filter = Enums.AssetFilter.none)
64+
{
65+
EndPointClass endPoint = LootLockerEndPoints.current.gettingAssetListWithCount;
66+
string getVariable = string.Format(endPoint.endPoint, assetCount);
67+
68+
if (idOfLastAsset != null && assetCount > 0)
69+
{
70+
endPoint = LootLockerEndPoints.current.gettingAssetListWithAfterAndCount;
71+
getVariable = string.Format(endPoint.endPoint, assetCount, idOfLastAsset.ToString());
72+
}
73+
else if (idOfLastAsset != null && assetCount > 0 && filter!= Enums.AssetFilter.none)
74+
{
75+
endPoint = LootLockerEndPoints.current.gettingAssetListOriginal;
76+
string filterString = "";
77+
switch(filter)
78+
{
79+
case Enums.AssetFilter.purchasable:
80+
filterString = Enums.AssetFilter.purchasable.ToString();
81+
break;
82+
case Enums.AssetFilter.nonpurchasable:
83+
filterString = "!purchasable";
84+
break;
85+
case Enums.AssetFilter.rentable:
86+
filterString = Enums.AssetFilter.rentable.ToString();
87+
break;
88+
case Enums.AssetFilter.nonrentable:
89+
filterString = "!rentable";
90+
break;
91+
case Enums.AssetFilter.popular:
92+
filterString = Enums.AssetFilter.popular.ToString();
93+
break;
94+
case Enums.AssetFilter.nonpopular:
95+
filterString = "!popular";
96+
break;
97+
}
98+
getVariable = string.Format(endPoint.endPoint, assetCount, idOfLastAsset.ToString(), filterString);
99+
}
100+
101+
ServerRequest.CallAPI(getVariable, endPoint.httpMethod, null, onComplete: (serverResponse) =>
102+
{
103+
AssetResponse response = new AssetResponse();
104+
if (string.IsNullOrEmpty(serverResponse.Error))
105+
{
106+
LootLockerSDKManager.DebugMessage(serverResponse.text);
107+
response = JsonConvert.DeserializeObject<AssetResponse>(serverResponse.text);
108+
response.text = serverResponse.text;
109+
if (response != null)
110+
{
111+
AssetRequest.lastId = response.assets.Last()?.id != null ? response.assets.Last().id : 0;
112+
}
57113
onComplete?.Invoke(response);
58114
}
59115
else
@@ -77,13 +133,8 @@ public static void GetAssetListWithCount(LootLockerGetRequest data, Action<Asset
77133
if (string.IsNullOrEmpty(serverResponse.Error))
78134
{
79135
LootLockerSDKManager.DebugMessage(serverResponse.text);
80-
Debug.Log("Server Response Text: " + serverResponse.text);
81136
response = JsonConvert.DeserializeObject<AssetResponse>(serverResponse.text);
82-
//you are checking the wrong response. that is null because you have not assigned anything to it
83-
//data you are looking for is in serverResponse.text
84-
//if you want the response.text to have the value you need, you need to assign it here
85137
response.text = serverResponse.text;
86-
Debug.Log("Response is: " + serverResponse.text);
87138
if (response != null)
88139
{
89140
AssetRequest.lastId = response.assets.Last()?.id != null ? response.assets.Last().id : 0;
@@ -173,7 +224,6 @@ public static void GetAssetInformation(LootLockerGetRequest data, Action<Asset>
173224
if (string.IsNullOrEmpty(serverResponse.Error))
174225
{
175226
LootLockerSDKManager.DebugMessage(serverResponse.text);
176-
//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
177227
response = JsonConvert.DeserializeObject<Asset>(serverResponse.text);
178228
response.text = serverResponse.text;
179229
onComplete?.Invoke(response);

Assets/LootLocker/Game/Resources/Config/LootLockerEndPoints.asset

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ MonoBehaviour:
135135
gettingAssetListWithCount:
136136
endPoint: v1/assets/list?count={0}
137137
httpMethod: 0
138+
gettingAssetListOriginal:
139+
endPoint: v1/assets/list?after={0}&count={1}&filter={2}
140+
httpMethod: 0
138141
gettingAssetListWithAfterAndCount:
139142
endPoint: v1/assets/list?after={0}&count={1}
140143
httpMethod: 0

Assets/LootLocker/Game/Samples/Scenes/GameTestScenes/AssetsScene.unity

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ PrefabInstance:
282282
- target: {fileID: 2770848158039835156, guid: cee2985c86b19c245847700449017d5e,
283283
type: 3}
284284
propertyPath: assetCountToDownload
285-
value: 20
285+
value: 30
286286
objectReference: {fileID: 0}
287287
- target: {fileID: 2770848158039835156, guid: cee2985c86b19c245847700449017d5e,
288288
type: 3}
@@ -294,6 +294,16 @@ PrefabInstance:
294294
propertyPath: assetsToRequest.Array.data[1]
295295
value: 6509
296296
objectReference: {fileID: 0}
297+
- target: {fileID: 2770848158039835156, guid: cee2985c86b19c245847700449017d5e,
298+
type: 3}
299+
propertyPath: filter
300+
value: 6
301+
objectReference: {fileID: 0}
302+
- target: {fileID: 2770848158039835156, guid: cee2985c86b19c245847700449017d5e,
303+
type: 3}
304+
propertyPath: sendNullLastId
305+
value: 1
306+
objectReference: {fileID: 0}
297307
- target: {fileID: 2770848158039835157, guid: cee2985c86b19c245847700449017d5e,
298308
type: 3}
299309
propertyPath: m_LocalPosition.x

Assets/LootLocker/Game/Samples/Scripts/AssetTest.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public class AssetTest : MonoBehaviour
1010
{
1111
public string assetCountToDownload = "20";
1212
public string assetId;
13+
public int lastAssetId;
14+
public bool sendNullLastId;
15+
public Enums.AssetFilter filter;
1316
public string labelText;
1417
Vector2 scrollPosition;
1518
public string[] assetsToRequest = new string[] { "23", "2342", "32152" };
@@ -112,12 +115,34 @@ private void OnGUI()
112115

113116
}
114117

118+
[ContextMenu("Get Asset Original")]
119+
public void GetAssetListOriginal()
120+
{
121+
int? valToSend = null;
122+
if(!sendNullLastId)
123+
{
124+
valToSend = lastAssetId;
125+
}
126+
LootLockerSDKManager.GetAssetsOriginal(int.Parse(assetCountToDownload), (response) =>
127+
{
128+
if (response.success)
129+
{
130+
labelText = "Success\n" + response.text;
131+
}
132+
else
133+
{
134+
labelText = "Failed\n" + response.text;
135+
}
136+
137+
}, valToSend, filter);
138+
}
139+
115140
[ContextMenu("Get Asset List")]
116141
public void GetAssetListWithCount()
117142
{
118143
LootLockerSDKManager.GetAssetListWithCount(int.Parse(assetCountToDownload), (response) =>
119144
{
120-
145+
//GetAssetsOriginal
121146
if (response.success)
122147
{
123148
labelText = "Success\n" + response.text;

0 commit comments

Comments
 (0)