mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Added functionality that focuses on selected nodes. (#173)
Resets view if no nodes are selected.
This commit is contained in:
parent
43bcb54fda
commit
c16ad1fff0
@ -335,11 +335,18 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Puts all nodes in focus. If no nodes are present, resets view to </summary>
|
/// <summary> Puts all selected nodes in focus. If no nodes are present, resets view and zoom to to origin </summary>
|
||||||
public void Home() {
|
public void Home() {
|
||||||
|
var nodes = Selection.objects.Where(o => o is XNode.Node).Cast<XNode.Node>().ToList();
|
||||||
|
if (nodes.Count > 0) {
|
||||||
|
Vector2 minPos = nodes.Select(x => x.position).Aggregate((x, y) => new Vector2(Mathf.Min(x.x, y.x), Mathf.Min(x.y, y.y)));
|
||||||
|
Vector2 maxPos = nodes.Select(x => x.position + (nodeSizes.ContainsKey(x) ? nodeSizes[x] : Vector2.zero)).Aggregate((x, y) => new Vector2(Mathf.Max(x.x, y.x), Mathf.Max(x.y, y.y)));
|
||||||
|
panOffset = -(minPos + (maxPos - minPos) / 2f);
|
||||||
|
} else {
|
||||||
zoom = 2;
|
zoom = 2;
|
||||||
panOffset = Vector2.zero;
|
panOffset = Vector2.zero;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Remove nodes in the graph in Selection.objects</summary>
|
/// <summary> Remove nodes in the graph in Selection.objects</summary>
|
||||||
public void RemoveSelectedNodes() {
|
public void RemoveSelectedNodes() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user