[EventHandlerAttribute(EventType.MouseDown, 0)] // One of the highest priorities after node selection private static void HandleContextClicks(NodeEditorInputInfo inputInfo) { if (Event.current.button == 1) { // Handle context clicks on Node and canvas NodeEditorState state = inputInfo.editorState; GenericMenu contextMenu = new GenericMenu(); if (inputInfo.editorState.focusedNode != null) // Node Context Click { if (!state.selectedNodes.Contains(state.focusedNode)) //&& state.focusedNode != state.selectedNode) { state.selectedNodes.Clear(); state.selectedNodes.Add(state.focusedNode); state.selectedNode = state.focusedNode; } FillContextMenu(inputInfo, contextMenu, ContextType.Node); } else // Editor Context Click { FillContextMenu(inputInfo, contextMenu, ContextType.Canvas); } contextMenu.Show(inputInfo.inputPos); Event.current.Use(); } }
public static void ShowContextMenu(NodeEditorInputInfo inputInfo) { GenericMenu contextMenu = new GenericMenu(); FillContextMenu(inputInfo, contextMenu, ContextType.Canvas); contextMenu.Show(inputInfo.inputPos); }
private static void HandleNodeDraggingEnd(NodeEditorInputInfo inputInfo) { if (inputInfo.editorState.dragUserID == "node") { Vector2 dragStart = inputInfo.editorState.dragObjectStart; Vector2 dragEnd = inputInfo.editorState.EndDrag("node"); if (inputInfo.editorState.dragNode && inputInfo.editorState.selectedNode) { if ((dragStart - dragEnd).magnitude > 10) { inputInfo.editorState.selectedNode.position = dragEnd; #if UNITY_EDITOR // Important: Copy variables used within anonymous functions within same level (this if block) for correct serialization! float prevX = dragStart.x, prevY = dragStart.y, newX = dragEnd.x, newY = dragEnd.y; Node draggedNode = inputInfo.editorState.selectedNode; UndoPro.UndoProManager.RecordOperation( () => NodeEditorUndoActions.SetNodePosition(draggedNode, new Vector2(newX, newY)), () => NodeEditorUndoActions.SetNodePosition(draggedNode, new Vector2(prevX, prevY)), "Node Drag", true, false); #endif NodeEditorCallbacks.IssueOnMoveNode(inputInfo.editorState.selectedNode); } else { inputInfo.editorState.selectedNode.position = dragStart; } } } inputInfo.editorState.dragNode = false; }
private static void HandleNodeDragging(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (state.dragNode) { // If conditions apply, drag the selected node, else disable dragging if (state.selectedNode != null && inputInfo.editorState.dragUserID == "node") { // Apply new position for the dragged node state.UpdateDrag("node", inputInfo.inputPos); if ((state.dragObjectPos - state.dragObjectStart).magnitude > 10) { state.selectedNode.position = state.dragObjectPos; } else { state.selectedNode.position = state.dragObjectStart; } NodeEditor.RepaintClients(); } else { state.dragNode = false; } } }
private static void HandleNodeDragging(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (state.dragNode) { // If conditions apply, drag the selected node, else disable dragging if (state.selectedNode != null && GUIUtility.hotControl == 0) { // Calculate new position for the dragged object state.dragOffset = inputInfo.inputPos - state.dragStart; Vector2 delta = (state.dragPos + state.dragOffset * state.zoom) - state.selectedNode.rect.position; state.selectedNode.rect.position = state.dragPos + state.dragOffset * state.zoom; if (inputInfo.inputEvent.alt) { Dictionary <Node, int> d = new Dictionary <Node, int>(); d[state.selectedNode] = 1; MoveChildren(ref d, state.selectedNode, delta); } NodeEditorCallbacks.IssueOnMoveNode(state.selectedNode); NodeEditor.RepaintClients(); } else { state.dragNode = false; } } }
[EventHandlerAttribute(EventType.MouseDown, -2)] // Absolute second to call! private static void HandleSelecting(NodeEditorInputInfo inputInfo) { if (inputInfo.inputEvent.button == 0 && inputInfo.editorState.focusedNode != inputInfo.editorState.selectedNode) { // Select focussed Node inputInfo.editorState.selectedNode = inputInfo.editorState.focusedNode; #if UNITY_EDITOR NodeEditorState state = inputInfo.editorState; Node prevSelection = state.selectedNode, newSelection = state.focusedNode; UndoPro.UndoProManager.RecordOperation( () => NodeEditorUndoActions.SetNodeSelection(state, newSelection), () => NodeEditorUndoActions.SetNodeSelection(state, prevSelection), "Node Selection", false, true); #endif // Make sure previous controls get unfocussed later, but except if control is in newly selected node unfocusControlsForState = inputInfo.editorState; unfocusControlsHot = GUIUtility.hotControl; unfocusControlsKeyboard = GUIUtility.keyboardControl; } #if UNITY_EDITOR if (inputInfo.editorState.selectedNode != null) { UnityEditor.Selection.activeObject = inputInfo.editorState.selectedNode; } else if (UnityEditor.Selection.activeObject is Node) { UnityEditor.Selection.activeObject = inputInfo.editorState.canvas; } #endif }
private static void KB_MoveNode(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (state.selectedNode != null) { Vector2 pos = state.selectedNode.rect.position; int shiftAmount = inputInfo.inputEvent.shift? 50 : 10; if (inputInfo.inputEvent.keyCode == KeyCode.RightArrow) { pos = new Vector2(pos.x + shiftAmount, pos.y); } else if (inputInfo.inputEvent.keyCode == KeyCode.LeftArrow) { pos = new Vector2(pos.x - shiftAmount, pos.y); } else if (inputInfo.inputEvent.keyCode == KeyCode.DownArrow) { pos = new Vector2(pos.x, pos.y + shiftAmount); } else if (inputInfo.inputEvent.keyCode == KeyCode.UpArrow) { pos = new Vector2(pos.x, pos.y - shiftAmount); } state.selectedNode.rect.position = pos; inputInfo.inputEvent.Use(); } NodeEditor.RepaintClients(); }
[EventHandlerAttribute(EventType.MouseDown, -2)] // Absolute second to call! private static void HandleSelecting(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (inputInfo.inputEvent.button == 0 && state.focusedNode != null) { // Select focussed Node unfocusControlsForState = state; if (!NodeEditor.CheckNodeIsSelected(state.focusedNode)) { state.selectedNodes.Clear(); state.selectedNodes.Add(state.focusedNode); } NodeEditor.RepaintClients(); } #if UNITY_EDITOR if (state.selectedNodes.Count > 0 && state.focusedNode != null) { UnityEditor.Selection.activeObject = state.selectedNodes[0]; } else if (state.focusedNode == null) { state.selectedNodes.Clear(); UnityEditor.Selection.activeObject = state.canvas; } #endif }
private static void CallEventHandlers(NodeEditorInputInfo inputInfo, bool late) { object[] args = new object[1] { inputInfo }; foreach (KeyValuePair <EventHandlerAttribute, Delegate> eventHandler in eventHandlers) { if (eventHandler.Key.handledEvent.HasValue) { EventType?handledEvent = eventHandler.Key.handledEvent; if (handledEvent.GetValueOrDefault() != inputInfo.inputEvent.type || !handledEvent.HasValue) { continue; } } if ((!late) ? (eventHandler.Key.priority < 100) : (eventHandler.Key.priority >= 100)) { eventHandler.Value.DynamicInvoke(args); if (inputInfo.inputEvent.type == EventType.Used) { break; } } } }
[EventHandlerAttribute(EventType.MouseDown, 0)] // One of the highest priorities after node selection private static void HandleContextClicks(NodeEditorInputInfo inputInfo) { if (Event.current.button == 1) { // Handle context clicks on Node and canvas GenericMenu contextMenu = new GenericMenu(); if (inputInfo.editorState.focusedConnectionKnob != null && inputInfo.editorState.focusedNode.GetType() == typeof(StateNode)) { FillContextMenu(inputInfo, contextMenu, ContextType.StateConnectKnob); } else if (inputInfo.editorState.focusedNode != null && inputInfo.editorState.focusedNode.GetType() == typeof(StateNode)) { FillContextMenu(inputInfo, contextMenu, ContextType.StateNode); } else if (inputInfo.editorState.focusedNode != null) // Node Context Click { FillContextMenu(inputInfo, contextMenu, ContextType.Node); } else // Editor Context Click { FillContextMenu(inputInfo, contextMenu, ContextType.Canvas); } contextMenu.ShowAsContext(); Event.current.Use(); } }
private static void KB_MoveNode(NodeEditorInputInfo inputInfo) { NodeEditorState editorState = inputInfo.editorState; if ((UnityEngine.Object)editorState.selectedNode != (UnityEngine.Object)null) { Vector2 position = editorState.selectedNode.rect.position; int num = 0; num = ((!inputInfo.inputEvent.shift) ? 5 : 10); if (inputInfo.inputEvent.keyCode == KeyCode.RightArrow) { position = new Vector2(position.x + (float)num, position.y); } else if (inputInfo.inputEvent.keyCode == KeyCode.LeftArrow) { position = new Vector2(position.x - (float)num, position.y); } else if (inputInfo.inputEvent.keyCode == KeyCode.DownArrow) { position = new Vector2(position.x, position.y + (float)num); } else if (inputInfo.inputEvent.keyCode == KeyCode.UpArrow) { position = new Vector2(position.x, position.y - (float)num); } editorState.selectedNode.rect.position = position; inputInfo.inputEvent.Use(); } NodeEditor.RepaintClients(); }
[EventHandlerAttribute(-4)] // Absolute first to call! private static void HandleFocussing(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; //必须放在这个地方,因为需要处理连线问题,如果不每次刷新就检测,就无法处理 state.focusedNode = NodeEditor.NodeAtPosition(NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos), out state.focusedConnectionKnob); }
private static void HandleConnectionDrawing(NodeEditorInputInfo inputInfo) { // TODO: Revamp Multi-Multi knob editing NodeEditorState state = inputInfo.editorState; if (inputInfo.inputEvent.button == 0 && state.focusedConnectionKnob != null) { // Left-Clicked on a ConnectionKnob, handle editing if (state.focusedConnectionKnob.maxConnectionCount == ConnectionCount.Multi) { // Knob with multiple connections clicked -> Draw new connection from it state.connectKnob = state.focusedConnectionKnob; inputInfo.inputEvent.Use(); } else if (state.focusedConnectionKnob.maxConnectionCount == ConnectionCount.Single) { // Knob with single connection clicked if (state.focusedConnectionKnob.connected()) { // Loose and edit existing connection from it state.connectKnob = state.focusedConnectionKnob.connection(0); state.focusedConnectionKnob.RemoveConnection(state.connectKnob); inputInfo.inputEvent.Use(); } else { // Not connected, draw a new connection from it state.connectKnob = state.focusedConnectionKnob; inputInfo.inputEvent.Use(); } } } }
private static void CallHotkeys(NodeEditorInputInfo inputInfo, KeyCode keyCode, EventModifiers mods) { object[] args = new object[1] { inputInfo }; foreach (KeyValuePair <HotkeyAttribute, Delegate> hotkeyHandler in hotkeyHandlers) { if (hotkeyHandler.Key.handledHotKey == keyCode && (!hotkeyHandler.Key.modifiers.HasValue || hotkeyHandler.Key.modifiers == mods)) { if (hotkeyHandler.Key.limitingEventType.HasValue) { EventType?limitingEventType = hotkeyHandler.Key.limitingEventType; if (limitingEventType.GetValueOrDefault() != inputInfo.inputEvent.type || !limitingEventType.HasValue) { continue; } } hotkeyHandler.Value.DynamicInvoke(args); if (inputInfo.inputEvent.type == EventType.Used) { break; } } } }
[EventHandlerAttribute(EventType.MouseDown, -2)] // Absolute second to call! private static void HandleSelecting(NodeEditorInputInfo inputInfo) { ResetHotControlId(); NodeEditorState state = inputInfo.editorState; if (inputInfo.inputEvent.button == 0 && state.focusedNode != null) { // Select focussed Node if (!NodeEditor.CheckNodeIsSelected(state.focusedNode)) { state.selectedNodes.Clear(); state.selectedNodes.Add(state.focusedNode); } } if (state.selectedNodes.Count > 0 && state.focusedNode != null) { UnityEditor.Selection.activeObject = state.selectedNodes[0]; } else if (state.focusedNode == null) { state.selectedNodes.Clear(); UnityEditor.Selection.activeObject = state.canvas; } }
[EventHandlerAttribute(EventType.MouseDown, -1)] // One of the highest priorities after node selection private static void HandleContextClicks(NodeEditorInputInfo inputInfo) { if (Event.current.button == 1) { // Handle context clicks on Node and canvas if (inputInfo.editorState.focusedNode != null) // Node Context Click { if (!NodeEditor.CheckNodeIsSelected(inputInfo.editorState.focusedNode)) { inputInfo.editorState.selectedNodes.Clear(); inputInfo.editorState.selectedNodes.Add(inputInfo.editorState.focusedNode); } GenericMenu contextMenu = new GenericMenu(); FillContextMenu(inputInfo, contextMenu, ContextType.Node); contextMenu.ShowAsContext(); Event.current.Use(); } else // Editor Context Click { inputInfo.editorState.selectedNodes.Clear(); CreateNodesAdvancedDropdown.ShowDropdown(new Rect(inputInfo.inputPos, Vector2.zero)); Event.current.Use(); } } }
private static void HandleConnectionDrawing(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (inputInfo.inputEvent.button == 0 && state.focusedConnectionKnob != null) { // Left-Clicked on a ConnectionKnob, handle editing if (state.focusedConnectionKnob.direction == Direction.Out) { // Knob with multiple connections clicked -> Draw new connection from it state.connectKnob = state.focusedConnectionKnob; CreateConnection = true; inputInfo.inputEvent.Use(); } else if (state.focusedConnectionKnob.direction == Direction.In) { // Knob with single connection clicked if (state.focusedConnectionKnob.connected()) { // Loose and edit existing connection from it state.connectKnob = state.focusedConnectionKnob.connection(0); state.focusedConnectionKnob.RemoveConnection(state.connectKnob); CreateConnection = false; inputInfo.inputEvent.Use(); } else { // Not connected, draw a new connection from it state.connectKnob = state.focusedConnectionKnob; CreateConnection = true; inputInfo.inputEvent.Use(); } } } }
private static void HandleNodeDragging(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (state.dragNode) { // If conditions apply, drag the selected node, else disable dragging if (state.selectedNodes.Count > 0 && inputInfo.editorState.dragUserID == "node") { // Apply new position for the dragged node Vector2 newOffset = state.UpdateDrag("node", inputInfo.inputPos); foreach (var node in state.selectedNodes) { node.position += newOffset; } NodeEditor.RepaintClients(); } else { state.dragNode = false; } Event.current.Use(); } }
[EventHandlerAttribute(EventType.MouseDown, -2)] // Absolute second to call! private static void HandleSelecting(NodeEditorInputInfo inputInfo) { if (inputInfo.inputEvent.button == 0 && inputInfo.editorState.focusedNode != inputInfo.editorState.selectedNode) { // Select focussed Node unfocusControlsForState = inputInfo.editorState; inputInfo.editorState.selectedNode = inputInfo.editorState.focusedNode; #if UNITY_EDITOR NodeEditorState state = inputInfo.editorState; Node prevSelection = state.selectedNode, newSelection = state.focusedNode; UndoPro.UndoProManager.RecordOperation( () => NodeEditorUndoActions.SetNodeSelection(state, newSelection), () => NodeEditorUndoActions.SetNodeSelection(state, prevSelection), "Node Selection", false, true); #endif } #if UNITY_EDITOR if (inputInfo.editorState.selectedNode != null) { UnityEditor.Selection.activeObject = inputInfo.editorState.selectedNode; } else if (UnityEditor.Selection.activeObject is Node) { UnityEditor.Selection.activeObject = inputInfo.editorState.canvas; } #endif }
private static void HandleGroupDragging(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; NodeGroup active = state.activeGroup; if (active != null) { // Handle dragging and resizing of active group if (state.dragUserID != "group") { state.activeGroup = null; state.resizeGroup = false; return; } // Update drag operation Vector2 dragChange = state.UpdateDrag("group", inputInfo.inputPos); Vector2 newSizePos = state.dragObjectPos; if (state.resizeGroup) { // Resizing -> Apply drag to selected borders while keeping a minimum size // Note: Binary operator and !=0 checks of the flag is enabled, but not necessarily the only flag (in which case you would use ==) Rect r = active.rect; if ((NodeGroup.resizeDir & BorderSelection.Left) != 0) { active.rect.xMin = r.xMax - Math.Max(minGroupSize, r.xMax - newSizePos.x); } else if ((NodeGroup.resizeDir & BorderSelection.Right) != 0) { active.rect.xMax = r.xMin + Math.Max(minGroupSize, newSizePos.x - r.xMin); } if ((NodeGroup.resizeDir & BorderSelection.Top) != 0) { active.rect.yMin = r.yMax - Math.Max(minGroupSize, r.yMax - newSizePos.y); } else if ((NodeGroup.resizeDir & BorderSelection.Bottom) != 0) { active.rect.yMax = r.yMin + Math.Max(minGroupSize, newSizePos.y - r.yMin); } } else { // Dragging -> Apply drag to body and pinned nodes active.rect.position = newSizePos; foreach (Node pinnedNode in active.pinnedNodes) { pinnedNode.position += dragChange; } foreach (NodeGroup pinnedGroup in active.pinnedGroups) { pinnedGroup.rect.position += dragChange; } } inputInfo.inputEvent.Use(); NodeEditor.RepaintClients(); } }
public static void HandleLateInputEvents(NodeEditorState state) { if (!shouldIgnoreInput(state)) { NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(state); CallEventHandlers(inputInfo, true); } }
private static void HandleEndNavigating(NodeEditorInputInfo inputInfo) { if (GUIUtility.keyboardControl > 0) { return; } inputInfo.editorState.navigate = false; }
private static void DeleteNode(NodeEditorInputInfo inputInfo) { if (inputInfo.editorState.focusedNode != null) { inputInfo.editorState.focusedNode.Delete(); inputInfo.inputEvent.Use(); } }
private static void HandleZooming(NodeEditorInputInfo inputInfo) { if (inputInfo.editorState.canZoom) { inputInfo.editorState.zoom = (float)Math.Round(Math.Min(4.0, Math.Max(0.6, inputInfo.editorState.zoom + inputInfo.inputEvent.delta.y / 15)), 2); NodeEditor.RepaintClients(); } }
private static void HandleWindowPanningEnd(NodeEditorInputInfo inputInfo) { if (inputInfo.editorState.dragUserID == "window") { inputInfo.editorState.panOffset = inputInfo.editorState.EndDrag("window"); } inputInfo.editorState.panWindow = false; }
private static void HandleWindowSelectionEnd(NodeEditorInputInfo inputInfo) { if (inputInfo.editorState.boxSelecting) { inputInfo.editorState.boxSelecting = false; NodeEditor.RepaintClients(); } }
[EventHandlerAttribute(EventType.MouseDrag, -2)] // Absolute second to call! private static void HandleDrag(NodeEditorInputInfo inputInfo) { //因为在编辑文本的时候我们不希望进行拖拽,所以吃掉事件 if (GUIUtility.hotControl != 0) { Event.current.Use(); } }
public static void HandleInputEvents(NodeEditorState state) { if (!shouldIgnoreInput(state)) { NodeEditorInputInfo inputInfo = new NodeEditorInputInfo(state); CallEventHandlers(inputInfo, false); CallHotkeys(inputInfo, Event.current.keyCode, Event.current.modifiers); } }
private static void HandleWindowSelection(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (state.boxSelecting) { NodeEditor.RepaintClients(); } }
private static void HandleNodeConnectionContext(NodeEditorInputInfo inputInfo) { NodeEditorState state = inputInfo.editorState; if (inputInfo.inputEvent.button == 2 && state.focusedConnectionKnob != null) { // Middle-Clicked on a ConnectionKnob, handle editing Debug.Log("right clicked on a node connection: " + state.focusedConnectionKnob); } }