コード例 #1
0
    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;
    }
コード例 #2
0
    void Start()
    {
        cam = Camera.main;
        Toolbar.InitToolBar(10);

        // Fill toolbar with debug items
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Floor"), 1), 0);
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Wall"), 1), 1);
        Toolbar.SetItemAtIndex(new InventoryItem(TileBook.GetTileByName("Object"), 1), 2);
    }
コード例 #3
0
 // Create debug room
 private void CreateStartRoom()
 {
     for (int y = 4; y < 10; y++)
     {
         for (int x = 4; x < 10; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Wall"));
         }
     }
     for (int y = 5; y < 9; y++)
     {
         for (int x = 5; x < 9; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Floor"));
         }
     }
 }
コード例 #4
0
 // Initialise whole grid to space tiles
 public void SetGridToSpace()
 {
     for (int y = 0; y < grid.height; y++)
     {
         for (int x = 0; x < grid.width; x++)
         {
             StaticMaps.SetTile(StaticMaps.MapType.World, new Vector3Int(x, y, 0), TileBook.GetTileByName("Space"));
         }
     }
 }