Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by KEELAN · Oct 07, 2014 at 05:51 PM · editordraggingpolygononscenegui

Adding drag function to a polygon editor

Hi, Im writing a onscenegui polygon editor, trying to mimic the polygoncollider2D editor. I am using a FreeMoveHandle for each vertex (green) and there is a dotcap handle (shown in cyan) to show where new vertices would be placed

alt text

A new vertex is placed when the cyan dotcap handle is visible and the mouse button is clicked. This means i have to click to place, then click to drag the FreeMoveHandle of the new vertex.

This is pretty cumbersome and I really would like to just click and drag. Does anyone know how i could achieve this?

The code to add a new vertex is as follows;

                              Handles.color = Color.cyan;
                     Vector3 closestPoint = HandleUtility.ClosestPointToPolyLine(polygonArray);
 Handles.DotCap(0,closestPoint,Quaternion.identity,handleSize);
 
                     if(e.type == EventType.mouseDown && e.button == 0)
                     {
                         AddPoint(closestPoint);
                     }
 
                     Handles.color = Color.green;

and

 private void AddPoint(Vector3 pointToAdd)
 {
     m_PointCount.intValue++;

     int[] polygonEdge = FindEdgeByPoint(pointToAdd);

     for(int i = m_PointCount.intValue-2 ; i >= polygonEdge[1] ;i--)
     {
         SetPointArray(i+1, GetPointAtIndex(i));
     }

     SetPointArray(polygonEdge[1], pointToAdd);
 }


untitled.png (2.5 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KMKxJOEY1 · Oct 07, 2014 at 07:19 PM

without posting code it is hard to really tell what is going on but from what I understand this could be a solution:

When you check the mouse button the click for placing a new vtx, make it check MouseButtonDown and then create the vtx. Flag that vtx as the active editing vtx that same frame, and the update method where you are handling dragging, it should automatically begin to start updating that vtx's position until the mouse button is released and un flagging the vtx.

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 KEELAN · Oct 07, 2014 at 07:39 PM 0
Share

added the code in, dont know how i would set the vertex as the active editing vertex as you suggest though

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

29 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

Related Questions

Adjustable width columns in editor 0 Answers

Triangles Index always zero - Custom Editor 1 Answer

Draw line on polygons in editor 1 Answer

How to disable the default transform gizmo in editor? 1 Answer

Override default drag and drop behavior inside editor 1 Answer


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