Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. 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:
    261
    @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:
    261
    @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,203
    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:
    8
    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,203
    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.
     
  15. MegaMasterX

    MegaMasterX

    Joined:
    Apr 6, 2014
    Posts:
    9
    Hey there. Got the LTS packages installed (per documentation) and implemented some basic nodes but the Node Editor window is flat out not showing up when going to Window > Node Editor. There aren't any errors being thrown either; Hopefully I'm just missing something simple. Thoughts?
     
  16. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,203
    Latest version I have currently installed is 2019.4, but I've tested 2020 before too, and no problems. Added using package manager with the git urls and it's opening just fine. Any exact unity version? Does this happen in an empty project as well?
    The window, at the very least, should always show, even if something in the setup failed. That makes me think maybe your layout is messed up - maybe try Window/Layout/Revert?
     
    Last edited: Jan 14, 2021
    MegaMasterX likes this.
  17. MegaMasterX

    MegaMasterX

    Joined:
    Apr 6, 2014
    Posts:
    9
    I'm currently using 2020.2.0f1.

    It looks like resetting the layout worked. Thank you!
     
  18. GintarasOE

    GintarasOE

    Joined:
    Sep 17, 2019
    Posts:
    2
    Hi, so a lot of stuff in this thread - maybe I just missed something but: is there any way to get something like nodes tree? Some representation of what nodes are used and how are they connected?

    Basically, I'm working on some code generation tool, the idea is: user adds and connects nodes in the way he wants and the system outputs generated script. I want to have one node responsible for file generation let's call it "OutputNode" - this node needs to get some representation of all nodes in canvas it is in and how each of them connects to properly resolve what code to put in the output file.

    Is there any way to get this info?
     
  19. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,203
    Sure, I'll quickly go over two parts to this.

    First, structure.
    Make a custom canvas, where you can decide whether you want to allow loops or not.
    Then decide where you want to put the generation code. If you only want one Output per graph, I recommend you to not have the code in the output node itself (although you can) but in a traversal routine (check examples, especially the standard calculation). Then read some setup parameters from the output node. Then it's just a matter of going through the node structure (see the traversal, some runtime examples, or FlowNode for that). You have the responsibility in your custom nodes to call something like
    Code (CSharp):
    1. NodeEditor.curNodeCanvas.OnNodeChange (this);
    to notify your traversal routine that a node updated.
    You can enforce only one output node (and have it appear by default), see graph canvas example for a similar example.

    Second, visuals.
    FlowNode has some examples of explicit knob placement, you can also put them on top to get a vertical graph, etc. Unfortunately there's no toggle to switch to straight lines so if that's the visual you're going for, you can add an overload here to this function).
     
  20. GintarasOE

    GintarasOE

    Joined:
    Sep 17, 2019
    Posts:
    2
    Thank you! It seems that slowly I'm starting to get where I want.
     
unityunity