예제 #1
0
        /// <summary>
        /// Shrink the map bounds to the minimum area enclosing all visible tiles
        /// </summary>
        public void ShrinkMapBoundsToVisibleArea()
        {
            Bounds  mapBounds    = new Bounds();
            Vector2 halfCellSize = CellSize / 2f; // used to avoid precission errors

            m_maxGridX = m_maxGridY = m_minGridX = m_minGridY = 0;
            var valueIter = m_dicChunkCache.Values.GetEnumerator();

            while (valueIter.MoveNext())
            {
                TilemapChunk chunk = valueIter.Current;
                if (chunk)
                {
                    Bounds  tilechunkBounds = chunk.GetBounds();
                    Vector2 min             = transform.InverseTransformPoint(chunk.transform.TransformPoint(tilechunkBounds.min));
                    Vector2 max             = transform.InverseTransformPoint(chunk.transform.TransformPoint(tilechunkBounds.max));
                    mapBounds.Encapsulate(min + halfCellSize);
                    mapBounds.Encapsulate(max - halfCellSize);
                }
            }
            m_minGridX = BrushUtil.GetGridX(mapBounds.min, CellSize);
            m_minGridY = BrushUtil.GetGridY(mapBounds.min, CellSize);
            m_maxGridX = BrushUtil.GetGridX(mapBounds.max, CellSize);
            m_maxGridY = BrushUtil.GetGridY(mapBounds.max, CellSize);
            RecalculateMapBounds();
        }