@@ -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