public void OnGUI() { NodeEditor.checkInit(); if (NodeEditor.InitiationError) { GUILayout.Label("Initiation failed! Check console for more information!"); return; } AssureHasEditor(); // Example of creating Nodes and Connections through code // CalcNode calcNode1 = CalcNode.Create (new Rect (200, 200, 200, 100)); // CalcNode calcNode2 = CalcNode.Create (new Rect (600, 200, 200, 100)); // Node.ApplyConnection (calcNode1.Outputs [0], calcNode2.Inputs [0]); mainEditorState.canvasRect = canvasWindowRect; try { NodeEditor.DrawCanvas(mainNodeCanvas, mainEditorState); } catch (UnityException e) { // on exceptions in drawing flush the canvas to avoid locking the ui. NewNodeCanvas(); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } // Draw Side Window sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5))); NodeEditorGUI.StartNodeGUI(); GUILayout.BeginArea(sideWindowRect, GUI.skin.box); DrawSideWindow(); GUILayout.EndArea(); NodeEditorGUI.EndNodeGUI(); }
/// <summary> /// Draws the Node Canvas on the screen in the rect specified by editorState /// </summary> public static void DrawCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState) { if (!editorState.drawing) { return; } checkInit(); NodeEditorGUI.StartNodeGUI(); OverlayGUI.StartOverlayGUI(); DrawSubCanvas(nodeCanvas, editorState); OverlayGUI.EndOverlayGUI(); NodeEditorGUI.EndNodeGUI(); }
/// <summary> /// Used to display a custom node property editor in the GUI. /// By default shows the standard NodeGUI. /// </summary> public virtual void DrawNodePropertyEditor() { try { // Draw Node GUI without disturbing knob placement ignoreGUIKnobPlacement = true; NodeEditorGUI.StartNodeGUI(false); GUILayout.BeginVertical(GUI.skin.box); NodeGUI(); GUILayout.EndVertical(); NodeEditorGUI.EndNodeGUI(); } finally { // Be sure to always reset the state to not mess up other GUI code ignoreGUIKnobPlacement = false; } }
public void OnGUI() { // Initiation NodeEditor.checkInit(); if (NodeEditor.InitiationError) { GUILayout.Label("Initiation failed! Check console for more information!"); return; } AssureHasEditor(); if (mainNodeCanvas == null) { NewNodeCanvas(); } //Debug.Log ("mainNodeCanvas " + mainNodeCanvas.name); // Specify the Canvas rect in the EditorState mainEditorState.canvasRect = canvasWindowRect; // If you want to use GetRect: // Rect canvasRect = GUILayoutUtility.GetRect (600, 600); // if (Event.current.type != EventType.Layout) // mainEditorState.canvasRect = canvasRect; // Perform drawing with error-handling try { NodeEditor.DrawCanvas(mainNodeCanvas, mainEditorState); } catch (UnityException e) { // on exceptions in drawing flush the canvas to avoid locking the ui. NewNodeCanvas(); Debug.LogError("Unloaded Canvas due to exception in Draw!"); Debug.LogException(e); } // Draw Side Window sideWindowWidth = Math.Min(600, Math.Max(200, (int)(position.width / 5))); NodeEditorGUI.StartNodeGUI(); GUILayout.BeginArea(sideWindowRect, GUI.skin.box); DrawSideWindow(); GUILayout.EndArea(); NodeEditorGUI.EndNodeGUI(); }