public void Export() { LevelMapData data = new LevelMapData(); data.mapType = MapType; data.ballRadius = GridRadius; data.minCol = MaxCol; data.maxBallId = 0; foreach (var ball in Balls) { BallData ballData = new BallData(); ballData.id = ball.Value.Id; ballData.type = (int)ball.Value.Type; ballData.localX = ball.Value.gameObject.transform.localPosition.x; ballData.localY = ball.Value.gameObject.transform.localPosition.y; ballData.grids.Add(new GridPosition(ball.Key.col, ball.Key.row)); ballData.IsRoot = ball.Key.col == 0; foreach (var connect in ball.Value.Connections) { ballData.connections.Add(connect.Id); } data.balls.Add(ballData); if (ballData.id > data.maxBallId) { data.maxBallId = ballData.id; } if (ball.Key.col < data.minCol) { data.minCol = ball.Key.col; } } FileStream file = new FileStream(GetLevelDataPath(LevelId), FileMode.Create); FileBytesWriter writer = new FileBytesWriter(file); data.Write(writer); file.Flush(); file.Close(); }
private bool ReadBalls(BytesReader buffer) { uint flag = buffer.ReadUInt32(); if (flag != BallFlag) { return(false); } int numOfBall = buffer.ReadInt32(); if (numOfBall > 0) { for (int i = 0; i < numOfBall; i++) { BallData ball = new BallData(); ball.Read(buffer); balls.Add(ball); } } return(true); }