Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Help drawing a GL line in an Editor Window

Discussion in 'Immediate Mode GUI (IMGUI)' started by Stickworm, Oct 19, 2013.

  1. Stickworm

    Stickworm

    Joined:
    Apr 24, 2011
    Posts:
    67
    Hi I'm trying to draw a line in an editor window using the Drawing script of the Unity Wiki, I can't figure out why nothing is displaying, could someone explain to me what I'm doing wrong? Cheers

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4.  
    5. public class DrawLine: EditorWindow {
    6.    
    7.     Vector2 lineStart = new Vector2();
    8.     Vector2 mousePos = new Vector2();
    9.    
    10.     [MenuItem("Window/DrawLine")]
    11.     private static void Init()
    12.     {
    13.         DrawLine window = (DrawLine)EditorWindow.GetWindow(typeof(DrawLine));
    14.         window.minSize = new Vector2(600.0f, 300.0f);
    15.         window.wantsMouseMove = true;
    16.         window.Show();
    17.         EditorWindow.FocusWindowIfItsOpen<DrawLine>();
    18.     }
    19.    
    20.     void OnGUI(){
    21.        
    22.         GUILayout.Label("LineStart: " + lineStart);
    23.         GUILayout.Label("MousePos: " + mousePos);
    24.        
    25.         if(Event.current.type == EventType.MouseDown  Event.current.button == 0){
    26.             lineStart = Event.current.mousePosition;
    27.             Debug.Log("Down");
    28.             Event.current.Use();
    29.         }
    30.        
    31.         if(Event.current.type == EventType.MouseDrag  Event.current.button == 0){
    32.             mousePos = Event.current.mousePosition;
    33.             Drawing.DrawLine(lineStart, mousePos, Color.red, 3, true);
    34.             Debug.Log("Drawing Line" + Event.current.mousePosition);           
    35.             Repaint();
    36.             Event.current.Use();
    37.         }
    38.  
    39.         if(Event.current.type == EventType.MouseUp  Event.current.button == 0){
    40.             Event.current.Use();
    41.         }      
    42.     }
    43. }
     
unityunity