-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed slow load times for refreshing tilemap colliders in the scene view
- Loading branch information
Showing
6 changed files
with
95 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
- To allow the LDtk importer to load Aseprite files, install the [Unity Aseprite Importer](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) | ||
The Aseprite importer requires Unity 2021.3.15 or above | ||
|
||
- Fixed the slow load time to reset tilemap colliders in the scene after reimporting a tileset definition file | ||
- Added a notification in the scene view indicating how many tilemap colliders were reset, and how long it took | ||
- Fixed a bug where reordering IntGrid value definitions would use the wrong tile references, and in some cases, cause an exception | ||
- Changed the icons for the imported Project/Level/Tileset to match with the icons from LDtk 1.5 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Assets/LDtkUnity/Editor/Utility/LDtkTilemapColliderReset.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.Tilemaps; | ||
|
||
namespace LDtkUnity.Editor | ||
{ | ||
internal static class LDtkTilemapColliderReset | ||
{ | ||
private static bool _willRefreshTilemapsInScene; | ||
|
||
public static void TilemapColliderTileUpdate() | ||
{ | ||
//Refresh tilemap colliders in the current scene. | ||
//Tiles would normally not update in the scene view until entering play mode, or reloading the scene, or resetting the component. | ||
//This will immediately update it. | ||
//There is currently no easy solution found for refreshing tilemap colliders in the scene, so this is the best solution I could find for now. | ||
//Related forum: https://forum.unity.com/threads/ispritephysicsoutlinedataprovider-is-not-updating-the-tilemapcollider2d-in-the-scene-immediately.1458874/#post-9358610 | ||
|
||
if (_willRefreshTilemapsInScene) | ||
{ | ||
return; | ||
} | ||
_willRefreshTilemapsInScene = true; | ||
|
||
EditorApplication.delayCall += () => | ||
{ | ||
_willRefreshTilemapsInScene = false; | ||
|
||
Stopwatch watch = Stopwatch.StartNew(); | ||
|
||
//should only try resetting tilemaps that are in an LDtk hierarchy | ||
var levels = LDtkFindInScenes.FindInAllScenes<LDtkComponentLevel>(); | ||
if (levels.IsNullOrEmpty()) | ||
{ | ||
watch.Stop(); | ||
return; | ||
} | ||
|
||
var layers = levels.SelectMany(p => p.GetComponentsInChildren<LDtkComponentLayer>()).ToList(); | ||
if (layers.IsNullOrEmpty()) | ||
{ | ||
watch.Stop(); | ||
return; | ||
} | ||
|
||
var colliders = layers.SelectMany(p => p.GetComponentsInChildren<TilemapCollider2D>()).ToList(); | ||
int affected = 0; | ||
foreach (var collider in colliders) | ||
{ | ||
Unsupported.SmartReset(collider); | ||
if (LDtkBuilderLayer.ConfigureTilemapCollider(collider)) | ||
{ | ||
affected++; | ||
} | ||
} | ||
watch.Stop(); | ||
|
||
SceneView view = SceneView.lastActiveSceneView; | ||
if (view != null && affected > 0) | ||
{ | ||
float seconds = watch.ElapsedMilliseconds * 0.001f; | ||
view.ShowNotification(new GUIContent($"Refreshed LDtk scene tilemaps\n({affected} in {seconds:F2}s)"), 2.5f); | ||
} | ||
}; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/LDtkUnity/Editor/Utility/LDtkTilemapColliderReset.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters