Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
0
Question by hexdump · Feb 23, 2016 at 01:17 PM · editoreditor-scriptingeditorwindowline

Drawing a line in a EditorWIndow?

Hi,

I need to draw a line between two points in an Editor window. I have found this answer but it is not working for me: http://answers.unity3d.com/questions/428599/how-to-make-a-line-between-object-in-editor-window.html

Does Handles.DrawLine just works inside an OnSceneGUI method? I have tried this too without any luck.

I would like to draw a line inside OnGUI if it is possible.

The code:

 using UnityEngine;
 using UnityEditor;
 using System.Collections.Generic;
 
     public class NodeWindow : EditorWindow
     {
         const int kPadding = 10;
 
         List<INode> _nodes = new List<INode>();
 
         INode _currentNode = null;
 
         [MenuItem("ComboMaker/Node window")]
         static void Create()
         {
             // Get existing open window or if none, make a new one:
             NodeWindow window = (NodeWindow)EditorWindow.GetWindow(typeof(NodeWindow));
             window.Show();
         }
 
         public NodeWindow()
         {
 
         }
 
         public void OnGUI()
         {
              Handles.BeginGUI();
              Handles.color = Color.red;
              Handles.DrawLine(new Vector3(0, 0), new Vector3(300, 300));
              Handles.EndGUI();
         }
 }
 
 
 


Cheers.

Comment
Add comment · Show 5
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 Multifred · Feb 23, 2016 at 01:41 PM 0
Share

Do you call your code after a BeginWindows() and before EndWindows()?

avatar image hexdump Multifred · Feb 23, 2016 at 02:08 PM 1
Share

I do this inside OnGUI in the EditWindow:

 Handles.BeginGUI();
 Handles.color = Color.red;
 Handles.DrawLine(new Vector3(0, 0), new Vector3(300, 300));
 Handles.EndGUI();
avatar image Graphics_Dev · Feb 23, 2016 at 02:05 PM 0
Share

Can you show your code so we can help ;)

avatar image hexdump Graphics_Dev · Feb 23, 2016 at 02:55 PM 0
Share

@Graphics_Dev I just added the code I'm using

avatar image Graphics_Dev · Feb 23, 2016 at 04:02 PM 0
Share

This seems to work just fine; I commented out lines 9-11 (because INode is created somewhere else). It draws a red line in your node window. You can use a Vector2 on line 30 because you are drawing in 2D space not in the scene view ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexdump · Feb 23, 2016 at 03:51 PM

Wel, I finally sorted out the problem. Indeed, it was a refresing problem. I must draw every frame the line.

Cheers!

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 Lilcolombian · Jan 18, 2018 at 07:53 PM 2
Share

How did you go about drawing it everyframe?

avatar image awsapps · Feb 22 at 06:16 PM 0
Share

Call the Handles methods in function: OnSceneGUI()

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

44 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

Related Questions

Custom Editor - Is there any way to detect whether the user is in Prefab editing mode? 1 Answer

Set MinWidth for EditorWindow 1 Answer

mouseposition and clicks in editor sceneview 0 Answers

Editor Window Views 0 Answers

Print to status bar. 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