Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using PlayFab;
  2. using PlayFab.ClientModels;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8.  
  9. public class PlayFabPlayerStats1 : MonoBehaviour
  10. {
  11.    
  12.  
  13.  
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.        
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.        
  24.     }
  25.  
  26.  
  27.     public void SaveStats()
  28.     {
  29.         //Neue Anfrage erstellen
  30.         var request = new UpdatePlayerStatisticsRequest();
  31.         //Liste mit Statistiken
  32.         request.Statistics = new List<StatisticUpdate>();
  33.         //Neuen Wert für Statistik anlegen
  34.         var stat = new StatisticUpdate { StatisticName = "Erfahrung", Value = 0 };
  35.         var stat1 = new StatisticUpdate { StatisticName = "Titan", Value = 0 };
  36.         var stat2 = new StatisticUpdate { StatisticName = "Orden", Value = 0 };
  37.         var stat3 = new StatisticUpdate { StatisticName = "Wasser", Value = 0 };
  38.         //Eintag hinzufügen
  39.         request.Statistics.Add(stat);
  40.         request.Statistics.Add(stat1);
  41.         request.Statistics.Add(stat2);
  42.         request.Statistics.Add(stat3);
  43.         //Anfrage an PlayFab API starten
  44.         PlayFabClientAPI.UpdatePlayerStatistics(request, OnStatsSuccess, OnPlayFabError);
  45.     }
  46.  
  47.     private void OnPlayFabError(PlayFabError obj)
  48.     {
  49.         print("Es ist etwas im Stats-Script schiefgelaufen");
  50.     }
  51.  
  52.     private void OnStatsSuccess(UpdatePlayerStatisticsResult obj)
  53.     {
  54.         print("Neue Statistik gespeichert");
  55.     }
  56.  
  57.  
  58.     public void GetStats()
  59.     {
  60.         //Neue Anfrage erstallen
  61.         var request = new GetPlayerStatisticsRequest();
  62.         // request an PlayFabAPI
  63.         PlayFabClientAPI.GetPlayerStatistics(request, GetPlayerStaticsSuccess, OnPlayFabError);
  64.                              
  65.     }
  66.  
  67.     private void GetPlayerStaticsSuccess(GetPlayerStatisticsResult obj)
  68.     {
  69.         print("Stats wurden erfolgreich empfangen");
  70.  
  71.         // Statisken ausgeben
  72.  
  73.         foreach (var stat in obj.Statistics)
  74.         {
  75.             print("Statistic:" + stat.StatisticName + "Wert:" + stat.Value);
  76.         }
  77.     }
  78.  
  79.    
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement