예제 #1
0
    public void UpdateSwatch()
    {
        // -------------------------------------------------
        // SWAPPING COLORS
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.X))
        {
            SwapColors();
        }

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse      = Input.GetMouseButton(0);
        bool rightMouse     = Input.GetMouseButton(1);
        bool leftMouseDown  = Input.GetMouseButtonDown(0);
        bool leftMouseUp    = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp   = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        RaycastHit ray = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2   pixelUV    = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;

            // -------------------------------------------------------------------------
            // SWATCH PLANE
            // -------------------------------------------------------------------------
            if (ray.transform.gameObject.layer == LayerMask.NameToLayer("Swatch"))
            {
                if (leftMouseDown && !_editor.GetIsDragging() && !_editor.GetIsEditingPixels())
                {
                    _draggingSwatchBorder = true;

                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    _borderDragWorldOffset = (Vector2)_swatchBorderPlane1.transform.position - mouseWorldPos;
                }

                ZoomSwatchPlane();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if (!zoomedThisFrame && _zoomTimer > 0.0f)
        {
            ZoomSwatchPlane();
        }

        if (_draggingSwatchBorder)
        {
            if (Input.GetMouseButtonUp(0))
            {
                _draggingSwatchBorder = false;
                PlayerPrefs.SetFloat("swatchPosX", _swatchPlane1.transform.position.x);
                PlayerPrefs.SetFloat("swatchPosY", _swatchPlane1.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _swatchPlane1.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.SWATCH_PLANE_DEPTH);
            }
        }
    }
예제 #2
0
    public void UpdatePalette()
    {
        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse      = Input.GetMouseButton(0);
        bool rightMouse     = Input.GetMouseButton(1);
        bool leftMouseDown  = Input.GetMouseButtonDown(0);
        bool leftMouseUp    = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp   = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        RaycastHit ray = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2   pixelUV    = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;

            // -------------------------------------------------------------------------
            // PALETTE PLANE
            // -------------------------------------------------------------------------
            if (ray.transform.gameObject == _palettePlane)
            {
                if (!_editor.GetIsDragging())
                {
                    int index = (PALETTE_NUM_Y - y - 1) * PALETTE_NUM_X + x;

                    if (GetColorExists(index))
                    {
                        if (leftMouse)
                        {
                            Color32 color = _paletteColors[index];
                            if (!color.Equals(_editor.GetCurrentColor()))
                            {
                                if (_editor.GetToolMode() == ToolMode.Eraser)
                                {
                                    _editor.SetToolMode(ToolMode.Brush);
                                }

                                _editor.SetCurrentColor(_paletteColors[index]);
                            }
                        }
                        else if (rightMouse && _editor.GetModifierKey() && !_editor.GetIsEditingPixels())
                        {
                            _editor.AddNewCommand(new DeletePaletteColorCommand(index));
                            _editor.SetTextEnteringMode(TextEnteringMode.None);
                        }
                        else if (rightMouse && !_editor.GetModifierKey())
                        {
                            _editor.SetTextEnteringMode(TextEnteringMode.PaletteColor);

                            Color32 color = _paletteColors[index];
                            _editor.PaletteColorString = color.r.ToString() + "," + color.g.ToString() + "," + color.b.ToString() + ((color.a < 255) ? ("," + color.a.ToString()) : "");
                            _paletteColorEditIndex     = index;

                            _editor.PaletteInputScreenPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);                             // gotta flip the y-position;
                        }

                        // -----------------------------------------------------------
                        // COLOR SWAPPING
                        // -----------------------------------------------------------
                        if (leftMouseDown)
                        {
                            _paletteColorEditIndex       = index;
                            _draggingCurrentPaletteColor = true;
                        }
                        else if (leftMouseUp && _draggingCurrentPaletteColor && index != _paletteColorEditIndex && _editor.GetModifierKey() && !_editor.GetIsEditingPixels())
                        {
                            if (_editor.GetModifierKey())
                            {
                                _editor.AddNewCommand(new SetPaletteColorCommand(_paletteColors[_paletteColorEditIndex], index));                                 // duplicate color
                            }
                            else
                            {
                                _editor.AddNewCommand(new SwapPaletteColorsCommand(index, _paletteColorEditIndex));
                            }

                            _draggingCurrentPaletteColor = false;
                        }
                    }
                    else
                    {
                        if (leftMouseDown)
                        {
                            _draggingPaletteBorder = true;

                            Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                            _borderDragWorldOffset = (Vector2)_paletteBorderPlane.transform.position - mouseWorldPos;
                        }
                        else if (rightMouse)
                        {
                            _editor.SetTextEnteringMode(TextEnteringMode.PaletteColor);

                            _editor.PaletteColorString = "...";

                            _editor.PaletteInputScreenPosition = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);                             // gotta flip the y-position;
                            _paletteColorEditIndex             = index;
                        }
                        else if (leftMouseUp && _draggingCurrentPaletteColor && index != _paletteColorEditIndex && _editor.GetModifierKey() && !_editor.GetIsEditingPixels())
                        {
                            _editor.AddNewCommand(new SwapPaletteColorsCommand(index, _paletteColorEditIndex));

                            _draggingCurrentPaletteColor = false;
                        }
                    }
                }

                ZoomPalettePlane();
                zoomedThisFrame = true;
            }
            // -------------------------------------------------------------------------
            // PALETTE BORDER PLANE
            // -------------------------------------------------------------------------
            else if (ray.transform.gameObject == _paletteBorderPlane)
            {
                if (leftMouseDown && !_editor.GetIsDragging() && !_editor.GetIsEditingPixels())
                {
                    _draggingPaletteBorder = true;

                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    _borderDragWorldOffset = (Vector2)_paletteBorderPlane.transform.position - mouseWorldPos;
                }

                ZoomPalettePlane();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if (!zoomedThisFrame && _zoomTimer > 0.0f)
        {
            ZoomPalettePlane();
        }

        // -------------------------------------------------
        // WRAP UP SOME PALETTE MOUSE SHIT
        // -------------------------------------------------
        if (leftMouseUp && _draggingCurrentPaletteColor)
        {
            _draggingCurrentPaletteColor = false;
        }

        if (leftMouse && _editor.GetTextEnteringMode() == TextEnteringMode.PaletteColor)
        {
            _editor.SetTextEnteringMode(TextEnteringMode.None);
        }

        if (_draggingPaletteBorder)
        {
            if (Input.GetMouseButtonUp(0))
            {
                _draggingPaletteBorder = false;
                PlayerPrefs.SetFloat("palettePosX", _palettePlane.transform.position.x);
                PlayerPrefs.SetFloat("palettePosY", _palettePlane.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _palettePlane.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.PALETTE_PLANE_DEPTH);
            }
        }
    }
예제 #3
0
    public void UpdateFramePreview()
    {
        // -------------------------------------------------
        // SWITCHING FRAMES
        // -------------------------------------------------
        if (Input.GetKeyDown(KeyCode.A) && !_editor.GetIsEditingPixels())       // || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (_editor.GetModifierKey())
            {
                _editor.AddNewCommand(new DuplicateFrameCommand(true));
            }
            else
            {
                GoToPreviousFrame();
            }

            _isPlayingAnimation = false;
        }
        else if (Input.GetKeyDown(KeyCode.D) && !_editor.GetIsEditingPixels())       // || Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (_editor.GetModifierKey())
            {
                _editor.AddNewCommand(new DuplicateFrameCommand(false));
            }
            else
            {
                GoToNextFrame();
            }

            _isPlayingAnimation = false;
        }
        else if (_editor.GetModifierKey() && Input.GetKeyUp(KeyCode.Space) && !_editor.GetIsEditingPixels())
        {
            _editor.AddNewCommand(new AddNewBlankFrameCommand());
            _isPlayingAnimation = false;
        }

        // -------------------------------------------------
        // ANIMATION
        // -------------------------------------------------
        if (_isPlayingAnimation)
        {
            _animTimer += Time.deltaTime;
            if (_animTimer >= _frameTimes[_currentFrame])
            {
                // ----------------------------------------------------------------
                // LOOPS
                // ----------------------------------------------------------------
                if (_loopMode == LoopMode.Loops)
                {
                    GoToNextFrame();
                }
                // ----------------------------------------------------------------
                // PLAY ONCE
                // ----------------------------------------------------------------
                else if (_loopMode == LoopMode.PlayOnce)
                {
                    if (_currentFrame < GetNumFrames() - 1)
                    {
                        GoToNextFrame();
                    }
                    else
                    {
                        _isPlayingAnimation = false;
                    }
                }
                // ----------------------------------------------------------------
                // PING PONG
                // ----------------------------------------------------------------
                else if (_loopMode == LoopMode.PingPong)
                {
                    if (_pingPongForward)
                    {
                        if (_currentFrame < GetNumFrames() - 1)
                        {
                            GoToNextFrame();
                        }
                        else
                        {
                            GoToPreviousFrame();
                            _pingPongForward = false;
                        }
                    }
                    else
                    {
                        if (_currentFrame > 0)
                        {
                            GoToPreviousFrame();
                        }
                        else
                        {
                            GoToNextFrame();
                            _pingPongForward = true;
                        }
                    }
                }
                // ----------------------------------------------------------------
                // RANDOM
                // ----------------------------------------------------------------
                else if (_loopMode == LoopMode.RandomFrame)
                {
                    if (GetNumFrames() > 1)
                    {
                        int newFrame = Random.Range(0, GetNumFrames());
                        while (newFrame == _currentFrame)
                        {
                            newFrame = Random.Range(0, GetNumFrames());
                        }

                        _editor.AddNewCommand(new SetFrameCommand(newFrame));

                        _editor.GetCanvas().DirtyPixels = true;
                        _editor.CurrentFrameTimeString = _frameTimes[_currentFrame].ToString();
                    }
                }

                _animTimer = 0.0f;
            }
        }

        if (!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.Space))
        {
            if (_isPlayingAnimation)
            {
                _isPlayingAnimation = false;
            }
            else if (!_isPlayingAnimation && GetNumFrames() > 1)
            {
                if (_loopMode == LoopMode.PlayOnce && _currentFrame == GetNumFrames() - 1)
                {
                    _editor.AddNewCommand(new SetFrameCommand(0));
                    _editor.GetCanvas().DirtyPixels = true;
                }

                _animTimer          = 0.0f;
                _isPlayingAnimation = true;
            }
        }

        if (Input.GetKeyDown(KeyCode.L))
        {
            ToggleLoopMode();
        }

        if (_editor.GetModifierKey() && (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Q)) && !_editor.GetIsEditingPixels())
        {
            _editor.AddNewCommand(new DeleteFrameCommand());

            HighlightCurrentFramePreview();
        }

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse      = Input.GetMouseButton(0);
        bool rightMouse     = Input.GetMouseButton(1);
        bool leftMouseDown  = Input.GetMouseButtonDown(0);
        bool leftMouseUp    = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp   = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        RaycastHit ray = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2   pixelUV    = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;


            // -------------------------------------------------------------------------
            // FRAME PREVIEW PLANES
            // -------------------------------------------------------------------------
            if (ray.transform.gameObject.layer == LayerMask.NameToLayer("PreviewFrame"))
            {
                if (leftMouse)
                {
                    // SELECT THE FRAME
                    for (int i = 0; i < GetNumFrames(); i++)
                    {
                        GameObject framePlane       = _framePlanes[i];
                        GameObject frameBorderPlane = _frameBorderPlanes[i];

                        if (ray.transform.gameObject == framePlane || ray.transform.gameObject == frameBorderPlane)
                        {
                            if (!_editor.GetIsDragging() && !_editor.GetIsEditingPixels())
                            {
                                if (leftMouseDown && _currentFrame == i)
                                {
                                    _draggingPreviewFrames = true;

                                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                                    _borderDragWorldOffset = (Vector2)_frameContainer.transform.position - mouseWorldPos;
                                }
                                else if (leftMouse && _currentFrame != i && !_editor.GetIsEditingPixels())
                                {
                                    _editor.AddNewCommand(new SetFrameCommand(i));
                                    _editor.GetCanvas().DirtyPixels = true;
                                    _isPlayingAnimation            = false;
                                    _editor.CurrentFrameTimeString = _frameTimes[_currentFrame].ToString();
                                }
                            }
                        }
                    }
                }

                ZoomFramePreviews();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if (!zoomedThisFrame && _zoomTimer > 0.0f)
        {
            ZoomFramePreviews();
        }

        // -------------------------------------------------
        // BORDERS
        // -------------------------------------------------
        if (_draggingPreviewFrames)
        {
            if (Input.GetMouseButtonUp(0))
            {
                _draggingPreviewFrames = false;
                PlayerPrefs.SetFloat("previewFramesPosX", _frameContainer.transform.position.x);
                PlayerPrefs.SetFloat("previewFramesPosY", _frameContainer.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _frameContainer.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.FRAME_PREVIEW_DEPTH);
            }
        }
    }
예제 #4
0
    public void UpdatePatternViewer()
    {
        // -------------------------------------------------
        // TOGGLE PATTERN VIEWER
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.P) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            TogglePatternViewer();
        }

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse      = Input.GetMouseButton(0);
        bool rightMouse     = Input.GetMouseButton(1);
        bool leftMouseDown  = Input.GetMouseButtonDown(0);
        bool leftMouseUp    = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp   = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        RaycastHit ray = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2   pixelUV    = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;

            // -------------------------------------------------------------------------
            // PLANES
            // -------------------------------------------------------------------------
            if (ray.transform.gameObject == _patternPlane || ray.transform.gameObject == _patternBorderPlane)
            {
                if (leftMouseDown && !_editor.GetIsDragging() && !_editor.GetIsEditingPixels())
                {
                    _draggingPatternBorder = true;

                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    _borderDragWorldOffset = (Vector2)_patternBorderPlane.transform.position - mouseWorldPos;
                }

                ZoomPatternPlane();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if (!zoomedThisFrame && _zoomTimer > 0.0f)
        {
            ZoomPatternPlane();
        }

        if (_draggingPatternBorder)
        {
            if (Input.GetMouseButtonUp(0))
            {
                _draggingPatternBorder = false;
                PlayerPrefs.SetFloat("patternPosX", _patternPlane.transform.position.x);
                PlayerPrefs.SetFloat("patternPosY", _patternPlane.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _patternPlane.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.PATTERN_PLANE_DEPTH);
            }
        }
    }
예제 #5
0
    public void UpdateCanvas()
    {
        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse      = Input.GetMouseButton(0);
        bool rightMouse     = Input.GetMouseButton(1);
        bool leftMouseDown  = Input.GetMouseButtonDown(0);
        bool leftMouseUp    = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp   = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        RaycastHit ray = new RaycastHit();

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2   pixelUV    = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;

            _editor.GridIndexString = "(" + x.ToString() + "," + y.ToString() + ")";

            // -------------------------------------------------------------------------
            // CANVAS PLANE
            // -------------------------------------------------------------------------
            if (ray.transform.gameObject == _canvasPlane)
            {
                int  index       = y * pixelWidth + x;
                bool pixelExists = _pixels[_editor.CurrentFrame][index].a > 0;

                if (leftMouse && !_editor.GetIsDragging())
                {
                    if (_editor.GetToolMode() == ToolMode.Brush)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if (!indexColor.Equals(_editor.GetCurrentColor()) || indexColor.a != 255)
                        {
                            if (_editor.GetModifierKey())
                            {
                                DrawLine(_lastDrawnPoint.x, _lastDrawnPoint.y, x, y);
                                if (_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                                {
                                    DrawLine(pixelWidth - 1 - _lastDrawnPoint.x, _lastDrawnPoint.y, pixelWidth - 1 - x, y);
                                }
                                if (_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                                {
                                    DrawLine(_lastDrawnPoint.x, pixelHeight - 1 - _lastDrawnPoint.y, x, pixelHeight - 1 - y);
                                }
                                if (_mirroringMode == MirroringMode.Both)
                                {
                                    DrawLine(pixelWidth - 1 - _lastDrawnPoint.x, pixelHeight - 1 - _lastDrawnPoint.y, pixelWidth - 1 - x, pixelHeight - 1 - y);
                                }
                            }
                            else
                            {
                                ToolDrawPixel(x, y);
                                if (_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                                {
                                    ToolDrawPixel(pixelWidth - 1 - x, y);
                                }
                                if (_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                                {
                                    ToolDrawPixel(x, pixelHeight - 1 - y);
                                }
                                if (_mirroringMode == MirroringMode.Both)
                                {
                                    ToolDrawPixel(pixelWidth - 1 - x, pixelHeight - 1 - y);
                                }
                            }

                            _lastDrawnPoint = new PixelPoint(x, y);
                        }
                    }
                    else if (_editor.GetToolMode() == ToolMode.Eraser)
                    {
                        ToolErasePixel(x, y);
                        if (_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                        {
                            ToolErasePixel(pixelWidth - 1 - x, y);
                        }
                        if (_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                        {
                            ToolErasePixel(x, pixelHeight - 1 - y);
                        }
                        if (_mirroringMode == MirroringMode.Both)
                        {
                            ToolErasePixel(pixelWidth - 1 - x, pixelHeight - 1 - y);
                        }
                    }
                    else if (_editor.GetToolMode() == ToolMode.Bucket)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if (!indexColor.Equals(_editor.GetCurrentColor()) || indexColor.a != 255)
                        {
                            if (!_pixelsDrawnThisStroke.Contains(index))
                            {
                                _editor.AddNewCommand(new FloodFillCommand(x, y, _editor.GetCurrentColor()));
                                _pixelsDrawnThisStroke.Add(index);
                            }
                        }
                    }
                    else if (_editor.GetToolMode() == ToolMode.Dropper)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if (!indexColor.Equals(_editor.GetCurrentColor()))
                        {
                            if (pixelExists)
                            {
                                _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                            }
                        }
                    }
                }
                else if (leftMouseUp && _editor.GetToolMode() == ToolMode.Dropper && !_editor.GetIsDragging())
                {
                    Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                    if (pixelExists)
                    {
                        _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                        _editor.SetToolMode(ToolMode.Brush);
                    }
                    else
                    {
                        _editor.SetToolMode(ToolMode.Eraser);
                    }
                }
                else if (_editor.GetModifierKey() && rightMouseDown && pixelExists)
                {
                    _editor.GetPalette().AddColorToFirstEmptySpot(_canvasTexture.GetPixel(x, y));
                }
                else if (rightMouse)
                {
                    _editor.SetToolMode(ToolMode.Dropper);

                    // check to see if there is any color at this pixel
                    // if so, eyedropper it
                    if (pixelExists)
                    {
                        _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                    }
                }
                else if (rightMouseUp)
                {
                    if (pixelExists)
                    {
                        _editor.SetToolMode(ToolMode.Brush);
                    }
                    else
                    {
                        _editor.SetToolMode(ToolMode.Eraser);
                    }
                }

                ZoomCanvasPlane();
                zoomedThisFrame = true;
            }
            // -------------------------------------------------------------------------
            // CANVAS BORDER PLANE
            // -------------------------------------------------------------------------
            else if (ray.transform.gameObject == _canvasBorderPlane)
            {
                if (leftMouseDown && !_editor.GetIsDragging() && !CurrentlyEditingPixels)
                {
                    _draggingCanvasBorder = true;

                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    _borderDragWorldOffset = (Vector2)_canvasBorderPlane.transform.position - mouseWorldPos;
                }

                ZoomCanvasPlane();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if (!zoomedThisFrame && _zoomTimer > 0.0f)
        {
            ZoomCanvasPlane();
        }

        if (_draggingCanvasBorder)
        {
            if (Input.GetMouseButtonUp(0))
            {
                _draggingCanvasBorder = false;
                PlayerPrefs.SetFloat("canvasPosX", _canvasPlane.transform.position.x);
                PlayerPrefs.SetFloat("canvasPosY", _canvasPlane.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _canvasPlane.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.CANVAS_PLANE_DEPTH);
            }
        }

        // -------------------------------------------------------------------------
        // CURRENTLY EDITING STUFF
        // -------------------------------------------------------------------------
        if (Input.GetMouseButtonUp(0))
        {
            if (_isCurrentlyEditingPixels)
            {
                _isCurrentlyEditingPixels = false;

                _editor.AddNewCommand(new EditPixelsCommand(_currentlyReplacedPixels, _currentlyAddedPixels));
                _currentlyReplacedPixels.Clear();
                _currentlyAddedPixels.Clear();
            }
        }

        if (_pixelsDrawnThisStroke.Count > 0 && leftMouseUp)
        {
            _pixelsDrawnThisStroke.Clear();
        }

        // -------------------------------------------------
        // CLEARING FRAME
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Q)) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            _editor.AddNewCommand(new ClearCurrentFrameCommand());
        }

        // -------------------------------------------------
        // SHIFTING PIXELS
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Up));
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Down));
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Right));
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Left));
            }
        }

        // -------------------------------------------------
        // FLIPPING CANVAS
        // -------------------------------------------------
        if (_editor.GetModifierKey() && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow))
            {
                _editor.AddNewCommand(new FlipCanvasCommand(false));
            }
            else if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
            {
                _editor.AddNewCommand(new FlipCanvasCommand(true));
            }
        }

        // -------------------------------------------------
        // ONION SKIN
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.O) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            ToggleOnionSkinMode();
        }

        if (!_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if (Input.GetKeyDown(KeyCode.Minus))
            {
                AdjustOnionSkinOpacity(false);
            }
            else if (Input.GetKeyDown(KeyCode.Equals))
            {
                AdjustOnionSkinOpacity(true);
            }
        }

        // -------------------------------------------------
        // MIRRORING
        // -------------------------------------------------
        if (!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.M) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            ToggleMirroringMode();
        }
    }