Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Andrii · Mar 21, 2017 at 10:49 AM · editor-scriptinggizmoshandles

How to create a control that allows to select position within a line?

Hey everybody. I'm new to editor scripting and it looks like it's not well documented. At least I can't find any information about how to do this.

What I want to do is to create a control that looks like this: https://s16.postimg.org/kmzeylrrp/GIF.gif

This is how it's implemented when you edit a 2D polygon collider but I want to have a control like that for my own shape editor thingy. And I don't really know if it's possible.

What I want is ability to draw a line and indicate a point on it on mouse move, and if you click that point it passes the coordinates to the script so I can create a new point and draw more lines and so on. Is there a control like that? Is it possible to do at all?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by gameplay4all · Mar 21, 2017 at 03:44 PM

Well, if you'd like it to be like the 2D polygon collider, why not use that?

It has some variables which will be useful for this like points and functions like GetPath. So you could have an object with a 2D polygon collider and when you edit your custom class, you pass this object the polygon data it needs, edit the data on the 2D Polygon Collider, and when you're done you retrieve the points variable plus other things you need and use it to form the -now edited- custom class that uses these polygons.

It's a bit of a hack, if you're doing it a lot, a custom editor will be the better option. And you've already tagged the right class for this: Handles (gizmos is more for in scene view, which could be used for 3D polygons).

Hope this puts you in the right direction,

-Gameplay4all

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andrii · Mar 21, 2017 at 04:22 PM 0
Share

I thought about using this hack but it doesn't really work for me. I want to create a vertex editor that allows to create and edit simple polygons that may or may not have a collider attached. And shapes of collider and mesh could differ.

It seems that I'll need to create this tool by tracking a mouse position and drawing a line with a point manually.

To illustrate it better, here's my progress with vertex editor.

avatar image Andrii · Mar 24, 2017 at 08:41 AM 0
Share

Huh. I've just accidentally found a script that does just that. Uses Polygon Collider 2D to build the mesh. It's very basic: a dozen lines of code + common triangulator. I'll leave it here just in case.

avatar image
1

Answer by FortisVenaliter · Mar 21, 2017 at 10:08 PM

What you want to do is implement an EditorWindow. From there, you can use the editor graphics calls to generate the lines and nodes. You will most likely have to write all the logic for creation/dragging/etc. yourself, but that will provide a good venue to do so. See here for how to create the Window, and here for how to draw the components.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Andrii · Mar 22, 2017 at 06:14 PM

I've figured out how to do this, but maybe I did it the hard way.

Here's how it looks.

I'm tracking the position of a mouse using custom editor script, calculating where the point should be by comparing bunch of distances and angles and then drawing Handle.Button() at that location. I hope it's the best way because I've spent too much time writing complicated math I don't understand.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gameplay4all · Mar 22, 2017 at 06:25 PM 0
Share

That looks very useful and clean, I'm impressed :) Well done!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Showing Handles in the Game View 1 Answer

Handles.PositionHandle not working anymore in version 2019.3? 0 Answers

Using handles to edit custom classes 2 Answers

Draw Gizmos and Handles in the scene from an EditorWindow 1 Answer

Gizmos.DrawLine is dissapearing after returning to editor after Playing the scene 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges