Skip to content

SelectionSnapshot

Namespace: SideXP.Selection

public class SelectionSnapshot

Saved state of a selection, which can be applied again later.

Constructors

SelectionSnapshot(IEnumerable<Object>, Object)

public SelectionSnapshot(IEnumerable<Object> objects, Object activeObject = null)

Creates a snapshot of the given selection.

Parameters

  • objects: The selected objects. Null entries and duplicates are ignored.
  • activeObject: The active object of the selection. Ignored if it's not one of the selected objects.

Properties

Objects

public IReadOnlyList<ObjectRef> Objects

The selected objects.

Count

public int Count

The number of selected objects.

IsEmpty

public bool IsEmpty

Checks if this snapshot doesn't contain any object.

Active

public ObjectRef Active

The reference to the active object of the selection, or null if there's no active object.

Methods

FromCurrentSelection()

public static SelectionSnapshot FromCurrentSelection()

Creates a snapshot of the current selection in the editor.

Returns

Returns the created snapshot.

Resolve(Object)

public Object[] Resolve(out Object activeObject)

Resolves the selected objects.

Parameters

  • activeObject: Outputs the active object, or null if there's no active object or if it can't be resolved.

Returns

Returns the selected objects that can be resolved.

Resolve()

public Object[] Resolve()

Resolves the selected objects.

Returns

Returns the selected objects that can be resolved.

CanResolve()

public bool CanResolve()

Checks if at least one of the selected objects can be resolved.

Returns

Returns true if this snapshot can be applied.

Matches(IEnumerable<Object>)

public bool Matches(IEnumerable<Object> objects)

Checks if the resolved objects of this snapshot are the given ones, regardless of their order. The active object is not compared.

Parameters

  • objects: The objects to compare. Null entries are ignored.

Returns

Returns true if the resolved objects are the same as the given ones.

Matches(SelectionSnapshot)

public bool Matches(SelectionSnapshot other)

Checks if the resolved objects of this snapshot are the given ones, regardless of their order. The active object is not compared.

Parameters

  • other: The snapshot to compare.

Returns

Returns true if the resolved objects are the same as the given ones.

HasSameObjects(SelectionSnapshot)

public bool HasSameObjects(SelectionSnapshot other)

Checks if this snapshot and the given one contain the same objects, regardless of their order. Unlike Matches, the objects that can't be resolved are compared too (using RefersToSameObject). The active object is not compared.

Parameters

  • other: The snapshot to compare.

Returns

Returns true if both snapshots contain the same objects.

Apply()

public bool Apply()

Selects the objects of this snapshot in the editor. Objects that can't be resolved are skipped.

Returns

Returns true if the selection has been applied, or false if none of the objects can be resolved.

Clean()

public bool Clean()

Removes the objects that don't exist anymore, or that can't be identified anymore (objects not saved in a scene that has been closed or reloaded, objects spawned in play mode once back to edit mode, ...). Objects saved in a scene that is not loaded are kept, since they can be resolved again once that scene is loaded.

Returns

Returns true if at least one object has been removed.

Remarks

The objects that don't have a stable id but are still resolved are refreshed, so they get one if possible (for example, an object selected in play mode that also exists in edit mode).

Clone()

public SelectionSnapshot Clone()

Creates a copy of this snapshot, independent from the original one (cleaning or refreshing the copy doesn't affect the original).

Returns

Returns the created copy.

Refresh()

public void Refresh()

Captures again the identifiers of the objects that are still alive.

Returns

Returns true if the identifiers have been captured again.

Remarks

Does nothing in play mode, so the stable ids captured in edit mode are not lost.