コード例 #1
0
        /// <summary>Does a preview of what happens when a GridBrush.FloodFill is done with the same parameters.</summary>
        /// <param name="gridLayout">Grid to paint data to.</param>
        /// <param name="brushTarget">Target of the flood fill operation. By default the currently selected GameObject.</param>
        /// <param name="position">The coordinates of the cell to flood fill data to.</param>
        public virtual void FloodFillPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
        {
            // This can be quite taxing on a large Tilemap, so users can choose whether to do this or not
            if (!EditorPrefs.GetBool(GridBrushProperties.floodFillPreviewEditorPref, true))
            {
                return;
            }

            var bounds = new BoundsInt(position, Vector3Int.one);

            if (brushTarget != null && brush.cellCount > 0)
            {
                Tilemap map = brushTarget.GetComponent <Tilemap>();
                if (map != null)
                {
                    GridBrush.BrushCell cell = brush.cells[0];
                    map.EditorPreviewFloodFill(position, cell.tile);
                    // Set floodfill bounds as tilemap bounds
                    bounds.min = map.origin;
                    bounds.max = map.origin + map.size;
                }
            }

            m_LastGrid        = gridLayout;
            m_LastBounds      = bounds;
            m_LastBrushTarget = brushTarget;
            m_LastTool        = GridBrushBase.Tool.FloodFill;
        }
コード例 #2
0
        /// <summary>Paints preview data into a cell of a grid given the coordinates of the cell.</summary>
        /// <param name="gridLayout">Grid to paint data to.</param>
        /// <param name="brushTarget">Target of the paint operation. By default the currently selected GameObject.</param>
        /// <param name="position">The coordinates of the cell to paint data to.</param>
        /// <remarks>The grid brush will paint preview sprites in its brush cells onto an associated Tilemap. This will not instantiate objects associated with the painted tiles.</remarks>
        public virtual void PaintPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
        {
            Vector3Int min    = position - brush.pivot;
            Vector3Int max    = min + brush.size;
            BoundsInt  bounds = new BoundsInt(min, max - min);

            if (brushTarget != null)
            {
                Tilemap map = brushTarget.GetComponent <Tilemap>();
                foreach (Vector3Int location in bounds.allPositionsWithin)
                {
                    Vector3Int          brushPosition = location - min;
                    GridBrush.BrushCell cell          = brush.cells[brush.GetCellIndex(brushPosition)];
                    if (cell.tile != null && map != null)
                    {
                        SetTilemapPreviewCell(map, location, cell.tile, cell.matrix, cell.color);
                    }
                }
            }

            m_LastGrid        = gridLayout;
            m_LastBounds      = bounds;
            m_LastBrushTarget = brushTarget;
            m_LastTool        = GridBrushBase.Tool.Paint;
        }
コード例 #3
0
 private bool CheckFloodFillPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
 {
     if (m_LastGrid == gridLayout &&
         m_LastBrushTarget == brushTarget &&
         m_LastBounds.HasValue && m_LastBounds.Value.Contains(position) &&
         brushTarget != null && brush.cellCount > 0)
     {
         Tilemap map = brushTarget.GetComponent <Tilemap>();
         if (map != null)
         {
             GridBrush.BrushCell cell = brush.cells[0];
             if (cell.tile == map.GetEditorPreviewTile(position))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #4
0
        /// <summary>Does a preview of what happens when a GridBrush.BoxFill is done with the same parameters.</summary>
        /// <param name="gridLayout">Grid to box fill data to.</param>
        /// <param name="brushTarget">Target of box fill operation. By default the currently selected GameObject.</param>
        /// <param name="position">The bounds to box fill data to.</param>
        public virtual void BoxFillPreview(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            if (brushTarget != null)
            {
                Tilemap map = brushTarget.GetComponent <Tilemap>();
                if (map != null)
                {
                    foreach (Vector3Int location in position.allPositionsWithin)
                    {
                        Vector3Int          local = location - position.min;
                        GridBrush.BrushCell cell  = brush.cells[brush.GetCellIndexWrapAround(local.x, local.y, local.z)];
                        if (cell.tile != null)
                        {
                            SetTilemapPreviewCell(map, location, cell.tile, cell.matrix, cell.color);
                        }
                    }
                }
            }

            m_LastGrid        = gridLayout;
            m_LastBounds      = position;
            m_LastBrushTarget = brushTarget;
            m_LastTool        = GridBrushBase.Tool.Box;
        }