Пример #1
0
    // Update is called once per frame
    void Update()
    {
        #region Movement
        horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }
        #endregion

        #region Break and place

        #region mouse
        MouseDistance = Vector3.Distance(mousePos, transform.position);
        mousePos      = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        #endregion

        if (Input.GetButtonDown("Fire1"))
        {
            if (MouseDistance < 11.5)
            {
                string Tilename = TileMap1.GetTile(TileMap1.WorldToCell(mousePos)).name;
                if (Tilename == null)
                {
                    Tilename = TileMap2.GetTile(TileMap2.WorldToCell(mousePos)).name;


                    TileMap2.SetTile(TileMap2.WorldToCell(mousePos), null);
                    Debug.Log(Tilename);

                    string[] GetTiles;
                    GetTiles = AssetDatabase.FindAssets($"{Tilename}", new[] { "Assets/Resources/Items" });

                    string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                    InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                    itemContainer.AddItem(new ItemSlot(item, 1));
                }

                if (Tilename != null)
                {
                    TileMap1.SetTile(TileMap1.WorldToCell(mousePos), null);
                    Debug.Log(Tilename);

                    string[] GetTiles;
                    GetTiles = AssetDatabase.FindAssets($"{Tilename}", new[] { "Assets/Resources/Items" });

                    string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                    InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                    itemContainer.AddItem(new ItemSlot(item, 1));
                }
            }
        }

        if (Input.GetButtonDown("Fire2"))
        {
            if (hotbar.selected.SlotItem is InventoryItem inventoryItem)
            {
                if (itemContainer.HasItem(inventoryItem))
                {
                    if (MouseDistance < 11.5)
                    {
                        string[] GetTiles;
                        if (PlaceBlock.name == "log")
                        {
                            GetTiles = AssetDatabase.FindAssets("Tree", new[] { "Assets/Resources/Items" });
                        }
                        else
                        {
                            GetTiles = AssetDatabase.FindAssets($"{PlaceBlock.name}", new[] { "Assets/Resources/Items" });
                        }
                        string        itemPath = AssetDatabase.GUIDToAssetPath(GetTiles[0]);
                        InventoryItem item     = (InventoryItem)AssetDatabase.LoadAssetAtPath(itemPath, typeof(InventoryItem));

                        if (TileMap1.GetTile(TileMap1.WorldToCell(mousePos)) == null)
                        {
                            TileMap1.SetTile(TileMap1.WorldToCell(mousePos), PlaceBlock);
                            itemContainer.UpdatedRemove(item, 1);
                        }
                    }
                }
            }
        }
        #endregion

        #region Block Selection

        #region KeyPresses
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            hotbar.Select(0);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            hotbar.Select(1);
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            hotbar.Select(2);
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            hotbar.Select(3);
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            hotbar.Select(4);
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            hotbar.Select(5);
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            hotbar.Select(6);
        }
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            hotbar.Select(7);
        }
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            hotbar.Select(8);
        }
        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            hotbar.Select(9);
        }
        #endregion

        hotbar.GetSelected();

        PlaceBlock = hotbar.selected.SlotItem.PlaceTile;
        #endregion
    }
Пример #2
0
    //Private

    private void Inputs()
    {
        InputDirection("w", Vector3.forward);
        InputDirection("s", Vector3.back);
        InputDirection("a", Vector3.left);
        InputDirection("d", Vector3.right);
        InputDirection("space", Vector3.up);
        InputDirection("left shift", Vector3.down);
        MouseDirection();
        Zoom();

        if (Input.GetMouseButton(0) && !replace)
        {
            Place();
        }
        if (Input.GetMouseButton(0) && replace)
        {
            Replace();
        }
        if (Input.GetMouseButton(1))
        {
            Delete();
        }
        if (Input.GetMouseButtonDown(2))
        {
            GetBlock();
        }
        if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
        {
            buildTimer = 0;
        }
        if (Input.GetKeyDown("i"))
        {
            ToggleInventory();
        }
        if (Input.GetKeyDown("u"))
        {
            Undo();
        }
        if (Input.GetKeyDown("z"))
        {
            ToggleAirTarget();
        }
        if (Input.GetKeyDown("e"))
        {
            ToggleExtend();
        }
        if (Input.GetKeyDown("c"))
        {
            ToggleArchitect();
        }
        if (Input.GetKeyDown("r"))
        {
            ToggleReplace();
        }
        if (Input.GetKeyDown("escape"))
        {
            ToggleMenu("Main Menu");
        }
        if (Input.GetKeyDown("m"))
        {
            ToggleExtendMatching();
        }
        for (int i = 1; i <= 5; i++)
        {
            if (Input.GetKeyDown(i + ""))
            {
                hotbar.Select(i - 1);
            }
        }
    }