public static Cell[,] GenerateLevel(GameObject parent, LevelDescription level, SaveData saveData = null) { AllStones.Clear(); Color[,] colorMap = level.GetColorMap(); int[,] mapData = level.GetMap(); if (mapData == null) { return(null); } Cell[,] map = new Cell[mapData.GetLength(0), mapData.GetLength(1)]; for (int i = 0; i < mapData.GetLength(0); i++) { for (int j = 0; j < mapData.GetLength(1); j++) { int needStone = 0; int hasStone = 0; int type = 1; GetCellSaveData(mapData[i, j], out type, out hasStone, out needStone); if (saveData != null) { hasStone = saveData.Map[i, j]; } Cell prefab = GetCellPrefabByType(type); Cell cell = InstantiateCell(parent, prefab, new Vector2Int(i, j), new Vector2((i + 1), j)); map[i, j] = cell; for (int k = 0; k < hasStone; k++) { InstantiateStone(cell, stonePrefab); } if (colorMap != null) { cell.SetColor(colorMap[i, j]); } } } return(map); }