Exemplo n.º 1
0
    void HandleUserInput()
    {
        World world = GameManager.Instance.World;

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (world.CannotUnpause == false)
            {
                world.Paused = !world.Paused;
            }
        }

        if (Input.GetMouseButtonDown(0)) // LPM
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                // Kursor jest nad elementem UI
                return;
            }
            else
            {
                SelectionPanel.HidePanels();
                SidePanel.HidePanels();
            }

            if (buildMode)
            {
                if (CurrentTile != null)
                {
                    if (buildModeManager.BuildMode == BuildMode.Multiple)
                    {
                        if (isDragging == false)
                        {
                            // Początek przeciągania
                            dragStartPosition = CurrentTile.Position;
                            isDragging        = true;
                        }
                    }
                    else // if (buildModeManager.BuildMode == BuildMode.Single)
                    {
                        buildModeManager.Build(CurrentTile.Position, CurrentTile.Position);
                    }
                }
            }
            else
            {
                DoRaycast();
            }
        }

        if (Input.GetMouseButton(0)) // LPM
        {
            if (isDragging)
            {
                if (CurrentTile != null)
                {
                    dragEndPosition = CurrentTile.Position;
                }
            }
        }

        if (Input.GetMouseButtonUp(0)) // LPM
        {
            // Koniec przeciągania
            if (isDragging && buildMode)
            {
                isDragging = false;
                if (CurrentTile != null)
                {
                    dragEndPosition = CurrentTile.Position;
                    buildModeManager.Build(dragStartPosition, dragEndPosition);
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (SidePanel.PanelVisible == false &&
                SelectionPanel.PanelVisible == false &&
                buildMode == false &&
                SelectedObject == null)
            {
                GameManager.Instance.World.QuitAction();
            }
        }

        if (Input.GetMouseButtonDown(1) || // PPM
            Input.GetKeyDown(KeyCode.Escape))
        {
            if (SidePanel.PanelVisible)
            {
                SidePanel.HidePanels();
            }
            if (SelectionPanel.PanelVisible)
            {
                SelectionPanel.HidePanels();
            }

            SetBuildMode(false);
            RemoveSelection();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            if (buildMode)
            {
                buildModeManager.Rotate();
            }
        }
    }