public void LoadPlayerInformation(Player player) { //Debug.LogError ("je sync l'inventaire de "+ player.playerName); for (int i = 0; i < worldData.playersName.Length; i++) { if (player.playerName == worldData.playersName [i]) { //Debug.Log ("je remplis l'inventaire de " + player.playerName); player.transform.position = worldData.playerPositions [i].Deserialize(); PlayerInventory playerInventory = player.GetComponent <PlayerInventory> (); SerializedPlayerInventory serializedPlayerInventory = worldData.playerInventories [i]; playerInventory.inventory.Clear(); playerInventory.inventory = new List <PlantSeedInventory> (serializedPlayerInventory.indexesInPlantManager.Length); playerInventory.nbOfCrossingPods = worldData.playerInventories [i].nbOfCrossingPods; for (int j = 0; j < serializedPlayerInventory.indexesInPlantManager.Length; j++) { playerInventory.inventory.Add(new PlantSeedInventory(serializedPlayerInventory.indexesInPlantManager [j], serializedPlayerInventory.numberOfSeeds [j])); } if (serializedPlayerInventory.indexesInPlantManager.Length > 0) { CanvasManager.cm.seedSelectionWheel.SetPlayer(player.GetComponent <PlayerInventory>()); } } } player.synched = true; }
public void SerializeWorld() { //(new GameObject ("Before serilisation")).AddComponent<Test> ().wd = new WorldData(worldData); //Debug.Log ("je serialise le monde"); GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); List <string> playersName = new List <string>(worldData.playersName); //Debug.Log (worldData.playersName.Length + " ---------- " + playersName.Count); List <SerializedVector3> playerPositions = new List <SerializedVector3> (worldData.playerPositions); List <SerializedPlayerInventory> playerInventories = new List <SerializedPlayerInventory> (worldData.playerInventories); foreach (var p in players) { Player player = p.GetComponent <Player> (); if (player.synched) { int index = -1; for (int i = 0; i < playersName.Count; i++) { if (player.playerName == playersName [i]) { index = i; playerPositions [i] = new SerializedVector3(player.transform.position); playerInventories [i] = new SerializedPlayerInventory(player.GetComponent <PlayerInventory> ()); } } if (index == -1) { playersName.Add(player.playerName); playerPositions.Add(new SerializedVector3(player.transform.position)); playerInventories.Add(new SerializedPlayerInventory(player.GetComponent <PlayerInventory> ())); } } } worldData.playersName = playersName.ToArray(); worldData.playerPositions = playerPositions.ToArray(); worldData.playerInventories = playerInventories.ToArray(); GameManager.gm.pm.SerializePlants(worldData); //Debug.Log(worldData.plants.Length); //GameManager.gm.zd.Init (); GameManager.gm.zd.SerializeZones(worldData); GameManager.gm.zd.SerializeDoors(worldData); //(new GameObject ("After serilisation")).AddComponent<Test> ().wd = new WorldData(worldData); //(new GameObject ()).AddComponent<Test> ().wd = worldData; }