Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. 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

Simple node editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by unimechanic, Jul 5, 2013.

  1. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    Hey guys

    I'm trying to get a GUILayout.Button to show/hide another GUILayout.Button on a node, but I can't figure out how.

    Anyone know how to do that?

    Code (CSharp):
    1.  GUILayout.Space(5);
    2.             if (GUILayout.Button(GoalActive ? "IsGOAL" : "IsNotGOAL"))
    3.                 GoalActive = !GoalActive;
    4.            
    5.             GUILayout.Space(5);
    6.             if (GUILayout.Button(maxMinSwitch ? "MAX" : "MIN"))
    7.                 maxMinSwitch = !maxMinSwitch;
    GoalActive needs to show/hide maxMinSwitch.
     
  2. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    204
    @Jamsa78 I think you just need to wrap another if statement around the 2nd button's if statement, like this:

    Code (CSharp):
    1. GUILayout.Space(5);
    2. if (GUILayout.Button(GoalActive ? "IsGOAL" : "IsNotGOAL"))
    3.     GoalActive = !GoalActive;
    4.  
    5. GUILayout.Space(5);
    6. if (GoalActive) {
    7.     if (GUILayout.Button(maxMinSwitch ? "MAX" : "MIN"))
    8.         maxMinSwitch = !maxMinSwitch;
    9. }
    10.  
    Therefore, if GoalActive (in the example code here) is false, then the GUILayout.Button(...) code will not run at all, and thus, no button will be drawn.
    When GoalActive turns true, then it will show the button.
     
    Jamsa78 likes this.
  3. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    Heh, you know...sometime it's just the simple stuff you overlook. :D

    Thanks, it's works perfectly! :)
     
    ModLunar likes this.
  4. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    And now that I have that working, I would like to change the GoalActive to a standard "boring" checkbox.

    I've tried using a toggle, but being a mere casual unity dev, the standard example is useless. And I don't even know if that's the right one to use. :D
     
  5. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    204
    @Jamsa78 Hahah I know right? You're welcome, glad to help!

    Oh, what's wrong with using EditorGUILayout.Toggle(...)?
     
    Jamsa78 likes this.
  6. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    ...not working runtime? :) Sorry, didn't mention that little detail. :D
     
  7. StephenL

    StephenL

    Joined:
    Oct 18, 2010
    Posts:
    218
    GUILayout.Toggle()
     
  8. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    Yeah...as I said I couldn't get it to work.

    If I'm not getting compile error, the program hangs when adding a node with the toggle. :(

    But maybe you've got an example that works? :)
     
  9. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    ...and just like that, it works today.

    I swear, my pc is the weirdest pc ever. :D
     
  10. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    88
    Hey guys

    I'm trying to implement a logging function to log when the user:
    • Adds a new node (ID(=the node name) and location)
    • Deletes a node(type and id)
    • Moves a node(id and to/from position)
    • Creates a connection(from and to (node id and knob name) )
    • Deletes a connection(from and to (node id and knob name) )
    • Changes to node properties( like name, value, toggle etc)
    • Saves/loads a canvas (filename)
    Anybody got idea as to do this a sensible way? :D

    The default log is "contaminated" by unity logentries, so that can't used. It has to be a separate, dedicated log. :)

    And yes, this is also something that has to work runtime. ;)
     
  11. pnf4665jds

    pnf4665jds

    Joined:
    Jun 4, 2020
    Posts:
    1
    Hi, I am trying to make a node that display the executing time at run time.

    But, the problem is that the showed time will not increase and the value depends on when I open the canvas.

    Is there any way to make a dynamic display at run time?
     
  12. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,201
    Sorry for the late reply. Just like any other window the Node Editor Window is usually only drawn when something changes. I guess you can call the repaint function of the editor window (found using getwindow) to ensure it keeps being drawn. You can either call it each time such a node is drawn to ensure fastest update rate or call it in a separate update loop at your own pace.
    There are several events you can subscribe to; all but change to node properties are supported. That one is a bit tricky, but I guess you could add a GUI.changed check after each NodeGUI to get this - however you'll not know WHAT exactly changed unless you do a SerializedObject comparision or manually whip up some reflection logic.
     
  13. Achondrite

    Achondrite

    Joined:
    Sep 23, 2015
    Posts:
    7
    I'm having issues sorting the rendered NEF nodes in IMGUI with unity other canvases.
    I thought rendering the output of NEF to a render target would be the way to go.

    My setup holds a few regions and subwindows with one on the bottom containing the NEF.
    Rendering to a render target works but the nodes are not rendered on the same position as without rendering to a rendertexture.
    It seems like the nodes are rendered too much (the y-offset of my subwindow containing NEF to the top of the application window) to the bottom.
    I've been trying to play with the canvasRect and other parameters but with no success so far.

    Does anyone have some pointers on how to get this right?

    Thanks
     
  14. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,201
    Rendering to a render target sounds like a workaround to me, not a solution.
    Haven't worked too much with GUI at runtime, but GUI.depth sounds like something to look into.
    Try to set it in the RTNodeEditor script before rendering and reset it afterwards.
     
unityunity