public GraphEvent(GEType type, GEContext context, Node node, IOOutlet outlet) { Type = type; Context = context; Node = node; Outlet = outlet; }
public IOConnection(Operator a, IOOutlet o, Operator b, IOOutlet i) { From = a; Output = o; To = b; Input = i; }
public GraphEvent(GEType type, GEContext context, Node node, IOOutlet outlet) { Type = type; Context = context; Node = node; Outlet = outlet; PositionData = Vector2.zero; }
public static void DrawConnections(this Template template) { if (_FloatingTextStyle == null) { _FloatingTextStyle = new GUIStyle(); _FloatingTextStyle.alignment = TextAnchor.UpperRight; _FloatingTextStyle.normal.textColor = Color.white; _FloatingTextStyle.fontSize = 16; } // Connections foreach (IOConnection conn in template.Connections) { Node a = GraphEditor.GetNode(conn.From.GUID); Node b = GraphEditor.GetNode(conn.To.GUID); DrawBezier(a.OutputOutlet(conn.Output), b.InputOutlet(conn.Input)); } // Open connections if (GraphEditor.CurrentEvent.Type == GEType.Drag) { Node node = GraphEditor.CurrentEvent.Node; IOOutlet outlet = GraphEditor.CurrentEvent.Outlet; Vector2 mousePos = Event.current.mousePosition; bool validConnection = false; // Dragging from Input if (GraphEditor.CurrentEvent.Context == GEContext.Input) { Vector2 inPoint = node.InputOutlet(outlet); DrawBezier(mousePos, inPoint); validConnection = true; } // Dragging from Output if (GraphEditor.CurrentEvent.Context == GEContext.Output) { Vector2 outPoint = node.OutputOutlet(outlet); DrawBezier(outPoint, mousePos); validConnection = true; } if (validConnection) { var point = mousePos + new Vector2(0f, 20f); string label = System.String.Format("{0}\n{1}", outlet.Name, outlet.DataType.TypeAlias(), _FloatingTextStyle); Handles.Label(point, label); } } }
public Vector2 OutputOutlet(IOOutlet target) { for (int i = 0; i < Operator.Outputs.Length; i++) { if (Operator.Outputs[i].Name == target.Name) { float height = TitleHeight * _cachedScale + TitleSeparator; height += (i * IOHeight) * _cachedScale; height += (IOHeight * _cachedScale) / 2; return(new Vector2( NodeRect.x + NodeRect.width, NodeRect.y + height )); } } return(new Vector2(NodeRect.x, NodeRect.y)); }
public bool EventsNeedRepaint(float scale, GraphEditor graphEditor) { bool needsRepaint = false, showType = false; int inputHover = -1, outputHover = -1; var scaledIOHeight = IOHeight * scale; if (scale != _cachedScale) { RecalculateBounds(scale); } Event ev = Event.current; bool mouseInNode = NodeRect.Contains(ev.mousePosition); bool mouseInInputs = InputsRect.Contains(ev.mousePosition); bool mouseInOutputs = OutputsRect.Contains(ev.mousePosition); // MouseOver node if (mouseInNode || mouseInInputs || mouseInOutputs) { showType = true; } // MouseOver inputs int inputIndex = Mathf.FloorToInt((ev.mousePosition.y - InputsRect.y) / scaledIOHeight); if (mouseInInputs) { inputHover = inputIndex; } // MouseOver outputs int outputIndex = Mathf.FloorToInt((ev.mousePosition.y - OutputsRect.y) / scaledIOHeight); if (mouseInOutputs) { outputHover = outputIndex; } // Left mouse button actions if (ev.button == 0) { // MouseDown outlets if (ev.type == EventType.MouseDown) { // Input if (mouseInInputs && inputIndex < Operator.Inputs.Length) { GraphEditor.CurrentEvent = new GraphEvent(GEType.Unresolved, GEContext.Input, this, Operator.Inputs[inputIndex]); } // Output if (mouseInOutputs && outputIndex < Operator.Outputs.Length) { GraphEditor.CurrentEvent = new GraphEvent(GEType.Unresolved, GEContext.Output, this, Operator.Outputs[outputIndex]); } } // MouseUp outlets if (ev.type == EventType.MouseUp) { // Releasing Output on Input if (mouseInInputs && GraphEditor.CurrentEvent.Type == GEType.Drag && GraphEditor.CurrentEvent.Context == GEContext.Output) { if (IOOutlet.CanConnect(GraphEditor.CurrentEvent.Outlet, Operator.Inputs[inputIndex])) { GraphEditor.Template.Connect( GraphEditor.CurrentEvent.Node.Operator, GraphEditor.CurrentEvent.Outlet, Operator, Operator.Inputs[inputIndex] ); } GraphEditor.CurrentEvent.Empty(); needsRepaint = true; } // Releasing Input on Output if (mouseInOutputs && GraphEditor.CurrentEvent.Type == GEType.Drag && GraphEditor.CurrentEvent.Context == GEContext.Input) { if (IOOutlet.CanConnect(Operator.Outputs[inputIndex], GraphEditor.CurrentEvent.Outlet)) { GraphEditor.Template.Connect( Operator, Operator.Outputs[inputIndex], GraphEditor.CurrentEvent.Node.Operator, GraphEditor.CurrentEvent.Outlet ); } GraphEditor.CurrentEvent.Empty(); needsRepaint = true; } } // Mouse cursor over node if (NodeRect.Contains(ev.mousePosition)) { // Mouse Down if (ev.type == EventType.MouseDown) { GraphEditor.CurrentEvent = new GraphEvent(GEType.Unresolved, GEContext.Node, this, IOOutlet.None, (ev.mousePosition / scale) - Operator.EditorPosition); } // Mouse Up if (ev.type == EventType.MouseUp && GraphEditor.CurrentEvent.Type == GEType.Unresolved) { if (!GraphEditor.Selection.Contains(this)) { if (Event.current.modifiers == EventModifiers.Shift) { GraphEditor.Selection.Add(this); } else { GraphEditor.Selection.Clear(); GraphEditor.Selection.Add(this); } } needsRepaint = true; } else if (ev.type == EventType.MouseUp && GraphEditor.CurrentEvent.Node == this && GraphEditor.CurrentEvent.Type == GEType.Drag) { GraphEditor.Template.Serialize(); } } // MouseDrag if (ev.type == EventType.MouseDrag) { // Drag node if (GraphEditor.CurrentEvent.IsNodeDrag(this)) { Vector2 newPosition = (ev.mousePosition / scale) - GraphEditor.CurrentEvent.PositionData; Vector2 snapOffset = new Vector2(newPosition.x % GridRenderer.StepSize, newPosition.y % GridRenderer.StepSize); Operator.EditorPosition = newPosition - snapOffset; RecalculateBounds(scale); GraphEditor.CurrentEvent.Type = GEType.Drag; needsRepaint = true; } // Drag input else if (GraphEditor.CurrentEvent.CanDragOutlet(this, GEContext.Input)) { var connections = GraphEditor.Template.ConnectionsTo(Operator, GraphEditor.CurrentEvent.Outlet); if (connections.Length > 0) { var last = connections[connections.Length - 1]; var fromNode = GraphEditor.GetNode(last.From.GUID); GraphEditor.CurrentEvent = new GraphEvent(GEType.Drag, GEContext.Output, fromNode, last.Output); GraphEditor.Template.Disconnect(last); needsRepaint = true; } } // Drag output else if (GraphEditor.CurrentEvent.CanDragOutlet(this, GEContext.Output)) { GraphEditor.CurrentEvent = new GraphEvent(GEType.Drag, GEContext.Output, this, GraphEditor.CurrentEvent.Outlet); needsRepaint = true; } } } if (showType != ShowType || inputHover != InputHover || outputHover != OutputHover) { ShowType = showType; InputHover = inputHover; OutputHover = outputHover; needsRepaint = true; } return(needsRepaint); }
public Vector2 OutputOutlet(IOOutlet target) { for (int i = 0; i < Operator.Outputs.Length; i++) { if (Operator.Outputs[i].Name == target.Name) { float height = TitleHeight * _cachedScale + TitleSeparator; height += (i * IOHeight) * _cachedScale; height += (IOHeight * _cachedScale) / 2; return new Vector2( NodeRect.x + NodeRect.width, NodeRect.y + height ); } } return new Vector2(NodeRect.x, NodeRect.y); }
public static string GetNiceName(this IOOutlet outlet) { return(ObjectNames.NicifyVariableName(outlet.Member.Name)); }