private void CreateBoard(int width, int height) { _allTileBackgrounds = new TileBackground[width, height]; var offset = tileBackgroundPrefab.BoundsSize; var startPos = transform.position; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Vector2 pos = new Vector2(startPos.x + (offset.x * x), startPos.y + (offset.y * y)); TileBackground instantiated = PoolManager.Instance.GetPooledObjectByTag <TileBackground>(tileBackgroundPrefab.tag); Tile tile = GetTileFromPool(_currentLevel.Grid[x, y], instantiated.transform); tile.SetArrayIndex(x, y); instantiated.transform.position = pos; instantiated.transform.localScale = tileBackgroundPrefab.transform.localScale; instantiated.transform.SetParent(transform); instantiated.SetResetTileBackgroundEvent(OnResetTileBackgroundEvent); instantiated.SetTile(tile); _allTileBackgrounds[x, y] = instantiated; } } UpdateBoardPosition(); }
private void SwipeTiles(Vector2Int current, Vector2Int target) { TileBackground currentTileBackground = GetTileBackgroundAtIndex(current); TileBackground targetTileBackground = GetTileBackgroundAtIndex(target); if (currentTileBackground == null || targetTileBackground == null) { return; } _currentTile = currentTileBackground.GetTile(); _targetTile = targetTileBackground.GetTile(); if (_targetTile.IsCompleted) { return; } OnSwipeStartEvent.Invoke(); currentTileBackground.SetTile(_targetTile); targetTileBackground.SetTile(_currentTile); _currentTile.SetArrayIndex(target.x, target.y); _targetTile.SetArrayIndex(current.x, current.y); _currentTile.SetParent(targetTileBackground.transform); _targetTile.SetParent(currentTileBackground.transform); _currentTile.DoMove(tweenTime); _targetTile.DoMove(tweenTime); StartCoroutine(WaitForSwipe(tweenTime * 1.05f)); }