Exemple #1
0
        /// <summary>
        /// Recalculate the bounding volume of the map from the grid limits
        /// </summary>
        public void RecalculateMapBounds()
        {
            // Fix grid limits if necessary
            m_minGridX = Mathf.Min(m_minGridX, 0);
            m_minGridY = Mathf.Min(m_minGridY, 0);
            m_maxGridX = Mathf.Max(m_maxGridX, 0);
            m_maxGridY = Mathf.Max(m_maxGridY, 0);

            Vector2 minTilePos = Vector2.Scale(new Vector2(m_minGridX, m_minGridY), CellSize);
            Vector2 maxTilePos = Vector2.Scale(new Vector2(m_maxGridX, m_maxGridY), CellSize);
            Vector3 savedSize  = m_mapBounds.size;

            m_mapBounds.min = m_mapBounds.max = Vector2.zero;
            m_mapBounds.Encapsulate(minTilePos);
            m_mapBounds.Encapsulate(minTilePos + CellSize);
            m_mapBounds.Encapsulate(maxTilePos);
            m_mapBounds.Encapsulate(maxTilePos + CellSize);
            if (savedSize != m_mapBounds.size)
            {
                var valueIter = m_dicChunkCache.Values.GetEnumerator();
                while (valueIter.MoveNext())
                {
                    TilemapChunk chunk = valueIter.Current;
                    if (chunk)
                    {
                        chunk.InvalidateBrushes();
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Force an update of all tilechunks. This is called after changing sensitive data like CellSize, Collider depth, etc
        /// </summary>
        /// <param name="refreshMesh"></param>
        /// <param name="refreshMeshCollider"></param>
        public void Refresh(bool refreshMesh = true, bool refreshMeshCollider = true, bool refreshTileObjects = false, bool invalidateBrushes = false)
        {
            BuildTilechunkDictionary();
            var valueIter = m_dicChunkCache.Values.GetEnumerator();

            while (valueIter.MoveNext())
            {
                TilemapChunk chunk = valueIter.Current;
                if (chunk)
                {
                    if (refreshMesh)
                    {
                        chunk.InvalidateMesh();
                    }
                    if (refreshMeshCollider)
                    {
                        chunk.InvalidateMeshCollider();
                    }
                    if (refreshTileObjects)
                    {
                        chunk.RefreshTileObjects();
                    }
                    if (invalidateBrushes)
                    {
                        chunk.InvalidateBrushes();
                    }
                }
            }
            UpdateMesh();
        }
Exemple #3
0
 /// <summary>
 /// Force an update of all tilechunks. This is called after changing sensitive data like CellSize, Collider depth, etc
 /// </summary>
 /// <param name="refreshMesh"></param>
 /// <param name="refreshMeshCollider"></param>
 public void Refresh(bool refreshMesh = true, bool refreshMeshCollider = true, bool refreshTileObjects = false, bool invalidateBrushes = false)
 {
     for (int i = 0; i < transform.childCount; ++i)
     {
         TilemapChunk chunk = transform.GetChild(i).GetComponent <TilemapChunk>();
         if (chunk != null)
         {
             if (refreshMesh)
             {
                 chunk.InvalidateMesh();
             }
             if (refreshMeshCollider)
             {
                 chunk.InvalidateMeshCollider();
             }
             if (refreshTileObjects)
             {
                 chunk.RefreshTileObjects();
             }
             if (invalidateBrushes)
             {
                 chunk.InvalidateBrushes();
             }
         }
     }
     UpdateMesh();
 }