mirror of
https://github.com/Siccity/xNode.git
synced 2026-02-06 15:24:55 +08:00
Support for DoubleClick on node to center it.
Added support for double clciking on Node header to center that node within the editor window.
This commit is contained in:
parent
932ff74663
commit
0f5539e077
@ -22,11 +22,12 @@ namespace XNodeEditor {
|
||||
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
|
||||
private RerouteReference hoveredReroute = new RerouteReference();
|
||||
private List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
||||
private Rect nodeRects;
|
||||
private Rect nodeRects; // Is this used?
|
||||
private Vector2 dragBoxStart;
|
||||
private UnityEngine.Object[] preBoxSelection;
|
||||
private RerouteReference[] preBoxSelectionReroute;
|
||||
private Rect selectionBox;
|
||||
private bool isDoubleClick = false;
|
||||
|
||||
private struct RerouteReference {
|
||||
public XNode.NodePort port;
|
||||
@ -172,6 +173,10 @@ namespace XNodeEditor {
|
||||
SelectNode(hoveredNode, e.control || e.shift);
|
||||
if (!e.control && !e.shift) selectedReroutes.Clear();
|
||||
} else if (e.control || e.shift) DeselectNode(hoveredNode);
|
||||
|
||||
// Cache double click state, but only act on it in MouseUp - Except ClickCount only works in mouseDown.
|
||||
isDoubleClick = ( e.clickCount == 2 );
|
||||
|
||||
e.Use();
|
||||
currentActivity = NodeActivity.HoldNode;
|
||||
} else if (IsHoveringReroute) {
|
||||
@ -239,6 +244,13 @@ namespace XNodeEditor {
|
||||
if (currentActivity == NodeActivity.HoldNode && !(e.control || e.shift)) {
|
||||
selectedReroutes.Clear();
|
||||
SelectNode(hoveredNode, false);
|
||||
|
||||
// Double click to center node
|
||||
if ( isDoubleClick )
|
||||
{
|
||||
Vector2 nodeDimension = nodeSizes.ContainsKey( hoveredNode ) ? nodeSizes[ hoveredNode ] / 2 : new Vector2(0f, 0f);
|
||||
panOffset = -hoveredNode.position - nodeDimension;
|
||||
}
|
||||
}
|
||||
|
||||
// If click reroute, select it.
|
||||
@ -273,6 +285,8 @@ namespace XNodeEditor {
|
||||
}
|
||||
isPanning = false;
|
||||
}
|
||||
// Reset DoubleClick
|
||||
isDoubleClick = false;
|
||||
break;
|
||||
case EventType.KeyDown:
|
||||
if (EditorGUIUtility.editingTextField) break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user