Ejemplo n.º 1
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            SetBuild(null);
        }
        else if (KeyBindings.GetKeyBindings.GetKey(BindingsNames.bulldoze).KeyDown)
        {
            SetDestroy(!destroy);
        }

        if (toBuild)
        {
            Vector2 pos = grid.GetPos(Camera.main.ScreenToWorldPoint(Input.mousePosition));
            if (pos.x < 0 || pos.x >= grid.xSize)
            {
                return;
            }
            if (pos.y < 0 || pos.y >= grid.ySize)
            {
                return;
            }

            if (lineStart.x <= 0)
            {
                if (KeyBindings.GetKeyBindings.GetKey(BindingsNames.interact).AnyInput)
                {
                    if (Menus.GetMenus.IsOverUI())
                    {
                        return;
                    }

                    Destroy(tempTile);
                    grid.ClearTempTile();

                    if (fill)
                    {
                        inumertions = 0;
                        Tile old = grid.GetTileAtPos(pos);
                        Fill((int)pos.x, (int)pos.y, old);
                    }
                    else if (drawLine)
                    {
                        lineStart = pos;
                    }
                    else
                    {
                        SetTile((int)pos.x, (int)pos.y);
                    }
                    return;
                }
                grid.SetTempTile(toBuild, ref tempTile, (int)pos.x, (int)pos.y);
            }
            else
            {
                if (KeyBindings.GetKeyBindings.GetKey(BindingsNames.interact).KeyUp)
                {
                    SetLine(pos);
                    lineStart = new Vector2(-1, 0);
                }
            }
        }
        else if (destroy)
        {
            if (KeyBindings.GetKeyBindings.GetKey(BindingsNames.interact).AnyInput)
            {
                if (Menus.GetMenus.IsOverUI())
                {
                    return;
                }
                Vector2 pos = grid.GetPos(Camera.main.ScreenToWorldPoint(Input.mousePosition));
                Tile    t   = grid.GetTileAtPos(pos);
                if (t)
                {
                    if (!t.replacable)
                    {
                        if (fill)
                        {
                            FillDestroy(t.x, t.y, t);
                        }
                        else
                        {
                            grid.ResetTile(t);
                        }
                    }
                }
            }
        }
    }