private void DetectClick() { // Get mouse position Vector3 clickPosition; clickPosition = cam.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward * 10.0f; if (Input.GetMouseButton(0)) { // Get tile map index of mouse position Vector3Int mapIndex = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0); float dstToClick = (clickPosition - transform.position).magnitude; // Check if mouse position is in range of player if (dstToClick <= clickReach && StaticMaps.worldMap.GetTile(mapIndex) != TileBook.GetTileByName("Space")) { breakTimer += Time.deltaTime; // Once break timer has exceeded value remove tile if (breakTimer >= 1.0f) { if (StaticMaps.objectMap.GetTile(mapIndex) != TileBook.GetTileByName("NullObject") && StaticMaps.objectMap.GetTile(mapIndex) != null) { StaticMaps.SetTile(StaticMaps.MapType.Object, mapIndex, TileBook.GetTileByName("NullObject")); } else { StaticMaps.SetTile(StaticMaps.MapType.World, mapIndex, TileBook.GetTileByName("Space")); } breakTimer = 0.0f; // Check for change in air seal DetectSeal.CheckSeal(); } } } else if (Input.GetMouseButtonDown(1)) { // If click detected check if within place range float dstToClick = (clickPosition - transform.position).magnitude; if (dstToClick <= clickReach && canPlace && Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile != null) { // Set tile at index to current tile if (TileBook.GetTileDataByName(Toolbar.GetItemByIndex(Toolbar.currentIndex).itemName).GetTileType() == TileData.TileType.WorldTile) { Vector3Int mapIndex = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0); StaticMaps.SetTile(StaticMaps.MapType.World, mapIndex, Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile); } else if (TileBook.GetTileDataByName(Toolbar.GetItemByIndex(Toolbar.currentIndex).itemName).GetTileType() == TileData.TileType.ObjectTile) { Vector3Int mapIndex = new Vector3Int((int)clickPosition.x, (int)clickPosition.y, 0); StaticMaps.SetTile(StaticMaps.MapType.Object, mapIndex, Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile); } DetectSeal.CheckSeal(); } } if (Input.GetMouseButtonUp(0)) { breakTimer = 0.0f; } StaticMaps.breakTimer = breakTimer; }
private void Update() { // Check if toolbar exists and has been initialised if (Toolbar.isInit()) { // Iterate over toolbar array and display item names for (int i = 0; i < 10; i++) { if (Toolbar.GetItemByIndex(i).itemName != "") { toolBarText[i].text = (Toolbar.currentIndex == i) ? "[ " + Toolbar.GetItemByIndex(i).itemName + " ]" : Toolbar.GetItemByIndex(i).itemName; } else { toolBarText[i].text = (Toolbar.currentIndex == i) ? "[ ---- ]" : "----"; } } } }
void Update() { Vector3 clickPosition; clickPosition = cam.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward * 10.0f; // Detect input for selecting tool bar items DetectToolbarSelection(); // Only display placement overlay if selected item is a placeable tile if (Toolbar.GetItemByIndex(Toolbar.currentIndex).itemType == InventoryItem.Type.Tile && GridUtils.AABBFloat2D(0, StaticMaps.worldMap.size.x, 0, StaticMaps.worldMap.size.y, new Vector2(clickPosition.x, clickPosition.y))) { // Display placement preview StaticMaps.ToggleMapRenderer(StaticMaps.MapType.Placement, true); StaticMaps.placementMap.SetTile(Vector3Int.zero, Toolbar.GetItemByIndex(Toolbar.currentIndex).itemTile); DisplayTileToPlace(); } else { StaticMaps.ToggleMapRenderer(StaticMaps.MapType.Placement, false); canPlace = false; } DetectClick(); }