示例#1
0
 public MapCell(MapChip chip, int roomId, int row, int col)
 {
     Chip   = chip;
     RoomId = roomId;
     Row    = row;
     Col    = col;
 }
示例#2
0
        public void Generate()
        {
            if (Rooms == null)
            {
                Setup();
            }

            if (Rooms.Count == 0)
            {
                Debug.LogWarning("MapGenerator has no rooms");
                return;
            }

            // Create MapChip
            for (int j = 0; j < NRow; j++)
            {
                for (int i = 0; i < NCol; i++)
                {
                    int index = RoomMatrix[j][i];
                    Debug.Log("Rooms index = " + index);
                    if (index < 0)
                    {
                        continue;
                    }

                    MapChip chip = Instantiate(mapChipPrefab);
                    chip.transform.SetParent(canvas.transform, false);
                    chip.RectTransform.anchoredPosition = new Vector2(i * CellSize.x, j * CellSize.y);

                    MapCell cell = new MapCell(chip, index, j, i);
                    MapGrid[j][i] = cell;

                    if (!CellGroups.ContainsKey(index))
                    {
                        CellGroups[index] = new List <MapCell>();
                    }
                    CellGroups[index].Add(cell);
                }
            }

            // Determine shape
            for (int j = 0; j < NRow; j++)
            {
                for (int i = 0; i < NCol; i++)
                {
                    int index = RoomMatrix[j][i];
                    if (index < 0)
                    {
                        continue;
                    }

                    MapGrid[j][i].Shape = GuessShapeType(j, i);
                }
            }
        }