/// <summary> /// Update the render mesh and mesh collider of all tile chunks. This should be called once after making all modifications to the tilemap with SetTileData. /// </summary> public void UpdateMesh() { #if UNITY_EDITOR if (!Application.isPlaying) { #if UNITY_5_3 UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); #else EditorApplication.MarkSceneDirty(); #endif } #endif RecalculateMapBounds(); List <TilemapChunk> chunkList = new List <TilemapChunk>(transform.childCount); for (int i = 0; i < transform.childCount; ++i) { TilemapChunk chunk = transform.GetChild(i).GetComponent <TilemapChunk>(); if (chunk != null) { if (!chunk.UpdateMesh()) { --i; #if UNITY_EDITOR if (IsUndoEnabled) { Undo.DestroyObjectImmediate(chunk.gameObject); } else { DestroyImmediate(chunk.gameObject); } #else DestroyImmediate(chunk.gameObject); #endif } else { //chunk.UpdateColliderMesh(); chunkList.Add(chunk); } } } // UpdateColliderMesh is called after calling UpdateMesh of all tilechunks, because UpdateColliderMesh needs the tileId to be updated // ( remember a brush sets neighbours tile id to empty, so UpdateColliderMesh won't be able to know the collider type ) for (int i = 0; i < chunkList.Count; ++i) { chunkList[i].UpdateColliders(); } }
/// <summary> /// Update the render mesh and mesh collider of all tile chunks. This should be called once after making all modifications to the tilemap with SetTileData. /// </summary> public void UpdateMeshImmediate() { #if UNITY_EDITOR if (!Application.isPlaying && m_markSceneDirtyOnNextUpdateMesh) { m_markSceneDirtyOnNextUpdateMesh = false; #if UNITY_5_3 || UNITY_5_3_OR_NEWER UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); #else EditorApplication.MarkSceneDirty(); #endif } #endif RecalculateMapBounds(); s_chunkList.Clear(); var valueIter = m_dicChunkCache.Values.GetEnumerator(); while (valueIter.MoveNext()) { TilemapChunk chunk = valueIter.Current; if (chunk) { if (!chunk.UpdateMesh()) { #if UNITY_EDITOR if (IsUndoEnabled) { Undo.DestroyObjectImmediate(chunk.gameObject); } else { DestroyImmediate(chunk.gameObject); } #else DestroyImmediate(chunk.gameObject); #endif } else { //chunk.UpdateColliderMesh(); s_chunkList.Add(chunk); } } } if (m_autoShrink) { ShrinkMapBoundsToVisibleArea(); } // UpdateColliderMesh is called after calling UpdateMesh of all tilechunks, because UpdateColliderMesh needs the tileId to be updated // ( remember a brush sets neighbours tile id to empty, so UpdateColliderMesh won't be able to know the collider type ) for (int i = 0; i < s_chunkList.Count; ++i) { s_chunkList[i].UpdateColliders(); } if (OnMeshUpdated != null) { OnMeshUpdated(this); } }