Last active
April 9, 2020 01:56
-
-
Save JayStGelais/ab38e29280974c0bd941fce6bf007527 to your computer and use it in GitHub Desktop.
Automatically generate Collider2D around boundary of Tiled Map
This file contains hidden or 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
| public class DefaultTmxImporter : CustomTmxImporter | |
| { | |
| public override void TmxAssetImported(TmxAssetImportedArgs args) | |
| { | |
| var map = args.ImportedSuperMap; | |
| CreateColliderForCameraConfiner(map); | |
| } | |
| private static void CreateColliderForCameraConfiner(SuperMap map) | |
| { | |
| var collider = map.gameObject.AddComponent<PolygonCollider2D>(); | |
| collider.points = new[] | |
| { | |
| new Vector2(0, 0), | |
| new Vector2(map.m_Width, 0), | |
| new Vector2(map.m_Width, -map.m_Height), | |
| new Vector2(0, -map.m_Height) | |
| }; | |
| collider.isTrigger = true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment