Skip to content

Commit c28b0c8

Browse files
committed
chore: test cleanup
1 parent 51bd328 commit c28b0c8

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

Assets/Scenes/TestScene.unity

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,16 @@ MonoBehaviour:
286286
m_Script: {fileID: 11500000, guid: dc3a2b9cdc24aab40906ce4bcdee9943, type: 3}
287287
m_Name:
288288
m_EditorClassIdentifier:
289+
gameId: FmOBeUfQO2AOLNIrJNSJ
289290
baseUrl: https://ws.joinplayroom.com/api/store
290-
gameApiKey:
291+
gameApiKey: 510a71af-3a69-4f5d-9b9b-296a1871e624
292+
token: eyJhbGciOiJIUzI1NiJ9.eyJkaXNjb3JkSWQiOiI0NzY3MDk1MjQwMTE2MTQyMTkiLCJyb29tSWQiOiJEQ1JEX2ktMTM4OTk1NjgzMTE0NDgzNzE0MC1wYy0xMzcxOTI3NzM0MTY2NDg3MDkwIiwiZ2FtZUlkIjoiRm1PQmVVZlFPMkFPTE5JckpOU0oiLCJndWlsZElkIjpudWxsLCJjaGFubmVsSWQiOiIxMzcxOTI3NzM0MTY2NDg3MDkwIiwiYWNjZXNzVG9rZW4iOiJNVE0zTURReE5qSTRORFk0T0RNeU1qWTRNZy5CNjdvckR6UjV1V0Q4dWE2TlZlUzNtczRpdEM2cGoiLCJhdXRoIjoiZGlzY29yZCIsInQiOjE3NTE0NjE5NzF9.Te4Fgg6KrSs9bqsxKPlyDYZotcumECoGCi_Q5cWCCAM
291293
text: {fileID: 1547749}
292294
skus: []
293295
entitlements: []
296+
discordSkus: []
297+
discordEntitlements: []
298+
serverRewards: []
294299
--- !u!4 &1054460207
295300
Transform:
296301
m_ObjectHideFlags: 0

Assets/Scripts/GameManager.cs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ Action<string, string> onError
179179

180180
Debug.LogWarning($"body: {bodyJson}");
181181

182-
183182
byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJson);
184183
using (var request = new UnityWebRequest(url, "POST"))
185184
{
@@ -192,22 +191,19 @@ Action<string, string> onError
192191

193192
yield return request.SendWebRequest();
194193

195-
// Network or protocol error?
196194
if (request.result == UnityWebRequest.Result.ConnectionError ||
197195
request.result == UnityWebRequest.Result.DataProcessingError)
198196
{
199197
onError?.Invoke($"Error granting reward: {request.error}", request.downloadHandler.text);
200198
yield break;
201199
}
202200

203-
// Handle HTTP response codes
204201
long code = request.responseCode;
205202
string text = request.downloadHandler.text;
206203

207204
switch (code)
208205
{
209206
case 200:
210-
// { "message": "..." }
211207
onSuccess?.Invoke(text);
212208
break;
213209

@@ -332,35 +328,68 @@ private void Update()
332328

333329
if (Input.GetKeyDown(KeyCode.M))
334330
{
335-
StartCoroutine(GetActiveServerRewards(gameId, playroomKit.GetPlayroomToken(), "510a71af-3a69-4f5d-9b9b-296a1871e624", (result) =>
331+
#if !UNITY_EDITOR && UNITY_WEBGL
332+
StartCoroutine(GetActiveServerRewards(gameId, playroomKit.GetPlayroomToken(), gameApiKey, (result) =>
333+
{
334+
serverRewards = ServerReward.FromJSON(result);
335+
text.text = "id :" + serverRewards[0].id + " - server id: " + serverRewards[0].serverId;
336+
}, (error) => text.text = error));
337+
#elif UNITY_EDITOR
338+
StartCoroutine(GetActiveServerRewards(gameId, token, gameApiKey, (result) =>
336339
{
337340
serverRewards = ServerReward.FromJSON(result);
338-
text.text = "id :" +serverRewards[0].id + " - server id: " + serverRewards[0].serverId;
341+
text.text = "id :" + serverRewards[0].id + " - server id: " + serverRewards[0].serverId;
339342
}, (error) => text.text = error));
343+
#endif
340344
}
341345

346+
347+
342348
if (Input.GetKeyDown(KeyCode.N))
343349
{
344-
StartCoroutine(GrantServerReward(gameId, playroomKit.GetPlayroomToken(), "510a71af-3a69-4f5d-9b9b-296a1871e624", serverRewards[0].serverId, (result) =>
350+
351+
#if !UNITY_EDITOR && UNITY_WEBGL
352+
StartCoroutine(GrantServerReward(gameId, playroomKit.GetPlayroomToken(), gameApiKey, serverRewards[0].serverId, (result) =>
345353
{
346354
text.text = result;
347355
}, (error, response) =>
348356
{
349357
text.text = response;
350358
Debug.LogError(error);
351359
}));
360+
#else
361+
StartCoroutine(GrantServerReward(gameId, token, gameApiKey, serverRewards[0].serverId, (result) =>
362+
{
363+
text.text = result;
364+
}, (error, response) =>
365+
{
366+
text.text = response;
367+
Debug.LogError(error);
368+
}));
369+
#endif
352370
}
353371

354372
if (Input.GetKeyDown(KeyCode.L))
355373
{
356-
StartCoroutine(GrantServerReward(gameId, playroomKit.GetPlayroomToken(), "510a71af-3a69-4f5d-9b9b-296a1871e624", serverRewards[0].id, (result) =>
374+
#if !UNITY_EDITOR && UNITY_WEBGL
375+
StartCoroutine(GrantServerReward(gameId, playroomKit.GetPlayroomToken(), gameApiKey, serverRewards[0].id, (result) =>
376+
{
377+
text.text = result;
378+
}, (error, response) =>
379+
{
380+
text.text = response;
381+
Debug.LogError(error);
382+
}));
383+
#elif UNITY_EDITOR
384+
StartCoroutine(GrantServerReward(gameId, token, gameApiKey, serverRewards[0].id, (result) =>
357385
{
358386
text.text = result;
359387
}, (error, response) =>
360388
{
361389
text.text = response;
362390
Debug.LogError(error);
363391
}));
392+
#endif
364393
}
365394
}
366395
#endregion

0 commit comments

Comments
 (0)