public static void SelectTile(int xPos, int yPos, TileTab tab, int clicks) { var ti = TileHandler.GetTileImage(tab); var tileSize = ti.TileSize; int originalIndex = TileHandler.GetTileIndex(xPos, yPos, tab); int index = ti.ColumnsPerRow * yPos + xPos; if (xPos >= ti.Image.Width / tileSize || yPos >= ti.Image.Height / tileSize) { return; } if (clicks == 1) { if (SelectedTiles.Contains(index)) { SelectedTiles.Remove(index); } else { SelectedTiles.Add(index); } } else { switch (tab) { case TileTab.Source: { TileHandler.SelectedTile = originalIndex; break; } case TileTab.Randomized: { TileHandler.SelectedTile = RandomizedMap[xPos, yPos]; break; } case TileTab.RuleTest: { TileHandler.SelectedTile = RuleTestMap[xPos, yPos]; break; } } } }
void Update() { //Checks if left mouse button was pressed if (Input.GetMouseButtonDown(0)) { //Checks if mouse is currently over ui element if (!EventSystem.current.IsPointerOverGameObject()) { //Raycast to check for collider under mouse RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.down, 0.1f); int hitx = (int)hit.transform.position.x; int hity = (int)hit.transform.position.y; if (hit.collider != null) { if (TileGenerator.GetTileAt(hitx, hity).ActiveTower != null) { //Checks if object is already selected if (!SelectedObjects.ContainsKey(hit.collider.transform)) { //Checks if holding shift to select multiple if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift)) { if (SelectedTiles.Count > 0) { //Clears previous selection if shift was not held down ClearSelection(); } } //Add new selection AddSelection(hit.collider.transform); } //Object was already selected else { //Removes selection RemoveSelection(hit.collider.transform); SelectedTiles.Remove(hit.collider.gameObject); } } } } } }