public void ResetMap() { position = initialPosition.position; legendPosition = brickLegendPosition.position; bricks = Bricks; brickCollider = bricks [0].GetComponent <BoxCollider2D> (); offSetX = brickCollider.size.x; offSetY = brickCollider.size.y; defaultBricksMap.Clear(); brickListXml.Clear(); for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { defaultBricksMap.Add(Instantiate(defaultBrick, position, Quaternion.identity) as GameObject); BrickXml brickXml = new BrickXml(); brickXml.brickNumber = 0; brickXml.brickPosX = position.x; brickXml.brickPosY = position.y; brickListXml.Add(brickXml); position.x += offSetX; } position.x = initialPosition.position.x; position.y -= offSetY; } for (int i = 0; i < bricks.Length; i++) { Instantiate(bricks [i], legendPosition, Quaternion.identity); legendPosition.y -= offSetY; } /* for (int i = 0; i < brickListXml.Count; i++) * { * Debug.Log (defaultBricksMap[i].transform.position); * Debug.Log (brickListXml[i].brickNumber + " " + brickListXml[i].brickPosX + " " + brickListXml[i].brickPosY); * }*/ }
// Use this for initialization void Start() { bricks = Bricks; brickCollider = bricks [0].GetComponent <BoxCollider2D>(); offsetx = brickCollider.size.x; offsety = brickCollider.size.y; position = startPosition.position; for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { randomNumber = Random.Range(0, Bricks.Length); Instantiate(bricks[randomNumber], position, Quaternion.identity); //assign values and add object to List<BrickXml> to be serialized later BrickXml brick = new BrickXml(); brick.brickNumber = randomNumber; brick.brickPosX = position.x; brick.brickPosY = position.y; BricksLists.Add(brick); //end assigning position.x += offsetx; //numberOfBricks++; } position.x = startPosition.position.x; position.y -= offsety; } // testing purposes only for (int i = 0; i < BricksLists.Count; i++) { //Debug.Log (BricksLists [i].brickNumber + " " + BricksLists [i].brickPosX + " " + BricksLists [i].brickPosY); } XMLObjectSerializer.Serialize(BricksLists, Application.dataPath + "/bricksList.xml"); }
void Start() { BrickXml Brick = XMLObjectSerializer.Deserialize <BrickXml> (Application.dataPath + "/brick.xml"); Debug.Log(Brick.brickNumber); }