Search Unity

[SOLVED] Handles not drawing on Button toggle.

Discussion in 'Scripting' started by Flickayy, Oct 27, 2015.

  1. Flickayy

    Flickayy

    Joined:
    Jan 20, 2013
    Posts:
    40
    Hey all, I'm hoping someone can help with a little issue I've ran into.

    I've ran into a confusing issue with the Handles class, trying to draw a bezier line after a GUI Button has been clicked, has brought me no luck.

    Drawing it outside of the GUI.Button, and all is glorious.

    The code currently used to display the curve.

    Code (CSharp):
    1.     void DrawCurve(Rect start, Rect end) {
    2.                 Vector3 startPos = new Vector3(start.x + start.width, start.y + start.height / 2, 0);
    3.                 Vector3 endPos = new Vector3(end.x, end.y + end.height / 2, 0);
    4.                 Vector3 startTan = startPos + Vector3.right * 50;
    5.                 Vector3 endTan = endPos + Vector3.left * 50;
    6.                 Color shadowCol = new Color(0, 0, 0, 0.06f);
    7.                 for (int i = 0; i < 3; i++) // Draw a shadow
    8.                     Handles.DrawBezier(startPos, endPos, startTan, endTan, shadowCol, null, (i + 1) * 5);
    9.                 Handles.DrawBezier(startPos, endPos, startTan, endTan, Color.black, null, 1);
    10.             }
    Calling the code likes this from a Method inside OnGUI.

    Code (CSharp):
    1.     // DRAW START NODE
    2.                 Rect startPage = new Rect(10, 45, 100, 50);
    3.                 Rect inputRect = new Rect(startPage.width - 16, startPage.y + 5, 16, 16);
    4.                 _uiStyle = EditorUI.ui.GetStyle("box_opaque");
    5.                 GUI.Box(startPage, string.Empty, _uiStyle);
    6.  
    7.                 GUI.Label(new Rect(startPage.x + 5, startPage.y + 5, startPage.width, 20), "START", EditorStyles.miniBoldLabel);
    8.                 _uiStyle = EditorUI.ui.GetStyle("connector_empty");
    9.                 if (GUI.Button(inputRect, string.Empty, _uiStyle)) {
    10.                     DrawCurve(inputRect, new Rect(100, 100, 10, 10));
    11.                 }
    I was originally trying to get it to display a line from the input Rect, to the mouse until another Rect has been selected, but that's a problem for another day.

    Thanks in advance!
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    GUI.Button is only true for the single frame that the button is pressed, so your DrawCurve is only called once
     
    Flickayy likes this.
  3. Flickayy

    Flickayy

    Joined:
    Jan 20, 2013
    Posts:
    40
    So, what do you think would be a suitable substitute? GUI.Toggle?

    EDIT:
    GUI.Toggle seems to be the approach for this, thanks for the helping hand.
     
    Last edited: Oct 27, 2015