Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Retrieving Player Title data Private Playfab

Discussion in 'Multiplayer' started by xeonheart, May 22, 2021.

  1. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    114
    Hello,

    I am trying to find a way to retrieve player data private, specifically, I have it working where it has Stored it successfully to Playfab... However bringing it down I was using link:https://docs.microsoft.com/en-us/re...tuserdata?view=playfab-rest#getuserdataresult

    , or using the method "GetTitleDataRequest", to trying to retrieve it, is not working or not doing it right... also trying to do the same for Player Statistics... here is my code below, hopefully its a simple misunderstanding or wrong method or field?

    Player Data Title private retrieval method:
    Code (CSharp):
    1. public void ClientGetTitleData()
    2.     {
    3.         PlayFabClientAPI.GetTitleData(new GetTitleDataRequest(),
    4.             result =>
    5.             {
    6.                 if (result.Data.Keys == null)
    7.                 {
    8.                     Debug.Log("No Player Name");
    9.                 }
    10.                 else
    11.                 {
    12.                     Debug.Log("PlayerName: " +  result.Data["PlayerName"]);
    13.                 }
    14.             },
    15.             error =>
    16.             {
    17.                 Debug.Log("Got error getting titleData:");
    18.                 Debug.Log(error.GenerateErrorReport());
    19.             }
    20.         );
    21.     }
    22.  
    also below is the Player statistics that are not working or getting the stats:

    Code (CSharp):
    1. void OnDataReceived(GetPlayerStatisticsResult result)
    2.     {
    3.         if(result.CustomData != null)
    4.         {
    5.             foreach(var eachstat in result.Statistics)
    6.             {
    7.                 if(eachstat.StatisticName.Equals("PlayerGender"))
    8.                 {
    9.                     P_Gender_Index = eachstat.Value;
    10.                 }
    11.                 if (eachstat.StatisticName.Equals("PlayerSkinColor"))
    12.                 {
    13.                     P_SkinColor_Index = eachstat.Value;
    14.                 }
    15.                 if (eachstat.StatisticName.Equals("PlayerHair"))
    16.                 {
    17.                     P_HairType_Index = eachstat.Value;
    18.                 }
    19.                 if (eachstat.StatisticName.Equals("PlayerHairColor"))
    20.                 {
    21.                     P_HairColor_Index = eachstat.Value;
    22.                 }
    23.                 if (eachstat.StatisticName.Equals("PlayerShirt"))
    24.                 {
    25.                     P_Shirt_Index = eachstat.Value;
    26.                 }
    27.                 if (eachstat.StatisticName.Equals("PlayerShirtColor"))
    28.                 {
    29.                     P_ShirtColor_Index = eachstat.Value;
    30.                 }
    31.                 if (eachstat.StatisticName.Equals("PlayerPants"))
    32.                 {
    33.                     P_Pants_Index = eachstat.Value;
    34.                 }
    35.                 if (eachstat.StatisticName.Equals("PlayerPantsColor"))
    36.                 {
    37.                     P_PantsColor_Index = eachstat.Value;
    38.                 }
    39.             }
    40.         }
    41.         else
    42.         {
    43.             var randGender = new System.Random();
    44.             int resgender = randGender.Next(0, 2);
    45.             P_Gender_Index = resgender;
    46.             System.Random randSkinColor = new System.Random();
    47.             P_SkinColor_Index = randSkinColor.Next(0, 4);
    48.             System.Random randHairColor = new System.Random();
    49.             P_HairColor_Index = randHairColor.Next(0, 3);
    50.             while (P_SkinColor_Index == P_HairColor_Index)
    51.                 P_HairColor_Index = randHairColor.Next(0, 3);
    52.         }
    53.     }
     
  2. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    114
    So good news, i did get the player statistics working, able to read stats now... However still trying to Read Player Title Data private... any idea? attached is the image.
     

    Attached Files:

  3. xeonheart

    xeonheart

    Joined:
    Jul 24, 2018
    Posts:
    114
    finally got it to work, so something similar to the get player stats method, here is the code example below, hope it comes in handy for someone:

    Code (CSharp):
    1.     public void PlayerData(GetUserDataResult result)
    2.     {
    3.         if(result.Data != null)
    4.         {
    5.             foreach(var playerData in result.Data)
    6.             {
    7.                 if (playerData.Key == "PlayerName")
    8.                 {
    9.                     IF_DisplayName.text = playerData.Value.Value;
    10.                 }
    11.             }
    12.         }
    13.     }
    14.  
    15.     void GetPlayerName()
    16.     {
    17.         PlayFabClientAPI.GetUserData(
    18.             new GetUserDataRequest(), PlayerData, OnError);
    19.     }
    20.  
    21.  
     
unityunity