public void DrawConnectionInputPointMark(OnNodeEvent eventSource, bool justConnecting) { if (scaleFactor != SCALE_MAX) { return; } var defaultPointTex = NodeGUIUtility.inputPointMarkTex; if (justConnecting && eventSource != null) { if (eventSource.eventSourceNode.nodeId != this.nodeId) { var connectionPoint = eventSource.eventSourceNode.ConnectionPointFromConPointId(eventSource.conPointId); if (connectionPoint.isOutput) { defaultPointTex = NodeGUIUtility.enablePointMarkTex; } } } var connectionPoints = WholeConnectionPoints(); foreach (var point in connectionPoints) { if (point.isInput) { var inputPointRect = GetInputRectForPoint(point); GUI.DrawTexture( inputPointRect, defaultPointTex ); } } }
public void DrawConnectionOutputPointMark(OnNodeEvent eventSource, bool justConnecting, Event current) { if (scaleFactor != SCALE_MAX) { return; } var defaultPointTex = NodeGUIUtility.outputPointMarkConnectedTex; if (justConnecting && eventSource != null) { if (eventSource.eventSourceNode.nodeId != this.nodeId) { var connectionPoint = eventSource.eventSourceNode.ConnectionPointFromConPointId(eventSource.conPointId); if (connectionPoint.isInput) { defaultPointTex = NodeGUIUtility.enablePointMarkTex; } } } var globalMousePosition = current.mousePosition; var connectionPoints = WholeConnectionPoints(); foreach (var point in connectionPoints) { if (point.isOutput) { var outputPointRect = GetOutputRectForPoint(point); GUI.DrawTexture( outputPointRect, defaultPointTex ); // eventPosition is contained by outputPointRect. if (outputPointRect.Contains(globalMousePosition)) { if (current.type == EventType.MouseDown) { NodeGUIUtility.FireNodeEvent(new OnNodeEvent(OnNodeEvent.EventType.EVENT_NODE_CONNECT_STARTED, this, current.mousePosition, point.pointId)); } } } } }
/** emit event from node-GUI. */ private void EmitNodeEvent(OnNodeEvent e) { switch (modifyMode) { case ModifyMode.CONNECT_STARTED: { switch (e.eventType) { /* handling */ case OnNodeEvent.EventType.EVENT_NODE_MOVING: { // do nothing. break; } /* connection drop detected from toward node. */ case OnNodeEvent.EventType.EVENT_NODE_CONNECTION_RAISED: { // finish connecting mode. modifyMode = ModifyMode.CONNECT_ENDED; if (currentEventSource == null) break; var sourceNode = currentEventSource.eventSourceNode; var sourceConnectionPoint = currentEventSource.eventSourceConnectionPoint; var targetNode = e.eventSourceNode; var targetConnectionPoint = e.eventSourceConnectionPoint; if (sourceNode.nodeId == targetNode.nodeId) break; if (!IsConnectablePointFromTo(sourceConnectionPoint, targetConnectionPoint)) break; var startNode = sourceNode; var startConnectionPoint = sourceConnectionPoint; var endNode = targetNode; var endConnectionPoint = targetConnectionPoint; // reverse if connected from input to output. if (sourceConnectionPoint.isInput) { startNode = targetNode; startConnectionPoint = targetConnectionPoint; endNode = sourceNode; endConnectionPoint = sourceConnectionPoint; } var label = startConnectionPoint.label; AddConnection(label, startNode, startConnectionPoint, endNode, endConnectionPoint); SaveGraphWithReload(); break; } /* connection drop detected by started node. */ case OnNodeEvent.EventType.EVENT_NODE_CONNECTION_OVERED: { // finish connecting mode. modifyMode = ModifyMode.CONNECT_ENDED; /* connect when dropped target is connectable from start connectionPoint. */ var candidateNodes = NodesUnderPosition(e.globalMousePosition); if (!candidateNodes.Any()) break; var nodeUnderMouse = candidateNodes[0]; // ignore if target node is source itself. if (nodeUnderMouse.nodeId == e.eventSourceNode.nodeId) break; var candidatePoints = nodeUnderMouse.ConnectionPointUnderGlobalPos(e.globalMousePosition); if (!candidatePoints.Any()) break; var sourcePoint = currentEventSource.eventSourceConnectionPoint; // limit by connectable or not. var connectableCandidates = candidatePoints.Where(point => IsConnectablePointFromTo(sourcePoint, point)).ToList(); if (!connectableCandidates.Any()) break; // target point is determined. var connectablePoint = connectableCandidates.First(); var startNode = e.eventSourceNode; var startConnectionPoint = currentEventSource.eventSourceConnectionPoint; var endNode = nodeUnderMouse; var endConnectionPoint = connectablePoint; // reverse if connected from input to output. if (startConnectionPoint.isInput) { startNode = nodeUnderMouse; startConnectionPoint = connectablePoint; endNode = e.eventSourceNode; endConnectionPoint = currentEventSource.eventSourceConnectionPoint; } var label = startConnectionPoint.label; AddConnection(label, startNode, startConnectionPoint, endNode, endConnectionPoint); SaveGraphWithReload(); break; } default: { // Debug.Log("unconsumed or ignored event:" + e.eventType); modifyMode = ModifyMode.CONNECT_ENDED; break; } } break; } case ModifyMode.CONNECT_ENDED: { switch (e.eventType) { /* node move detected. */ case OnNodeEvent.EventType.EVENT_NODE_MOVING: { var tappedNode = e.eventSourceNode; var tappedNodeId = tappedNode.nodeId; if (activeObject.idPosDict.ContainsKey(tappedNodeId)) { // already active, do nothing for this node. var distancePos = tappedNode.GetPos() - activeObject.idPosDict.ReadonlyDict()[tappedNodeId]; foreach (var node in nodes) { if (node.nodeId == tappedNodeId) continue; if (!activeObject.idPosDict.ContainsKey(node.nodeId)) continue; var relativePos = activeObject.idPosDict.ReadonlyDict()[node.nodeId] + distancePos; node.SetPos(relativePos); } break; } if (Event.current.shift) { Undo.RecordObject(this, "Select Objects"); var additiveIds = new List<string>(activeObject.idPosDict.ReadonlyDict().Keys); additiveIds.Add(tappedNodeId); activeObject = RenewActiveObject(additiveIds); UpdateActivationOfObjects(activeObject); UpdateSpacerRect(); break; } Undo.RecordObject(this, "Select Node"); activeObject = RenewActiveObject(new List<string>{tappedNodeId}); UpdateActivationOfObjects(activeObject); break; } /* start connection handling. */ case OnNodeEvent.EventType.EVENT_NODE_CONNECT_STARTED: { modifyMode = ModifyMode.CONNECT_STARTED; currentEventSource = e; break; } case OnNodeEvent.EventType.EVENT_CLOSE_TAPPED: { Undo.RecordObject(this, "Delete Node"); var deletingNodeId = e.eventSourceNode.nodeId; DeleteNode(deletingNodeId); SaveGraphWithReload(); InitializeGraph(); break; } /* releasse detected. node move over. node tapped. */ case OnNodeEvent.EventType.EVENT_NODE_TOUCHED: { var movedNode = e.eventSourceNode; var movedNodeId = movedNode.nodeId; // already active, node(s) are just tapped or moved. if (activeObject.idPosDict.ContainsKey(movedNodeId)) { /* active nodes(contains tap released node) are possibly moved. */ var movedIdPosDict = new Dictionary<string, Vector2>(); foreach (var node in nodes) { if (!activeObject.idPosDict.ContainsKey(node.nodeId)) continue; var startPos = activeObject.idPosDict.ReadonlyDict()[node.nodeId]; if (node.GetPos() != startPos) { // moved. movedIdPosDict[node.nodeId] = node.GetPos(); } } if (movedIdPosDict.Any()) { foreach (var node in nodes) { if (activeObject.idPosDict.ReadonlyDict().Keys.Contains(node.nodeId)) { var startPos = activeObject.idPosDict.ReadonlyDict()[node.nodeId]; node.SetPos(startPos); } } Undo.RecordObject(this, "Move Node"); foreach (var node in nodes) { if (movedIdPosDict.Keys.Contains(node.nodeId)) { var endPos = movedIdPosDict[node.nodeId]; node.SetPos(endPos); } } var activeObjectIds = activeObject.idPosDict.ReadonlyDict().Keys.ToList(); activeObject = RenewActiveObject(activeObjectIds); } else { // nothing moved, should cancel selecting this node. var cancelledActivatedIds = new List<string>(activeObject.idPosDict.ReadonlyDict().Keys); cancelledActivatedIds.Remove(movedNodeId); Undo.RecordObject(this, "Select Objects"); activeObject = RenewActiveObject(cancelledActivatedIds); } UpdateActivationOfObjects(activeObject); UpdateSpacerRect(); SaveGraph(); break; } if (Event.current.shift) { Undo.RecordObject(this, "Select Objects"); var additiveIds = new List<string>(activeObject.idPosDict.ReadonlyDict().Keys); // already contained, cancel. if (additiveIds.Contains(movedNodeId)) { additiveIds.Remove(movedNodeId); } else { additiveIds.Add(movedNodeId); } activeObject = RenewActiveObject(additiveIds); UpdateActivationOfObjects(activeObject); UpdateSpacerRect(); SaveGraph(); break; } Undo.RecordObject(this, "Select Node"); activeObject = RenewActiveObject(new List<string>{movedNodeId}); UpdateActivationOfObjects(activeObject); UpdateSpacerRect(); SaveGraph(); break; } default: { // Debug.Log("unconsumed or ignored event:" + e.eventType); break; } } break; } } switch (e.eventType) { case OnNodeEvent.EventType.EVENT_CONNECTIONPOINT_DELETED: { var deletedConnectionPoint = e.eventSourceConnectionPoint; var deletedOutputPointConnections = connections.Where(con => con.outputPoint.pointId == deletedConnectionPoint.pointId).ToList(); if (!deletedOutputPointConnections.Any()) break; connections.Remove(deletedOutputPointConnections[0]); break; } case OnNodeEvent.EventType.EVENT_CONNECTIONPOINT_LABELCHANGED: { var labelChangedConnectionPoint = e.eventSourceConnectionPoint; var changedLabel = labelChangedConnectionPoint.label; var labelChangedOutputPointConnections = connections.Where(con => con.outputPoint.pointId == labelChangedConnectionPoint.pointId).ToList(); if (!labelChangedOutputPointConnections.Any()) break; labelChangedOutputPointConnections[0].label = changedLabel; break; } case OnNodeEvent.EventType.EVENT_BEFORESAVE: { Undo.RecordObject(this, "Update Node Setting"); break; } case OnNodeEvent.EventType.EVENT_SAVE: { SaveGraphWithReloadSilent(); Repaint(); break; } } }
private void DrawStraightLineFromCurrentEventSourcePointTo(Vector2 to, OnNodeEvent eventSource) { if (eventSource == null) return; var p = eventSource.eventSourceNode.GlobalConnectionPointPosition(eventSource.eventSourceConnectionPoint); Handles.DrawLine(new Vector3(p.x, p.y, 0f), new Vector3(to.x, to.y, 0f)); }
public void DrawConnectionOutputPointMark(OnNodeEvent eventSource, bool justConnecting, Event current) { if (scaleFactor != SCALE_MAX) return; var defaultPointTex = outputPointMarkConnectedTex; if (justConnecting && eventSource != null) { if (eventSource.eventSourceNode.nodeId != this.nodeId) { if (eventSource.eventSourceConnectionPoint.isInput) { defaultPointTex = enablePointMarkTex; } } } var globalMousePosition = current.mousePosition; foreach (var point in connectionPoints) { if (point.isOutput) { var outputPointRect = OutputRect(point); GUI.DrawTexture( outputPointRect, defaultPointTex ); // eventPosition is contained by outputPointRect. if (outputPointRect.Contains(globalMousePosition)) { if (current.type == EventType.MouseDown) { Emit(new OnNodeEvent(OnNodeEvent.EventType.EVENT_NODE_CONNECT_STARTED, this, current.mousePosition, point)); } } } } }
public void DrawConnectionInputPointMark(OnNodeEvent eventSource, bool justConnecting) { if (scaleFactor != SCALE_MAX) return; var defaultPointTex = inputPointMarkTex; if (justConnecting && eventSource != null) { if (eventSource.eventSourceNode.nodeId != this.nodeId) { if (eventSource.eventSourceConnectionPoint.isOutput) { defaultPointTex = enablePointMarkTex; } } } foreach (var point in connectionPoints) { if (point.isInput) { GUI.DrawTexture( new Rect( baseRect.x - 2f, baseRect.y + (baseRect.height - AssetBundleGraphGUISettings.CONNECTION_POINT_MARK_SIZE)/2f, AssetBundleGraphGUISettings.CONNECTION_POINT_MARK_SIZE, AssetBundleGraphGUISettings.CONNECTION_POINT_MARK_SIZE ), defaultPointTex ); } } }