I am using the Unity SDK and have made an call to the api function "PlayFabMultiplayerAPI.CreateMatchmakingTicket"
The request accept custom data through "MatchmakingPlayerAttributes"
in this tutorial https://api.playfab.com/docs/tutorials/landing-tournaments/matchmaking-unity-quickstart
they have just entered the data like this.
... // Here we specify the creator's attributes. Attributes = new MatchmakingPlayerAttributes { DataObject = new { Skill = 24.4 }, }, ...
I have however made a class for my player attributes and entered the data like this.
PlayerAttributes myPlayerAttributes = new PlayerAttributes { HostAdress = GetMyHostAdress() }; ... Attributes = new MatchmakingPlayerAttributes { DataObject = myPlayerAttributes } ...
This is all fine from what I can see. But what is the intended way to get the data back again when retrieving it from another api call.
For example when using this api call.
PlayFabMultiplayerAPI.GetMatch( new GetMatchRequest { MatchId = matchId, QueueName = "queuetest", ReturnMemberAttributes = true },
The tutorial never shows this.
I can get the DataObject and convert it back to my PlayerAttribute class structure by doing ToString on the DataObject and deserelize it from json to my PlayerAttribute class, but it feels like that isn't the intended way since the DataObject already is a PlayFab.Json.JsonObject.
How is it intended to convert "PlayFab.Json.JsonObject" to your own types?
,I am using the Unity SDK and have made an call to the api function "PlayFabMultiplayerAPI.CreateMatchmakingTicket"
The request accept custom data through "MatchmakingPlayerAttributes"
in this tutorial https://api.playfab.com/docs/tutorials/landing-tournaments/matchmaking-unity-quickstart
they have just entered the data like this.
... // Here we specify the creator's attributes. Attributes = new MatchmakingPlayerAttributes { DataObject = new { Skill = 24.4 }, }, ...
I have however made a class for my player attributes and entered the data like this.
PlayerAttributes myPlayerAttributes = new PlayerAttributes { HostAdress = GetMyHostAdress() }; ... Attributes = new MatchmakingPlayerAttributes { DataObject = myPlayerAttributes } ...
This is all fine from what I can see. But what is the intended way to get the data back again when retrieving it from another api call.
For example when using this api call.
PlayFabMultiplayerAPI.GetMatch( new GetMatchRequest { MatchId = matchId, QueueName = "queuetest", ReturnMemberAttributes = true },
The tutorial never shows this.
I can get the DataObject and convert it back to my PlayerAttribute class structure by doing ToString on the DataObject and deserelize it from json to my PlayerAttribute class, but it feels like that isn't the intended way since the DataObject already is a PlayFab.Json.JsonObject.
How is it intended to convert "PlayFab.Json.JsonObject" to your own types?
For some reason the post content and title got duplicated. And I don't seem to be able to edit it.
Answer by Sarah Zhang · Oct 14, 2019 at 10:52 AM
There is no built-in SDK to convert this DataObject to the custom type object. We should deserialize it to JSON string then convert it to the custom type object. A possible workaround is to use Newtonsoft.Json to convert it. You can refer to the following code. You can download the unity package on the Github page. It may be similar to your original way. In a word, converting DataObject to JSONString is needed.
//AttributesDataModel.cs public class AttributesDataModel { //should be correspond to your JSON path, in your code, your path is HostAdress, it should be HostAdress too public string HostAddress { get; set; } }
//use this function to convert Json to custom type using Newtonsoft.Json; … var itemAttribute = JsonConvert.DeserializeObject<AttributesDataModel>(member.Attributes.DataObject.ToString()); Debug.Log("itemAttribute.HostAddress----->" + itemAttribute.HostAddress); …
Ye, your suggestion is how I currently do it except I use the Json converter available in the playfab unity sdk.
And yes DataObject is by its definition of type object. But that is not was it is constructed as. If you use GetType on DataObject when retrieved from the api call you see that it is a PlayFab.Json.JsonObject.
I just thought it was weird that there had been an effort to construct a PlayFab.Json.JsonObject when I can't use that object to serialize it to my own type and instead has to do a third conversion to string first.
I did however found this forum post now.
https://community.playfab.com/questions/4521/executecloudscript-functionresult-frustration.html
Which explains the concerns I had.
Yeah, it looks like I missed something thank you for sharing it.
Any difference between Playfab C# SDK and PlayFab Unity SDK? 2 Answers
How do POST from php to playfab,How can i do POST from php to playfab 1 Answer
Unity Mirror and Playfab GameServers 1 Answer
Saving long text data in one UpdatePlayerData call? 2 Answers
How to download content from cdn? 1 Answer