Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to export each polygon collider as a separate collider gameobject. #18

Closed
tivec opened this issue Sep 14, 2015 · 5 comments
Closed

Comments

@tivec
Copy link

tivec commented Sep 14, 2015

Hello!

I have this map being exported from Tiled to Unity via this tool: http://i.imgur.com/3AL4UPP.png

When this prefab is loaded, the collider that was generated will be one of two paths under the same game object. What I would like to see is an option to export each of these two to separate polygons. This would help me out when working with something such as PolyNav2D.

Right now I solve this with a script attached to the collider that splits it into child objects, but that's probably not the best way of doing it. Here's the script I use: http://pastebin.com/0Bdv97jB

It splits each path in the polygon and makes a new sub object to the collider gameobject. If this could be done as an option from Tiled2Unity, that'd make it a lot nicer to work with :)

Thanks for a great tool, and keep up the great work!

@Seanba
Copy link
Owner

Seanba commented Sep 17, 2015

Tivec, I think what you're asking for is to replace one PolygonCollider2D
with multiple paths with several PolygonCollider2Ds with one path each (or
an option to do one or the other). Is that correct?

I think your approach is the right one, provided you make it a custom
importer script that is done at export time instead of something performed
at runtime in the behaviour's Start method.

That way when you export your Tiled maps you will have automatically
created prefabs with all the components you need ready to go. Any other
game-specific logic you need for your maps can be set up there too.

You can read about custom import scripts here:
http://www.seanba.com/megadadadventures.html

Make sure that such custom scripts have the CustomTiledImporter attribute
and are placed in an "Editor" folder (those are common mistakes).

Best,
Sean

On Mon, Sep 14, 2015 at 8:41 AM, Tivec notifications@github.com wrote:

Hello!

I have this map being exported from Tiled to Unity via this tool:
http://i.imgur.com/3AL4UPP.png

When this prefab is loaded, the collider that was generated will be one of
two paths under the same game object. What I would like to see is an
option to export each of these two to separate polygons.
This would help
me out when working with something such as PolyNav2D.

Right now I solve this with a script attached to the collider that splits
it into child objects, but that's probably not the best way of doing it.
Here's the script I use: http://pastebin.com/0Bdv97jB

It splits each path in the polygon and makes a new sub object to the
collider gameobject. If this could be done as an option from Tiled2Unity,
that'd make it a lot nicer to work with :)

Thanks for a great tool, and keep up the great work!


Reply to this email directly or view it on GitHub
#18.

@tivec
Copy link
Author

tivec commented Sep 23, 2015

I'm sorry for taking so long to respond. I solved the issue by writing a custom importer that splits the colliders into new seperate ones, and I think that it works fairly well. Thanks again for a great tool that helps production in Unity lots :)

@tivec tivec closed this as completed Sep 23, 2015
@Seanba
Copy link
Owner

Seanba commented Sep 23, 2015

Glad it worked. Thanks, Tivec.

On Wed, Sep 23, 2015 at 2:20 PM, Tivec notifications@github.com wrote:

I'm sorry for taking so long to respond. I solved the issue by writing a
custom importer that splits the colliders into new seperate ones, and I
think that it works fairly well. Thanks again for a great tool that helps
production in Unity lots :)


Reply to this email directly or view it on GitHub
#18 (comment).

@aggsol
Copy link

aggsol commented Sep 24, 2015

@tivec Are you willing to share that with us?

@tivec
Copy link
Author

tivec commented Sep 24, 2015

Of course! My script is fairly simple and should be quite easy to understand. I should also set a disclaimer: I am barely adept with C#, and there may be poorly written code in the snippet. You have been warned!

https://gist.github.com/tivec/9216ed5c30d60c4c84d8

You would have to customize it if you want to handle anything except the layer "Walls", but the idea is the same :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants