using System; using UnityEngine; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.Extensions.Logging; 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.Samples; using Naninovel; namespace PlayFab.AzureFunctions { public class FunctionHandlers { public int freeChoicesValue; public int premiumChoicesValue; [FunctionName("UpdateStats")] public static async Task<dynamic> UpdateStats([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log) { var context= await FunctionContext<dynamic>.Create(req); var args = context.FunctionArgument; var variableManager = Engine.GetService<ICustomVariableManager>(); var freeChoices = variableManager.GetVariableValue("g_freeChoices"); var premiumChoices = variableManager.GetVariableValue("g_premiumChoices"); freeChoicesValue = int.Parse(freeChoices); premiumChoicesValue = int.Parse(premiumChoices); var request = new UpdatePlayerStatisticsRequest{ PlayFabId = context.CurrentPlayerId, Statistics = new List<StatisticUpdate>{ StatisticName = "Free Choices", Value = freeChoicesValue }, new StatisticUpdate{ StatisticName = "Premium Choices", Value = premiumChoicesValue } }; var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext); return await serverApi.UpdatePlayerStatisticsRequest(request); } [FunctionName("FreeChoiceRewards")] public static async Task<dynamic> FreeChoiceRewards([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log){ var context = await FunctionContext<dynamic>.Create(req); var args = context.FunctionArgument; var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext); PlayFabClientAPI.GetPlayerStatistics( new GetPlayerStatisticsRequest {StatisticName = statNames}, OnGetFreeChoiceStatistics, error => Debug.LogError(error.GenerateErrorReport()) ); } void OnGetFreeChoiceStatistics(GetPlayerStatisticsResult result){ if(result.Statistics[0].Value%2 == 0){ RewardCurrency(5); } } void RewardCurrency(int amount){ AddUserVirutalCurrencyRequest request = new AddUserVirutalCurrencyRequest(); request.VirtualCurrency="BC"; request.Amount = amount; PlayFabClientAPI.AddUserVirtualCurrencyAsync(request, OnRewardedCurrencyResult, OnPlayFabError); } void OnRewardedCurrencyResult(ModifyUserVirtualCurrencyResult result){ Debug.Log("Rewarded Successfully! "); } void OnPlayFabError(PlayFabError error){ Debug.Log(error.GenerateErrorReport); } } }
So this is my function handlers script, where UpdateStats and FreeChoiceRewards are two azure functions I had created through VS Code and copied the function url into playfab.
I have saved this script in unity so, as you can see it can retrieve the game data, but however My IDE isn't able to find Microsoft.Azure.Webjobs and more as seen in the screenshot.
Had this issue initially with Visual Studio since i was using that for my unity project, but switched to VS Code because it wasn't showing any errors. But upon reloading it today, I am getting this. Even after installing the extensions/nu get packages.
Besides i also want to confirm, if this is the right way to do azure functions? and call these functions using ExecuteFunction()