/// <summary> /// Precondition: grille vide jamais remplie /// </summary> /// <param name="grid"></param> public void FillThisGrilleAndSpawn(GameObject parent) { JaggedGrid jagged = JaggedGrid.FillGridFromJSON(); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { for (int z = 0; z < sizeZ; z++) { if (jagged.grille[y * sizeZ * sizeX + z * sizeX + x] != 0) //On suppose que la grille était vide et jamais remplie! { GameObject obj = Instantiate(gameManager.networkManager.spawnPrefabs[jagged.grille[y * sizeZ * sizeX + z * sizeX + x] - 1], new Vector3(x, y, z), Quaternion.identity, parent.transform); obj.GetComponent <Placeable>().Position = new Vector3Int(x, y, z); // Debug.Log(obj.GetComponent<Placeable>().Position); obj.GetComponent <Placeable>().GameManager = gameManager; Grid[x, y, z] = obj.GetComponent <Placeable>(); //ce qui nous intéresse c'est pas le game object NetworkServer.Spawn(obj); } } } } }
/// <summary> /// Sauvegarde la grille dans un fichier json en utilisant un jaggedarray /// </summary> public void SaveGridFile() { JaggedGrid jagged = new JaggedGrid(); jagged.ToJagged(this); jagged.Save(); }
public void ConvertGridFromText(string _inPath, string _outPath) { /*if (System.IO.File.Exists(_inPath)) * { * Debug.Log("MapConverter: File " + _inPath + "does not exist"); * return; * }*/ Debug.Log("MapConverter: opening " + _inPath); blocks = CSVReader.ReadBlocks(_inPath); int minX = blocks[0].Position.x, minY = blocks[0].Position.y, minZ = blocks[0].Position.z, maxX = blocks[0].Position.x, maxY = blocks[0].Position.y, maxZ = blocks[0].Position.z; foreach (CSVReader.BlockCSV block in blocks) { Vector3Int position = block.Position; minX = Mathf.Min(minX, position.x); minY = Mathf.Min(minY, position.y); minZ = Mathf.Min(minZ, position.z); maxX = Mathf.Max(maxX, position.x); maxY = Mathf.Max(maxY, position.y); maxZ = Mathf.Max(maxZ, position.z); } int sizeX = maxX - minX + 1; int sizeY = maxY - minY + 1; int sizeZ = maxZ - minZ + 1; int shiftX = -1 * minX; int shiftY = -1 * minY; int shiftZ = -1 * minZ; int[] gridTable = new int[sizeX * sizeY * sizeZ]; // All elements are initialized to 0 JaggedGrid jaggedGrid = new JaggedGrid(sizeX, sizeY, sizeZ); foreach (CSVReader.BlockCSV block in blocks) { Debug.Log(string.Format("Bloc ({0}, {1}, {2}): {3} ", block.Position.x, block.Position.y, block.Position.z, block.Type)); int x = block.Position.x + shiftX, y = block.Position.y + shiftY, z = block.Position.z + shiftZ; if (strColorToSerialize[block.Type] == SPAWNPOINTP1) { //Debug.Log("SpawnPoints!!"); spawnPointsP1.Add(x); spawnPointsP1.Add(z); // swapping z and y for Unity spawnPointsP1.Add(y); // swapping z and y for Unity } else if (strColorToSerialize[block.Type] == SPAWNPOINTP2) { //Debug.Log("SpawnPoints!!"); spawnPointsP2.Add(x); spawnPointsP2.Add(z); // swapping z and y for Unity spawnPointsP2.Add(y); // swapping z and y for Unity } else if (strColorToSerialize[block.Type] == GOALP1) { //Debug.Log("SpawnPoints!!"); goalP1.Add(x); goalP1.Add(z); // swapping z and y for Unity goalP1.Add(y); // swapping z and y for Unity } else if (strColorToSerialize[block.Type] == GOALP2) { //Debug.Log("SpawnPoints!!"); goalP2.Add(x); goalP2.Add(z); // swapping z and y for Unity goalP2.Add(y); // swapping z and y for Unity } else if (strColorToSerialize[block.Type] == FLAG) { //Debug.Log("SpawnPoints!!"); flag.Add(x); flag.Add(z); // swapping z and y for Unity flag.Add(y); // swapping z and y for Unity } else { jaggedGrid.SetCell(strColorToSerialize[block.Type], x, y, z); } } jaggedGrid.spawnPlayerOne = spawnPointsP1.ToArray(); jaggedGrid.spawnPlayerTwo = spawnPointsP2.ToArray(); jaggedGrid.goalP1 = goalP1.ToArray(); jaggedGrid.goalP2 = goalP2.ToArray(); jaggedGrid.flagCoord = flag.ToArray(); jaggedGrid.Save(_outPath); Debug.Log("MapConverter: successfully converted to " + _outPath); }