public void GetBalance(Action <int> Callback) { PlayFab.ClientModels.AddUserVirtualCurrencyRequest request = new PlayFab.ClientModels.AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC" }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { Callback(result.Balance); }, (error) => { Debug.Log(error.ErrorMessage); //GetCurrencyList(); }); }
public void SetBalance(int newbalance) { PlayFab.ClientModels.AddUserVirtualCurrencyRequest request = new PlayFab.ClientModels.AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = newbalance - NetworkCurrencyManager.currentBalance }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { Debug.Log(result.Balance); }, (error) => { Debug.Log(error.ErrorMessage); }); }
public void IncBalance(int amount) { PlayFab.ClientModels.AddUserVirtualCurrencyRequest request = new PlayFab.ClientModels.AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { Debug.Log(result.Balance); }, (error) => { Debug.Log(error.ErrorMessage); }); }
/// <summary> /// Increments the user's balance of the specified virtual currency by the stated amount /// </summary> public static void AddUserVirtualCurrency(AddUserVirtualCurrencyRequest request, AddUserVirtualCurrencyCallback resultCallback, ErrorCallback errorCallback) { if (AuthKey == null) throw new Exception ("Must be logged in to call this method"); string serializedJSON = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings); Action<string,string> callback = delegate(string responseStr, string errorStr) { ModifyUserVirtualCurrencyResult result = null; PlayFabError error = null; ResultContainer<ModifyUserVirtualCurrencyResult>.HandleResults(responseStr, errorStr, out result, out error); if(error != null && errorCallback != null) { errorCallback(error); } if(result != null) { if(resultCallback != null) { resultCallback(result); } } }; PlayFabHTTP.Post(PlayFabSettings.GetURL()+"/Client/AddUserVirtualCurrency", serializedJSON, "X-Authorization", AuthKey, callback); }
/// <summary> /// Increments the user's balance of the specified virtual currency by the stated amount /// </summary> public static void AddUserVirtualCurrency(AddUserVirtualCurrencyRequest request, ProcessApiCallback<ModifyUserVirtualCurrencyResult> resultCallback, ErrorCallback errorCallback, object customData = null) { if (_authKey == null) throw new Exception("Must be logged in to call this method"); string serializedJson = SimpleJson.SerializeObject(request, Util.ApiSerializerStrategy); Action<CallRequestContainer> callback = delegate(CallRequestContainer requestContainer) { ResultContainer<ModifyUserVirtualCurrencyResult>.HandleResults(requestContainer, resultCallback, errorCallback, null); }; PlayFabHTTP.Post("/Client/AddUserVirtualCurrency", serializedJson, "X-Authorization", _authKey, callback, request, customData); }
//Add Currency to the user public static void AddUserCurrency(int amount) { var request = new AddUserVirtualCurrencyRequest() { VirtualCurrency = "GC", Amount = amount }; PlayFabClientAPI.AddUserVirtualCurrency(request, (result) => { PlayFabDataStore.playerCurrency = result.Balance; CharacterStats.characterStats.SetGoldText(); PlayFabDataStore.playerUnupdatedCurrency = 0; Debug.Log("Currency Updated"); }, (error) => { Debug.Log("Currency Can't added!"); Debug.Log(error.ErrorMessage); Debug.Log(error.ErrorDetails); }); }
/// <summary> /// Increments the user's balance of the specified virtual currency by the stated amount /// </summary> public static async Task<PlayFabResult<ModifyUserVirtualCurrencyResult>> AddUserVirtualCurrencyAsync(AddUserVirtualCurrencyRequest request) { if (AuthKey == null) throw new Exception ("Must be logged in to call this method"); object httpResult = await PlayFabHTTP.DoPost(PlayFabSettings.GetURL() + "/Client/AddUserVirtualCurrency", request, "X-Authorization", AuthKey); if(httpResult is PlayFabError) { PlayFabError error = (PlayFabError)httpResult; if (PlayFabSettings.GlobalErrorHandler != null) PlayFabSettings.GlobalErrorHandler(error); return new PlayFabResult<ModifyUserVirtualCurrencyResult> { Error = error, }; } string resultRawJson = (string)httpResult; var serializer = JsonSerializer.Create(PlayFabSettings.JsonSettings); var resultData = serializer.Deserialize<PlayFabJsonSuccess<ModifyUserVirtualCurrencyResult>>(new JsonTextReader(new StringReader(resultRawJson))); ModifyUserVirtualCurrencyResult result = resultData.data; return new PlayFabResult<ModifyUserVirtualCurrencyResult> { Result = result }; }
/// <summary> /// Method called to give the player a certain amount of in-game currency. /// </summary> /// <param name="amount">Currency amount to give.</param> public void AddInGameCurrency(int amount) { AddUserVirtualCurrencyRequest request = new AddUserVirtualCurrencyRequest(); request.VirtualCurrency = GameConstants.inGameCurrencyID; request.Amount = amount; PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddedInGameCurrency, OnAddGameCurrencyError); }