예제 #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
        public virtual void BoxFillPreview(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
        {
            if (brushTarget != null)
            {
                var pvmanager = PreviewManager.Instance;
                if (pvmanager == null)
                {
                    return;
                }

                foreach (Vector3Int location in position.allPositionsWithin)
                {
                    Vector3Int local = location - position.min;
                    TilePaletteGridObjectBrush.BrushCell cell = m_GridObjectBrush.cells[m_GridObjectBrush.GetCellIndexWrapAround(local.x, local.y, local.z)];
                    if (cell.gridObject != null)
                    {
                        SetPreviewCell(gridLayout, location, cell);
                    }
                }
            }

            m_LastGrid        = gridLayout;
            m_LastBounds      = position;
            m_LastBrushTarget = brushTarget;
            m_LastTool        = GridBrushBase.Tool.Box;
        }
예제 #4
0
        public virtual void PaintPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
        {
            Vector3Int min = position - m_GridTileBrush.pivot;
            Vector3Int max = min + m_GridTileBrush.size;
            BoundsInt bounds = new BoundsInt(min, max - min);

            var pvmanager = PreviewManager.Instance;
            if (pvmanager == null)
                return;

            if (brushTarget != null && gridLayout != null)
            {
                foreach (Vector3Int location in bounds.allPositionsWithin)
                {
                    Vector3Int brushPosition = location - min;
                    TilePaletteGridTileBrush.BrushCell cell = m_GridTileBrush.cells[m_GridTileBrush.GetCellIndex(brushPosition)];
                    if (cell.gridTile != null)
                    {
                        SetPreviewCell(gridLayout, location, cell);
                    }
                }
            }

            m_LastGrid = gridLayout;
            m_LastBounds = bounds;
            m_LastBrushTarget = brushTarget;
            m_LastTool = GridBrushBase.Tool.Paint;
        }
예제 #5
0
 public virtual void ClearPreview()
 {
     if (!(this.m_LastGrid == null))
     {
         BoundsInt?lastBounds = this.m_LastBounds;
         if (lastBounds.HasValue && !(this.m_LastBrushTarget == null))
         {
             GridBrushBase.Tool?lastTool = this.m_LastTool;
             if (lastTool.HasValue)
             {
                 Tilemap component = this.m_LastBrushTarget.GetComponent <Tilemap>();
                 if (component != null)
                 {
                     GridBrushBase.Tool?lastTool2 = this.m_LastTool;
                     if (lastTool2.HasValue)
                     {
                         GridBrushBase.Tool value = lastTool2.Value;
                         if (value != GridBrushBase.Tool.FloodFill)
                         {
                             if (value != GridBrushBase.Tool.Box)
                             {
                                 if (value == GridBrushBase.Tool.Paint)
                                 {
                                     foreach (Vector3Int current in this.m_LastBounds.Value.allPositionsWithin)
                                     {
                                         GridBrushEditor.ClearTilemapPreview(component, current);
                                     }
                                 }
                             }
                             else
                             {
                                 Vector3Int position  = this.m_LastBounds.Value.position;
                                 Vector3Int a         = position + this.m_LastBounds.Value.size;
                                 BoundsInt  boundsInt = new BoundsInt(position, a - position);
                                 foreach (Vector3Int current2 in boundsInt.allPositionsWithin)
                                 {
                                     GridBrushEditor.ClearTilemapPreview(component, current2);
                                 }
                             }
                         }
                         else
                         {
                             component.ClearAllEditorPreviewTiles();
                         }
                     }
                 }
                 this.m_LastBrushTarget = null;
                 this.m_LastGrid        = null;
                 this.m_LastBounds      = null;
                 this.m_LastTool        = null;
             }
         }
     }
 }
예제 #6
0
        public virtual void ClearPreview()
        {
            if (m_LastGrid == null || m_LastBounds == null || m_LastBrushTarget == null || m_LastTool == null)
            {
                return;
            }

            var pvmanager = PreviewManager.Instance;

            if (pvmanager != null)
            {
                switch (m_LastTool)
                {
                /*
                 * case GridBrushBase.Tool.FloodFill:
                 *  {
                 *      map.ClearAllEditorPreviewTiles();
                 *      break;
                 *  }
                 */
                case GridBrushBase.Tool.Box:
                {
                    Vector3Int min    = m_LastBounds.Value.position;
                    Vector3Int max    = min + m_LastBounds.Value.size;
                    BoundsInt  bounds = new BoundsInt(min, max - min);
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearPreviewCell(location);
                    }
                    break;
                }

                case GridBrushBase.Tool.Paint:
                {
                    BoundsInt bounds = m_LastBounds.Value;
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearPreviewCell(location);
                    }
                    break;
                }
                }
            }

            m_LastBrushTarget = null;
            m_LastGrid        = null;
            m_LastBounds      = null;
            m_LastTool        = null;
        }
예제 #7
0
        /// <summary>Clears any preview drawn previously by the GridBrushEditor.</summary>
        public virtual void ClearPreview()
        {
            if (m_LastGrid == null || m_LastBounds == null || m_LastBrushTarget == null || m_LastTool == null)
            {
                return;
            }

            Tilemap map = m_LastBrushTarget.GetComponent <Tilemap>();

            if (map != null)
            {
                switch (m_LastTool)
                {
                case GridBrushBase.Tool.FloodFill:
                {
                    map.ClearAllEditorPreviewTiles();
                    break;
                }

                case GridBrushBase.Tool.Box:
                {
                    Vector3Int min    = m_LastBounds.Value.position;
                    Vector3Int max    = min + m_LastBounds.Value.size;
                    BoundsInt  bounds = new BoundsInt(min, max - min);
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearTilemapPreview(map, location);
                    }
                    break;
                }

                case GridBrushBase.Tool.Paint:
                {
                    BoundsInt bounds = m_LastBounds.Value;
                    foreach (Vector3Int location in bounds.allPositionsWithin)
                    {
                        ClearTilemapPreview(map, location);
                    }
                    break;
                }
                }
            }

            m_LastBrushTarget = null;
            m_LastGrid        = null;
            m_LastBounds      = null;
            m_LastTool        = null;
        }
예제 #8
0
 public virtual void FloodFillPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
 {
     if (EditorPrefs.GetBool(GridBrushEditor.Styles.floodFillPreviewEditorPref, true))
     {
         BoundsInt value = new BoundsInt(position, Vector3Int.one);
         if (brushTarget != null && this.brush.cellCount > 0)
         {
             Tilemap component = brushTarget.GetComponent <Tilemap>();
             if (component != null)
             {
                 GridBrush.BrushCell brushCell = this.brush.cells[0];
                 component.EditorPreviewFloodFill(position, brushCell.tile);
                 value.min = component.origin;
                 value.max = component.origin + component.size;
             }
         }
         this.m_LastGrid        = gridLayout;
         this.m_LastBounds      = new BoundsInt?(value);
         this.m_LastBrushTarget = brushTarget;
         this.m_LastTool        = new GridBrushBase.Tool?(GridBrushBase.Tool.FloodFill);
     }
 }
예제 #9
0
 public virtual void BoxFillPreview(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
 {
     if (brushTarget != null)
     {
         Tilemap component = brushTarget.GetComponent <Tilemap>();
         if (component != null)
         {
             foreach (Vector3Int current in position.allPositionsWithin)
             {
                 Vector3Int          vector3Int = current - position.min;
                 GridBrush.BrushCell brushCell  = this.brush.cells[this.brush.GetCellIndexWrapAround(vector3Int.x, vector3Int.y, vector3Int.z)];
                 if (brushCell.tile != null)
                 {
                     GridBrushEditor.SetTilemapPreviewCell(component, current, brushCell.tile, brushCell.matrix, brushCell.color);
                 }
             }
         }
     }
     this.m_LastGrid        = gridLayout;
     this.m_LastBounds      = new BoundsInt?(position);
     this.m_LastBrushTarget = brushTarget;
     this.m_LastTool        = new GridBrushBase.Tool?(GridBrushBase.Tool.Box);
 }
예제 #10
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;
        }
예제 #11
0
        public virtual void PaintPreview(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
        {
            Vector3Int vector3Int = position - this.brush.pivot;
            Vector3Int a          = vector3Int + this.brush.size;
            BoundsInt  value      = new BoundsInt(vector3Int, a - vector3Int);

            if (brushTarget != null)
            {
                Tilemap component = brushTarget.GetComponent <Tilemap>();
                foreach (Vector3Int current in value.allPositionsWithin)
                {
                    Vector3Int          brushPosition = current - vector3Int;
                    GridBrush.BrushCell brushCell     = this.brush.cells[this.brush.GetCellIndex(brushPosition)];
                    if (brushCell.tile != null && component != null)
                    {
                        GridBrushEditor.SetTilemapPreviewCell(component, current, brushCell.tile, brushCell.matrix, brushCell.color);
                    }
                }
            }
            this.m_LastGrid        = gridLayout;
            this.m_LastBounds      = new BoundsInt?(value);
            this.m_LastBrushTarget = brushTarget;
            this.m_LastTool        = new GridBrushBase.Tool?(GridBrushBase.Tool.Paint);
        }
예제 #12
0
 public override void OnToolDeactivated(GridBrushBase.Tool tool)
 {
     base.OnToolDeactivated(tool);
     activeTool = null;
 }
예제 #13
0
 public override void OnToolActivated(GridBrushBase.Tool tool)
 {
     base.OnToolActivated(tool);
     activeTool = tool;
     UpdateActiveTilemapDropdown();
 }