diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs
index 03e32cb29..a0dc4a955 100644
--- a/Source/Editor/Surface/VisjectSurface.cs
+++ b/Source/Editor/Surface/VisjectSurface.cs
@@ -112,7 +112,7 @@ namespace FlaxEditor.Surface
///
/// Occurs when selection gets changed.
///
- protected event Action SelectionChanged;
+ public event Action SelectionChanged;
///
/// The surface owner.
@@ -252,6 +252,9 @@ namespace FlaxEditor.Surface
///
/// Gets the list of the selected nodes.
///
+ ///
+ /// Don't call it too often. It does memory allocation and iterates over the surface controls to find selected nodes in the graph.
+ ///
public List SelectedNodes
{
get
@@ -269,6 +272,9 @@ namespace FlaxEditor.Surface
///
/// Gets the list of the selected controls (comments and nodes).
///
+ ///
+ /// Don't call it too often. It does memory allocation and iterates over the surface controls to find selected nodes in the graph.
+ ///
public List SelectedControls
{
get
@@ -573,12 +579,17 @@ namespace FlaxEditor.Surface
///
public void SelectAll()
{
+ bool selectionChanged = false;
for (int i = 0; i < _rootControl.Children.Count; i++)
{
- if (_rootControl.Children[i] is SurfaceControl control)
+ if (_rootControl.Children[i] is SurfaceControl control && !control.IsSelected)
+ {
control.IsSelected = true;
+ selectionChanged = true;
+ }
}
- SelectionChanged?.Invoke();
+ if (selectionChanged)
+ SelectionChanged?.Invoke();
}
///
@@ -586,12 +597,17 @@ namespace FlaxEditor.Surface
///
public void ClearSelection()
{
+ bool selectionChanged = false;
for (int i = 0; i < _rootControl.Children.Count; i++)
{
if (_rootControl.Children[i] is SurfaceControl control)
+ {
control.IsSelected = false;
+ selectionChanged = true;
+ }
}
- SelectionChanged?.Invoke();
+ if (selectionChanged)
+ SelectionChanged?.Invoke();
}
///
@@ -600,6 +616,8 @@ namespace FlaxEditor.Surface
/// The control.
public void AddToSelection(SurfaceControl control)
{
+ if (control.IsSelected)
+ return;
control.IsSelected = true;
SelectionChanged?.Invoke();
}
@@ -610,9 +628,22 @@ namespace FlaxEditor.Surface
/// The control.
public void Select(SurfaceControl control)
{
- ClearSelection();
- control.IsSelected = true;
- SelectionChanged?.Invoke();
+ bool selectionChanged = false;
+ for (int i = 0; i < _rootControl.Children.Count; i++)
+ {
+ if (_rootControl.Children[i] is SurfaceControl c && c != control && c.IsSelected)
+ {
+ c.IsSelected = false;
+ selectionChanged = true;
+ }
+ }
+ if (!control.IsSelected)
+ {
+ control.IsSelected = true;
+ selectionChanged = true;
+ }
+ if (selectionChanged)
+ SelectionChanged?.Invoke();
}
///
@@ -903,7 +934,7 @@ namespace FlaxEditor.Surface
{
return _context.FindNode(id);
}
-
+
///
/// Adds the undo action to be batched (eg. if multiple undo actions is performed in a sequence during single update).
///