public void SetCanvasPosition(Vector2 value, GUI_Info info) { if (!info.scrollWindow) { this.SetSerializedValue("positionSize", new Rect(value - nodeCanvas.scrollOffset, positionSize.size)); } }
public void AddDelta(Vector2 delta, GUI_Info info) { foreach (var node in nodes) { node.SetCanvasPosition(node.canvasPosition + delta, info); } }
public Vector2 GetGUIPosForOrderGraph(Vector2 size, GUI_Info info) { var r = positionSize; r.position = canvasPosition; r.x += (r.width - size.x) * 0.5f; r.y -= size.y; return(r.position); }
/// <summary> /// Returns the tree output knob that is at the position on this node or null /// </summary> public NodeTreeOutput GetTreeOutputAtPos(Vector2 pos, GUI_Info info) { foreach (var treeOutput in treeOutputs) // Search for an output at the position { if (treeOutput.GetKnobRect(info).Contains(pos)) { return(treeOutput); } } return(null); }
/// <summary> /// Returns the input knob that is at the position on this node or null /// </summary> public NodeInput GetInputAtPos(Vector2 pos, GUI_Info info) { foreach (var input in inputs) // Search for an input at the position { if (input.GetKnobRect(info).Contains(pos)) { return(input); } } return(null); }
public override void OnSelectedDrawCanvas(GUI_Info info) { foreach (var g in groups) { if (g != null) { UnityEditor.Handles.DrawLine(canvasPositionPixelCorrected * info.zoom, g.CanvasPositionPixelCorrected * info.zoom); } } foreach (var n in nodes) { if (n != null) { UnityEditor.Handles.DrawLine(canvasPositionPixelCorrected * info.zoom, n.canvasPositionPixelCorrected * info.zoom); } } }
/// <summary> /// Function implemented by the children to draw the node /// </summary> public void Draw(GUI_Info guiInfo) { CheckArray(); if (nodes.Length == 0) { OnDelete(); } else { if (boxStyle == null || boxStyle.normal.background == null) { boxStyle = new GUIStyle(GUI.skin.box); boxStyle.normal.background = ColorToTex(new Color(1, 1, 1, 1), new Color(1, 1, 1, 0.3f)); boxStyle.padding = boxStyle.margin = new RectOffset(); boxStyle.border = new RectOffset(1, 1, 1, 1); boxStyle.normal.textColor = GetTextColor(color); } Color originalColor = GUI.backgroundColor; GUI.backgroundColor = color; Rect r = RectPixelCorrected; r.size = PositionSize.size; GUI.Box(r, groupName, boxStyle); GUI.backgroundColor = originalColor; Rect rColor = RectPixelCorrected; rColor.size = new Vector2(40, 20); rColor.x += PositionSize.size.x - 40; try { var oldColor = color; SetColor(UnityEditor.EditorGUI.ColorField(rColor, color)); if (oldColor != color) { boxStyle.normal.textColor = GetTextColor(color); } } catch (ExitGUIException) { } } }
public void OnGUI() { checkInit(); guiInfo = new GUI_Info(scrollWindow, knobSize, null != nodeCanvas ? nodeCanvas.zoom.GetZoom() : 1); nodeCanvas = (Context)EditorGUILayout.ObjectField(nodeCanvas, typeof(Context), true); if (nodeCanvas == null && 0 != nodeCanvasInstanceId) { nodeCanvas = EditorUtility.InstanceIDToObject(nodeCanvasInstanceId) as Context; if (null == nodeCanvas) { nodeCanvasInstanceId = 0; } } if (nodeCanvas == null) { return; } nodeCanvasInstanceId = nodeCanvas.GetInstanceID(); SetEditorColor(); try { // Draw Background when Repainting if (Event.current.type == EventType.Repaint) // Draw background when repainting { float w = GUI_Info.Background.width * nodeCanvas.zoom.GetZoom(); float h = GUI_Info.Background.height * nodeCanvas.zoom.GetZoom(); Vector2 offset = new Vector2((nodeCanvas.scrollOffset.x * nodeCanvas.zoom.GetZoom()) % w - w, (nodeCanvas.scrollOffset.y * nodeCanvas.zoom.GetZoom()) % h - h); int tileX = Mathf.CeilToInt((position.width + (w - offset.x)) / w); int tileY = Mathf.CeilToInt((position.height + (h - offset.y)) / h); for (int x = 0; x < tileX; x++) { for (int y = 0; y < tileY; y++) { GUI.DrawTexture(new Rect(offset.x + x * w, offset.y + y * h, w, h), GUI_Info.Background); } } } // We want to scale our nodes, but as GUI.matrix also scales our widnow's clipping group, // we have to scale it up first to receive a correct one as a result // End the default clipping group GUI.EndGroup(); // The Rect of the new clipping group to draw our nodes in Rect ScaledCanvasRect = new Rect(0, 23, (position.width - sideWindowRect.width) / nodeCanvas.zoom.GetZoom(), position.height / nodeCanvas.zoom.GetZoom()); // Now continue drawing using the new clipping group GUI.BeginGroup(ScaledCanvasRect); // Apply zoom GUIUtility.ScaleAroundPivot(Vector2.one * nodeCanvas.zoom.GetZoom(), Vector2.zero); // Draw groups nodeCanvas.ForeachGroup(g => g.Draw(guiInfo)); // draw window connectors + window buttons nodeCanvas.ForeachNode(DrawNodeCurves); nodeCanvas.ForeachNode(DrawNodeKnobs); InputEvents(); // Draw nodes BeginWindows(); for (int i = 0; i < nodeCanvas.GetNodesLength(); i++) { var node = nodeCanvas.GetNode(i); if (!node.CalculateVisibility(position.size / nodeCanvas.zoom.GetZoom())) { GUILayout.Window(i, node.rectPixelCorrected, DrawNode, node.GetName(), GUI_Info.nodeStyle); } else { Color originalColor = GUI.backgroundColor; GUI.backgroundColor = nodeCanvas.GetFirstNode() == node ? firstNodeColor : nodeCanvas.StackContainsNode(node) ? nodeInStackColor : node == selectedNode ? selectedNodeColor : nonExecutedColor; GUI.backgroundColor = Color.Lerp(executingNodeColor, GUI.backgroundColor, (Time.time - node.lastExecutedTime) / decayInSeconds); GUI.color = Color.white; Rect startRect = node.positionSize; Rect r = GUILayout.Window(i, node.rectPixelCorrected, DrawNode, node.GetName(), GUI_Info.nodeStyle); if (!nodeCanvas.zoom.IsZooming) { node.SetCanvasPosition(r.position, guiInfo); if (r.size != Vector2.zero) { node.positionSize.size = r.size; } if (startRect != node.positionSize) { nodeCanvas.ForeachGroup(g => g.needsUpdate = true); } } GUI.backgroundColor = originalColor; } } EndWindows(); // Draw gui order debug if (nodeCanvas.debug) { Color c = GUI.color; if (nodeCanvas.stepByStep && nodeCanvas.calledElementsInOrder.Count > 0 && nodeCanvas.calledElementsInOrder[curDebugStep].sender != null) { Vector2 pos = nodeCanvas.calledElementsInOrder[curDebugStep].sender.GetGUIPosForOrderGraph(debugBoxSize, guiInfo); GUI.color = Color.red; GUI.Box(new Rect(pos, debugBoxSize), nodeCanvas.calledElementsInOrder[curDebugStep].text); } GUI.color = c; } Repaint(); // undo zoom GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one); GUI.EndGroup(); if (selectedNode != null) { selectedNode.OnSelectedDrawCanvas(guiInfo); } // Now continue drawing using the new clipping group GUI.BeginGroup(new Rect(0, 23, position.width, position.height)); // Now continue drawing using the new clipping group GUILayout.BeginArea(sideWindowRect, GUI_Info.nodeBox); DrawSideWindow(); GUILayout.EndArea(); if (Event.current.type == EventType.Repaint) { ProcessDeferredNodesToDelete(); ProcessDeferredGroupsToDelete(); } } catch (Exception e) { Debug.LogError(e, this); } UndoEditorColor(); nodeCanvas.zoom.GUIUpdate(this); }
public virtual void OnSelectedDrawCanvas(GUI_Info info) { }