Example #1
0
    // Update is called once per frame
    private void LateUpdate()
    {
        float scroll = Input.GetAxis("Mouse ScrollWheel");

        if (scroll > 0)
        {
            currentItem = objectHolder.GetNextObject();
        }
        if (scroll < 0)
        {
            currentItem = objectHolder.GetPreviousObject();
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            snapAmount += snapDif;
        }

        if (Input.GetKeyDown(KeyCode.G))
        {
            snapAmount -= snapDif;
        }
        snapAmount = Mathf.Max(snapAmount, snapDif);

        if (Input.GetKeyDown(KeyCode.R))
        {
            snapToGrid = !snapToGrid;
        }

        RaycastHit hit;

        if (DoRaycastFromCamera(out hit))
        {
            Vector3 pos = hit.point;
            if (snapToGrid)
            {
                pos = SnapToGrid(pos, snapAmount);
            }

            ShowVisual(objectHolder.GetCurrentVisual(), pos, transform.rotation);

            if (Input.GetMouseButtonDown(0))
            {
                if (currentItem != null)
                {
                    Command command = new PlaceObjectCommand(currentItem, pos, transform.rotation);
                    command.Execute();
                    commandIndex++;
                    commandList.Insert(commandIndex, command);
                }
            }
        }

        //Undo
        if (Input.GetMouseButtonDown(1))
        {
            if (commandIndex >= 0)
            {
                commandList[commandIndex].Undo();
                commandIndex--;
            }
        }

        //Redo
        if (Input.GetMouseButtonDown(2))
        {
            if (commandIndex < commandList.Count - 1)
            {
                commandIndex++;
                commandList[commandIndex].Execute();
            }
        }
    }