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 kinatun · Feb 04, 2019 at 04:33 PM · guieditornode

drag line in node editor

recently I'm follow a tutorial to create a node editor,the thing is the tutorial is using clicking to connect input/output of the nodes, so I try to make it using dragging to create node connection.

You can see the below code in DrawConnecting() is trying to draw line when the node input is getting dragged. But unfortunately it didn't work out. I put the Debug.Log() in DrawConnecting() it show the function is updating everytime. But it seems the DrawBezier() is not get called at all.

So I make it more aggressive by testing DrawBezier() in the OnGUI() function,now I can see the DrawBezier() is very laggy,it feels like updated every 2s or so.

Why and what can I do to achieve the effect I want?

    private void OnGUI()
     {
       //other thing

         DrawConnecting(Event.current);
         
         Handles.DrawBezier(Vector2.zero,
             Event.current.mousePosition,
             Vector2.right*50f,
             Event.current.mousePosition-Vector2.right*50f,
             Color.white,
         null,
         2f
         );

    
 }

   
 private void DrawConnecting(Event e)
 {
     bool ining = selectedInPoint != null;
     bool outing = selectedOutPoint != null;
     ConnectPoint p = ining ? selectedInPoint : selectedOutPoint;
     Vector2 p_dir = ining ? Vector2.left : Vector2.right;
     Vector2 t = e.mousePosition;
  //   if(ining^outing)
  if(e.type==EventType.MouseDrag && (ining||outing))
     {
         Debug.Log("Dragging at " +p.rect.position);
         Handles.DrawBezier(p.rect.center,
             t,
             p.rect.center + p_dir * 50f,
             t - p_dir * 50f,
             Color.white,
             null,
             2f
             );

     }

 }
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
4
Best Answer

Answer by Bunny83 · Feb 04, 2019 at 05:07 PM

EditorWindows are not auto-redrawn when a drag event is issued. When you want your window to be redrawn you have to call the Repaint method of your window.


Also note that you should not draw the bezier line when the mouse drag event happens. All drawing is done when the repaint event is handled. So you probably want something like this:

 if( ining || outing )
 {
     if ( e.type==EventType.MouseDrag )
         Repaint();
     else if( e.type==EventType.Repaint )
     {
         Handles.DrawBezier(
             p.rect.center,
             t,
             p.rect.center + p_dir * 50f,
             t - p_dir * 50f,
             Color.white, null, 2f
         );
     }
 }

The "Handles.DrawBezier" method does the event check already inside, that's why it hasn't any effect in your original case since you only call DrawBezier when the event is DragMouse. However the DrawBezier method only draws anything when called during the repaint event. So it will never do anything since the event can't be both at the same time.

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

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

208 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 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 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

Why does the SceneGUI disappear when the component is folded? 0 Answers

Multiple attributes 0 Answers

Why can't I cast Editor.target to my CustomEditor type? 1 Answer

Is there an event being fired off when the Inspector is being resized? 1 Answer

GUI Remove focus from an editor text field when clicking elsewhere. 2 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