Пример #1
0
    public Texture2D ChangeTile(Cell cell, Point localTileID, Brush data)
    {
        var index = localTileID.Y * _tilerMap.TilesPerCell + localTileID.X;
        var t     = cell.GetTile(index);

        if (t.Properties != data.Properties)
        {
            var oldBrush = _tilerMap.GetTileBrush(cell, localTileID);
            Undo.PushUndo(cell, localTileID, oldBrush);

            t.Properties = new TileProperties(data.Properties);

            var texture = cell.GetTexture();
            if (!texture)
            {
                return(null);
            }

            texture.SetPixels(localTileID.X * _tilerMap.TileResolution, localTileID.Y * _tilerMap.TileResolution, _tilerMap.TileResolution,
                              _tilerMap.TileResolution, data.Colors);

            var c         = data.Collision;
            var collision = new bool[c.Length];
            Array.Copy(c, collision, c.Length);

            t.Collision = collision;

            // Just add to apply list so we don't run multiple applies for same texture
            cell.IsDirty = true;

            return(texture);
        }

        return(null);
    }
Пример #2
0
    private void MouseEvents()
    {
        var e = Event.current;

        var rect = Parent.position;

        rect.x      += 2;
        rect.y      += ToolbarHeight + 2;
        rect.width  -= RightWidth + 4;
        rect.height -= ToolbarHeight + 4;

        var mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition);

        if (!rect.Contains(mousePos))
        {
            return;
        }

        // Left mouse button events
        if (Event.current.button == 0 && !NoRightMouseAltInput())
        {
            if (e.type == EventType.MouseDown)
            {
                TilerMapEditFunctions.Undo.NewUndo();

                Paint();
                _lastPlaced = _currentPoint;
                _isPainting = true;
            }
            if (e.type == EventType.MouseDrag)
            {
                if (_isPainting && _lastPlaced != _currentPoint)
                {
                    Paint();
                    _lastPlaced = _currentPoint;
                }
            }
        }

        // Right mouse button events
        if (Event.current.button == 1 || NoRightMouseAltInput())
        {
            if (e.type == EventType.MouseDown)
            {
                _isDraggingCopy = true;
                _startCopyPoint = _currentPoint;
            }
            if (e.type == EventType.MouseUp)
            {
                if (_isDraggingCopy)
                {
                    var properties = new List <Brush>();

                    var start = new Point
                    {
                        X = Math.Min(_currentPoint.X, _startCopyPoint.X),
                        Y = Math.Min(_currentPoint.Y, _startCopyPoint.Y)
                    };

                    var count = new Point
                    {
                        X = Math.Abs(_currentPoint.X - _startCopyPoint.X) + 1,
                        Y = Math.Abs(_currentPoint.Y - _startCopyPoint.Y) + 1
                    };

                    for (var y = start.Y; y < start.Y + count.Y; y++)
                    {
                        for (var x = start.X; x < start.X + count.X; x++)
                        {
                            var p = new Point(x, y);
                            properties.Add(TilerMap.GetTileBrush(p));
                        }
                    }

                    var copy = new CopyBrush(properties.ToArray(), new Point(count.X, count.Y));

                    if (DrawTool is PaintTool)
                    {
                        DrawTool.SetBrush(copy);
                    }
                    else
                    {
                        DrawTool = new PaintTool(this, copy);
                    }

                    Repaint();

                    _isDraggingCopy = false;
                }
            }
        }

        if (e.type == EventType.MouseDrag)
        {
            if (Event.current.button == 2)
            {
                PanWindow();
                Repaint();
            }
        }
        else if (e.type == EventType.ScrollWheel)
        {
            _height += Event.current.delta.y / 10f;
            _height  = Mathf.Clamp(_height, -1, 5);
            SetCameraHeight();
            Repaint();
        }

        if (e.type == EventType.MouseDrag || e.type == EventType.MouseMove || e.type == EventType.ScrollWheel)
        {
            GetGridPoint();
        }
    }