question

brendan avatar image
brendan asked

HowTO: loading an other player data

deldam
started a topic on Sun, 08 March 2015 at 11:53 PM

I am trying to do async pvp in my game, the same way as clash of clan where you visit Cities

i have setup my game in unity this way:

Cities have Houses, Houses have guard spot

I have a database that allow me to instantiate a city prefab with all the city and guard spot already setup, only thing is guard spots are empty and i need to populate my guardspot list using a int[] guardIDList, I use the ID to have the prefab reference id my guard Database, now my problem is the docs do not explain how to use JSON in unity: https://api.playfab.com/Documentation/Client/method/UpdateUserData

using UnityEngine;

using System.Collections;



public class LoadPlayerCity : MonoBehaviour

{

    private Manager _m;





    void Start()

    {

        _m = Manager.Instance;

    }



    public class CityData

    {



    }

    public void LoadPlayerCityPvp(int cityID,CityData cityData)

    {

        GameObject newCity = Instantiate (_m.db_City.GetByID (cityID).prefab);

        City cityScript = newShip.GetComponent<City> ();



        //do serialization stuff here with cityData

        int serializedValue; //need to write a list of int here if value= 0 we considere it null so we do not load module

        //populate the rooms

        for (int i =0; i<cityScript.houseList.Count; i++)

        {

            //populate the slots

            for (int s =0; s<cityScript.houseList[i].slotList.Count; s++)

            {

                if(serializedValue != 0)

                {

                    cityScript.houseList[i].slotList[s].currentGuard = Instantiate (_m.db_guard.GetByID (serializedValue).prefab) as guardSlots;

                }



            }



        }

    }



}
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Best Answer
Brendan Vanous said on Mon, 09 March 2015 at 4:00 PM

There's also JSON serialization/deserialization in the PlayFab Unity SDK itself (PlayFab.Seralization.JsonFx). The JsonUtil.cs file in the project has some helper functions which you may find useful, it you'd like to go that route:

https://github.com/PlayFab/UnitySDK/blob/master/PlayFabClientSDK/Playfab/PlayFabSDK/Internal/JsonUtil.cs

Let us know if you have any questions on this, or run into any issues using it.


2 Comments
deadstarcgs said on Mon, 09 March 2015 at 2:30 AM

To use JSON in Unity, you either need to download one of the plugins (such as MiniJSON or SimpleJSON), write your own plugin or do what I've been doing....Basically just write out the JSON string manually yourself for upload and write code to sort the JSON string you download into usable code.


Brendan Vanous said on Mon, 09 March 2015 at 4:00 PM

There's also JSON serialization/deserialization in the PlayFab Unity SDK itself (PlayFab.Seralization.JsonFx). The JsonUtil.cs file in the project has some helper functions which you may find useful, it you'd like to go that route:

https://github.com/PlayFab/UnitySDK/blob/master/PlayFabClientSDK/Playfab/PlayFabSDK/Internal/JsonUtil.cs

Let us know if you have any questions on this, or run into any issues using it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.