Пример #1
0
        private void FlipY()
        {
            GridBrush.BrushCell[] array     = this.m_Cells.Clone() as GridBrush.BrushCell[];
            BoundsInt             boundsInt = new BoundsInt(Vector3Int.zero, this.m_Size);

            foreach (Vector3Int current in boundsInt.allPositionsWithin)
            {
                int y          = this.m_Size.y - current.y - 1;
                int cellIndex  = this.GetCellIndex(current.x, y, current.z);
                int cellIndex2 = this.GetCellIndex(current);
                this.m_Cells[cellIndex] = array[cellIndex2];
            }
            int y2 = this.m_Size.y - this.pivot.y - 1;

            this.pivot = new Vector3Int(this.pivot.x, y2, this.pivot.z);
            Matrix4x4 rhs = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, -1f, 1f));

            GridBrush.BrushCell[] cells = this.m_Cells;
            for (int i = 0; i < cells.Length; i++)
            {
                GridBrush.BrushCell brushCell = cells[i];
                Matrix4x4           matrix    = brushCell.matrix;
                brushCell.matrix = matrix * rhs;
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
        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;
        }
Пример #4
0
        public override void Rotate(GridBrushBase.RotationDirection direction, GridLayout.CellLayout layout)
        {
            Vector3Int size = this.m_Size;

            GridBrush.BrushCell[] array = this.m_Cells.Clone() as GridBrush.BrushCell[];
            this.size = new Vector3Int(size.y, size.x, size.z);
            BoundsInt boundsInt = new BoundsInt(Vector3Int.zero, size);

            foreach (Vector3Int current in boundsInt.allPositionsWithin)
            {
                int x          = (direction != GridBrushBase.RotationDirection.Clockwise) ? current.y : (size.y - current.y - 1);
                int y          = (direction != GridBrushBase.RotationDirection.Clockwise) ? (size.x - current.x - 1) : current.x;
                int cellIndex  = this.GetCellIndex(x, y, current.z);
                int cellIndex2 = this.GetCellIndex(current.x, current.y, current.z, size.x, size.y, size.z);
                this.m_Cells[cellIndex] = array[cellIndex2];
            }
            int x2 = (direction != GridBrushBase.RotationDirection.Clockwise) ? this.pivot.y : (size.y - this.pivot.y - 1);
            int y2 = (direction != GridBrushBase.RotationDirection.Clockwise) ? (size.x - this.pivot.x - 1) : this.pivot.x;

            this.pivot = new Vector3Int(x2, y2, this.pivot.z);
            Matrix4x4 rhs = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 0f, (direction != GridBrushBase.RotationDirection.Clockwise) ? -90f : 90f), Vector3.one);

            GridBrush.BrushCell[] cells = this.m_Cells;
            for (int i = 0; i < cells.Length; i++)
            {
                GridBrush.BrushCell brushCell = cells[i];
                Matrix4x4           matrix    = brushCell.matrix;
                brushCell.matrix = matrix * rhs;
            }
        }
Пример #5
0
 private void PaintCell(Vector3Int position, Tilemap tilemap, GridBrush.BrushCell cell)
 {
     if (cell.tile != null)
     {
         GridBrush.SetTilemapCell(tilemap, position, cell.tile, cell.matrix, cell.color);
     }
 }
Пример #6
0
        public override int GetHashCode()
        {
            int num = 0;

            GridBrush.BrushCell[] cells = this.cells;
            for (int i = 0; i < cells.Length; i++)
            {
                GridBrush.BrushCell brushCell = cells[i];
                num = num * 33 + brushCell.GetHashCode();
            }
            return(num);
        }
Пример #7
0
 public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
 {
     if (!(brushTarget == null))
     {
         Tilemap component = brushTarget.GetComponent <Tilemap>();
         foreach (Vector3Int current in position.allPositionsWithin)
         {
             Vector3Int          vector3Int = current - position.min;
             GridBrush.BrushCell cell       = this.m_Cells[this.GetCellIndexWrapAround(vector3Int.x, vector3Int.y, vector3Int.z)];
             this.PaintCell(current, component, cell);
         }
     }
 }
Пример #8
0
        private bool NotOverridingColor(GridBrush defaultGridBrush)
        {
            GridBrush.BrushCell[] cells = defaultGridBrush.cells;
            bool result;

            for (int i = 0; i < cells.Length; i++)
            {
                GridBrush.BrushCell brushCell = cells[i];
                TileBase            tile      = brushCell.tile;
                if (tile is Tile && ((tile as Tile).flags & TileFlags.LockColor) == TileFlags.None)
                {
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }
Пример #9
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);
     }
 }
Пример #10
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);
 }
Пример #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 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;
        }