public GameObject CreateTile(TileCreator.TileTypes type, int selectedFloor, int x = 0, int y = 0) { _selectedFloor = selectedFloor; _gridEditor = transform.GetComponent <GridEditor>(); Rect rect = gridCell.rect; float xOffset = x * (rect.width + GridEditor.Gap); float yOffset = y * (rect.height + GridEditor.Gap); GameObject tile = null; switch (type) { case TileCreator.TileTypes.Single: tile = InstantiateTile(TileCreator.TileTypes.Single, x, y, xOffset, -yOffset); break; case TileCreator.TileTypes.DoubleH: tile = InstantiateTile(TileCreator.TileTypes.DoubleH, x, y, xOffset + rect.width / 2, -yOffset); break; case TileCreator.TileTypes.DoubleV: tile = InstantiateTile(TileCreator.TileTypes.DoubleV, x, y, xOffset, -(yOffset + rect.height / 2)); break; } return(tile); }
public void GetBoardSpecs(List <LevelInfo> levelInfo, out int tilesCount) { int totalTiles = 0; int rows = 0; int cols = 0; int floors = 0; foreach (LevelInfo lInfo in levelInfo) { List <LevelTiles> levelTiles = lInfo.rows; foreach (LevelTiles lTiles in levelTiles) { List <int> tiles = lTiles.tiles; foreach (int t in tiles) { TileCreator.TileTypes type = (TileCreator.TileTypes)t; if (type != TileCreator.TileTypes.Empty && type != TileCreator.TileTypes.DummyH && type != TileCreator.TileTypes.DummyV) { totalTiles++; } } rows = Mathf.Max(rows, tiles.Count); } cols = Mathf.Max(cols, levelTiles.Count); floors++; } tilesCount = totalTiles; _boardSize = new Vector3(rows, cols, floors); }
private void CreateTile(TileCreator.TileTypes type) { GameObject tile = _tileEditor.CreateTile(type, _floorEditor.SelectedFloor); EditorTile et = tile.GetComponent <EditorTile>(); _boardEditor.AddTile(et); InvalidateExporter(); _validatorEnabled = true; }
public void CreateBoard(int levelId) { string levelPath = levelId == Exporter.EditorLevelNum ? Exporter.EditorLevelPath : $"Text/level{levelId.ToString()}"; TextAsset levelJson = Resources.Load <TextAsset>(levelPath); LevelData levelData = JsonUtility.FromJson <LevelData>(levelJson.text); List <LevelInfo> levelInfo = levelData.data; _boardInfo.GetBoardSpecs(levelInfo, out int tilesCount); _boardTiles = new Tile.Tile[(int)BoardSize.x, (int)BoardSize.y, (int)BoardSize.z]; _floors = new GameObject[(int)BoardSize.z]; _middleTilePos = new Vector2((int)Math.Floor(BoardSize.x / 2), (int)Math.Floor(BoardSize.y / 2)); _tileCreator = GetComponent <TileCreator>(); _tileCreator.BoardSize = BoardSize; _tileCreator.BoardTiles = BoardTiles; _tileCreator.Floors = _floors; for (int i = 0; i < levelInfo.Count; i++) { int f = levelInfo[i].floor; List <LevelTiles> levelTiles = levelInfo[i].rows; for (int j = 0; j < levelTiles.Count; j++) { List <int> tiles = levelTiles[j].tiles; for (int k = 0; k < tiles.Count; k++) { bool isMiddleTile = IsMiddleTile(k, j, f); TileCreator.TileTypes type = (TileCreator.TileTypes)tiles[k]; if (type == TileCreator.TileTypes.Empty) { _boardTiles[k, j, f] = null; } else { _boardTiles[k, j, f] = _tileCreator.CreateTile(new Vector3(k, j, f), isMiddleTile, type); } SelectMiddleTile(isMiddleTile, k, j, f); } } } _boardImages = new BoardImages(tilesCount); _boardImages.AddImagesToTiles(_floors, levelData.fillMethod); GetComponent <BoardMatcher>().GetAvailableMoves(); }
private GameObject InstantiateTile(TileCreator.TileTypes type, int x, int y, float xOffset = 0f, float yOffset = 0f) { GameObject floor = GameObject.Find($"Floor {_selectedFloor.ToString()}"); GameObject tile = Instantiate(boardTile, floor.transform, true); Vector3 tilePos = tile.transform.position; tile.transform.position = new Vector3(tilePos.x + xOffset, tilePos.y + yOffset, -_selectedFloor); EditorTile editorTile = tile.GetComponent <EditorTile>(); editorTile.GridEditor = _gridEditor; // Made on purpose editorTile.x = y; editorTile.y = x; editorTile.floor = _selectedFloor; editorTile.type = type; editorTile.SetName(); Selection.activeGameObject = tile; return(tile); }
public void ImportLevel(string path) { string[] splitPath = Regex.Split(path, @"/Resources/")[1].Split('.'); TextAsset levelJson = Resources.Load <TextAsset>(splitPath[0]); LevelData levelData = JsonUtility.FromJson <LevelData>(levelJson.text); List <LevelInfo> levelInfo = levelData.data; _boardInfo.GetBoardSpecs(levelInfo, out int tc); _gridEditor.Width = (int)_boardInfo.BoardSize.x; _gridEditor.Height = (int)_boardInfo.BoardSize.y; _gridEditor.CreateGrid(); for (int i = 0; i < levelInfo.Count; i++) { int f = levelInfo[i].floor; _floorEditor.AddNewFloor(); List <LevelTiles> levelTiles = levelInfo[i].rows; for (int j = 0; j < levelTiles.Count; j++) { List <int> tiles = levelTiles[j].tiles; for (int k = 0; k < tiles.Count; k++) { TileCreator.TileTypes type = (TileCreator.TileTypes)tiles[k]; if (type == TileCreator.TileTypes.Empty || type == TileCreator.TileTypes.DummyH || type == TileCreator.TileTypes.DummyV) { continue; } GameObject tile = _tileEditor.CreateTile(type, f, k, j); EditorTile editorTile = tile.GetComponent <EditorTile>(); _boardEditor.AddTile(editorTile); } } } }