public void LoadMap(Map map, MapRules rules) { UnloadMap(); this.Map = map; cells = new Dictionary <Int32, Cell> (); // current stair FloorManager.FloorStair stair = FloorManager.Instance.Stair; int i = 0; for (int y = 0; y < Map.Height; y++) { for (int x = 0; x < Map.Width; x++) { Cell cell = Map.getCell(rules, x, y); if (Map.Equals(stair.StairMap) && stair.StairPosition == new Vector2(x, y)) { cell = stair.StairCell.gameObject.GetComponent <Cell>(); } cell = Instantiate(cell, getPositionFromCell(i) + new Vector2(0.5f, 0.5f), Quaternion.identity).GetComponent <Cell> (); cell.init(i, null); cells.Add(cell.Id, cell); cell.transform.parent = gameObject.transform; //Debug.Log (i + " " + cell); // Rotation for texture cell.transform.rotation = Quaternion.Euler(0, 0, 180); i++; } } foreach (Cell c in cells.Values) { //Cell[] neighbors = new Cell[4]; //neighbors [Cell.LEFT] = (x==0)?null:cells[i-1]; //neighbors [Cell.TOP] = getCellFromPosition (new Vector2(x,y-1)); c.BindOn(getCellFromId(c.Id + Map.Width), Cell.TOP); c.BindOn((c.Id) % (Map.Height) >= Map.Width - 1?null:getCellFromId(c.Id + 1), Cell.RIGHT); } foreach (Map.TeleporterLine teleporterLine in Map.Teleporters) { Teleporter teleporter = getCellFromPosition(teleporterLine.origin).gameObject.AddComponent <Teleporter> (); teleporter.Destination(teleporterLine.destinationMap, teleporterLine.destinationPosition); } /*foreach (Cell c in cells.Values) { * if( * !c || * c.Left.Right != c || * c.Right.Left != c || * c.Top.Bottom != c || * c.Bottom.Top != c * ){ * Debug.LogWarning("Bug cell "+c.Id); * } * }*/ PutCameraOverMap(); this._ready = true; }