public void HandleDragAndDrop()
        {
            if (DragAndDrop.objectReferences.Length == 0 || !guiRect.Contains(Event.current.mousePosition))
            {
                return;
            }

            switch (Event.current.type)
            {
            //TODO: Cache this
            case EventType.DragUpdated:
            {
                List <Texture2D> sheets  = TileDragAndDrop.GetValidSpritesheets(DragAndDrop.objectReferences);
                List <Sprite>    sprites = TileDragAndDrop.GetValidSingleSprites(DragAndDrop.objectReferences);
                List <TileBase>  tiles   = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences);
                m_HoverData = TileDragAndDrop.CreateHoverData(sheets, sprites, tiles);

                if (m_HoverData != null && m_HoverData.Count > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    Event.current.Use();
                    GUI.changed = true;
                }
            }
            break;

            case EventType.DragPerform:
            {
                if (m_HoverData == null || m_HoverData.Count == 0)
                {
                    return;
                }

                RegisterUndo();

                bool wasEmpty = TilemapIsEmpty(tilemap);

                Vector2Int targetPosition = mouseGridPosition;
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                Dictionary <Vector2Int, TileBase> tileSheet = TileDragAndDrop.ConvertToTileSheet(m_HoverData);
                foreach (KeyValuePair <Vector2Int, TileBase> item in tileSheet)
                {
                    SetTile(tilemap, targetPosition + item.Key, item.Value, Color.white, Matrix4x4.identity);
                }

                OnPaletteChanged();

                m_PaletteNeedsSave = true;
                FlushHoverData();
                GUI.changed = true;
                SavePaletteIfNecessary();

                if (wasEmpty)
                {
                    ResetPreviewInstance();
                    FrameEntirePalette();
                }

                Event.current.Use();
                GUIUtility.ExitGUI();
            }
            break;

            case EventType.Repaint:
                // Handled in Render()
                break;
            }

            if (m_HoverData != null && (
                    Event.current.type == EventType.DragExited ||
                    Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape))
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.None;
                FlushHoverData();
                Event.current.Use();
            }
        }
 public void HandleDragAndDrop()
 {
     if (DragAndDrop.objectReferences.Length != 0 && this.guiRect.Contains(Event.current.mousePosition))
     {
         EventType type = Event.current.type;
         if (type != EventType.DragUpdated)
         {
             if (type != EventType.DragPerform)
             {
                 if (type != EventType.Repaint)
                 {
                 }
             }
             else
             {
                 if (this.m_HoverData == null || this.m_HoverData.Count == 0)
                 {
                     return;
                 }
                 this.RegisterUndo();
                 bool       flag = GridPaintPaletteClipboard.TilemapIsEmpty(this.tilemap);
                 Vector2Int mouseGridPosition = base.mouseGridPosition;
                 DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                 Dictionary <Vector2Int, TileBase> dictionary = TileDragAndDrop.ConvertToTileSheet(this.m_HoverData);
                 foreach (KeyValuePair <Vector2Int, TileBase> current in dictionary)
                 {
                     this.SetTile(this.tilemap, mouseGridPosition + current.Key, current.Value, Color.white, Matrix4x4.identity);
                 }
                 this.OnPaletteChanged();
                 this.m_PaletteNeedsSave = true;
                 this.FlushHoverData();
                 GUI.changed = true;
                 this.SavePaletteIfNecessary();
                 if (flag)
                 {
                     this.ResetPreviewInstance();
                     this.FrameEntirePalette();
                 }
                 Event.current.Use();
                 GUIUtility.ExitGUI();
             }
         }
         else
         {
             List <Texture2D> validSpritesheets  = TileDragAndDrop.GetValidSpritesheets(DragAndDrop.objectReferences);
             List <Sprite>    validSingleSprites = TileDragAndDrop.GetValidSingleSprites(DragAndDrop.objectReferences);
             List <TileBase>  validTiles         = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences);
             this.m_HoverData = TileDragAndDrop.CreateHoverData(validSpritesheets, validSingleSprites, validTiles);
             if (this.m_HoverData != null && this.m_HoverData.Count > 0)
             {
                 DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                 Event.current.Use();
                 GUI.changed = true;
             }
         }
         if (this.m_HoverData != null && (Event.current.type == EventType.DragExited || (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)))
         {
             DragAndDrop.visualMode = DragAndDropVisualMode.None;
             this.FlushHoverData();
             Event.current.Use();
         }
     }
 }