Hi,
Ive struggled to get a cloudscript working as most of the examples dont seem to work with the .net 6 and Playfab v4 but anyway, Ive now got my first cloudscript working and accessible from inside my Unity game, but they are taking around 1-2 seconds just to subtract 1 item from the inventory which makes me wonder if maybe my codes just a bit too bloated.
Here's my cloud script code:
using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using PlayFab.EconomyModels; using PlayFab.Samples; using PlayFab.ServerModels; using PlayFab.Json; using System.Collections.Generic; using PlayFab.DataModels; using System.Net.Http; using System.Net.Http.Headers; using PlayFab.CloudScriptModels; using PlayFab; using PlayFab.AzureFunctions; namespace TestNamespace.Blah { public static class OpenLootbox { [FunctionName("OpenLootbox")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { var serverSettings = new PlayFab.PlayFabApiSettings() { TitleId = "XXXXX", DeveloperSecretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }; var authAPI = new PlayFabAuthenticationInstanceAPI(serverSettings); var titleResponse = await authAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest()); var title = titleResponse.Result.Entity; var titleToken = titleResponse.Result.EntityToken; var titleAuthContext = new PlayFabAuthenticationContext(); titleAuthContext.EntityToken = titleToken; FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync()); var economyApi = new PlayFabEconomyInstanceAPI(serverSettings, titleAuthContext); var lootboxItemRef = new PlayFab.EconomyModels.InventoryItemReference { Id = "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXXX", StackId = "default" }; PlayFab.EconomyModels.EntityKey entity = new PlayFab.EconomyModels.EntityKey { Id = context.CallerEntityProfile.Entity.Id, Type = context.CallerEntityProfile.Entity.Type }; var request = new SubtractInventoryItemsRequest(){ Amount = 1, Entity = entity, Item = lootboxItemRef }; return await economyApi.SubtractInventoryItemsAsync(request); } } }
My understanding of the entity tokens is still rather limited, do I need to call this GetEntityTokenAsync method everytime I run a cloud script? I would of assumed the entity token could be included in the request from Unity?
await authAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());
Thanks,