/// <summary> /// Factory method to be passed to the Context Menu for creating /// an instance of this connector class /// </summary> /// <param name="editor">The node editor making the connection</param> /// <param name="nodes">Any nodes to start the connector with</param> /// <returns></returns> public static TransitionConnector TransitionConnectorFactory( ZeroProgress.NodeEditor.NodeEditor editor, params Node[] nodes) { TransitionConnector newConnector = new TransitionConnector(); if (nodes == null) { return(newConnector); } foreach (Node node in nodes) { newConnector.AddNode(node); } return(newConnector); }
/// <summary> /// Perform the focusing logic /// </summary> private void PerformFocus() { IEnumerable <Node> selectedNodes = NodeEditor.GetSelectedNodes(); int count = 0; Vector2 averagePosition = Vector2.zero; foreach (Node node in selectedNodes) { averagePosition += node.NodeRect.position; count++; } IEnumerable <Connector> selectedConnectors = NodeEditor.GetSelectedConnectors(); foreach (Connector connector in selectedConnectors) { Node startNode = connector.GetStartNode(); Node endNode = connector.GetEndNode(); averagePosition += ((startNode.NodeRect.position + endNode.NodeRect.position) * 0.5f); count++; } if (count == 0) { foreach (Node node in NodeEditor.Nodes) { averagePosition += node.NodeRect.position; count++; } } if (count == 0) { NodeEditor.SetPanOffset(Vector2.zero); return; } Vector2 offset = NodeEditor.NodeEditorRect.size * 0.5f; NodeEditor.SetPanOffset((-averagePosition / count) + offset); }
/// <summary> /// Configures the rectangle used for selection /// </summary> public override void AfterEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.button != 0) { Cancel(); Event.current.Use(); return; } if (Event.current.type == EventType.MouseDrag) { Vector2 startPoint = NodeEditor.ApplyZoomToVector(dragStartPos); Vector2 endPoint = NodeEditor.GetZoomedMousePosition(); selectionRect = RectExtensions.FromPoints(startPoint, endPoint); NodeEditor.FlagRepaint(); Event.current.Use(); } else if (Event.current.type == EventType.MouseUp) { SelectNodes(); SelectConnectors(); NodeEditor.RaiseSelectionChanged(); selectionRect = Rect.zero; Deactivate(); Event.current.Use(); } else if (Event.current.type == EventType.MouseLeaveWindow) { Cancel(); } }
/// <summary> /// Executes after the node editor has processed its events /// </summary> public override void AfterEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.type != EventType.KeyDown) { return; } if (Event.current.keyCode == KeyCode.Escape) { NodeEditor.CancelInputModes(); NodeEditor.UnselectAll(); } }
/// <summary> /// Check if delete key is pressed /// </summary> public override void BeforeEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.type != EventType.KeyDown) { return; } if (Event.current.keyCode == KeyCode.Delete) { NodeEditor.RemoveSelectedNodes(); NodeEditor.RemoveSelectedConnectors(); Event.current.Use(); } }
/// <summary> /// Creates a Connector object /// </summary> /// <param name="startNode">The starting node that the connector was opened on</param> /// <returns>An empty Connector</returns> public static Connector DefaultConnectorFactoryFunction(NodeEditor editor, params Node[] nodes) { return(new Connector(nodes)); }
/// <summary> /// Handles any non-repaint/layout events /// </summary> /// <param name="nodeEditor">The editor to work with</param> /// <param name="nodeOffset">The offset of the node</param> /// <returns>True if require repaint, false if not</returns> public virtual bool HandleEvents(NodeEditor nodeEditor, Vector2 nodeOffset) { return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public ConnectorSelectMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public SelectedNodeDragMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Activates if a selected node was clicked and if /// there are currently nodes selected /// </summary> /// <returns></returns> protected override bool ShouldActivate() { return(NodeEditor.GetSelectedNodesCount() > 0 && wasMouseDownInSelectedNode); }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public CancelAll(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public ConnectNodeInputMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { ConnectionLogic = ConnectionStyle.MULTIPLE; }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public FocusInput(NodeEditor nodeEditor, int priority = 2) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public BackgroundClickedUnselector(NodeEditor nodeEditor, int priority = 10) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public DeleteKeyInput(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public ConnectorMakerMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Handles re-configuring the Node Editor to its original state /// </summary> protected override void OnDeactivated() { NodeEditor.EnableZoom(); selectionRect = Rect.zero; }
/// <summary> /// Handles cancelling box select mode /// </summary> protected override void OnCancelled() { NodeEditor.UnselectAll(); NodeEditor.RaiseSelectionChanged(); }
/// <summary> /// Handles configuring the node editor for box select mode activation /// </summary> protected override void OnActivated() { dragStartPos = Event.current.mousePosition; NodeEditor.DisableZoom(); }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public BoxSelectMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { CanSelectConnectors = CanSelectNodes = true; }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public SelectAllNodesMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">Node editor to work on</param> /// <param name="priority">When this mode should be processed relative /// to other input modes. Lower number == processed first</param> public NodeRightClickMode(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }
/// <summary> /// Constructor /// </summary> /// <param name="nodeEditor">The node editor this input mode works on</param> /// <param name="priority">Priority of the input mode</param> public ContextMenuInput(NodeEditor nodeEditor, int priority = 0) : base(nodeEditor, priority) { }