There may be times when you would like to change the object selection from code. The RTObjectSelection class exposes the following functions for this purpose:
public void AppendObjects(List<GameObject> gameObjects, bool allowUndoRedo);
public void RemoveObjects(List<GameObject> gameObjects, bool allowUndoRedo);
public void SetSelectedObjects(List<GameObject> gameObjects, bool allowUndoRedo);
public void ClearSelection(bool allowUndoRedo);
FunctionName | Description |
---|---|
AppendObjects | Appends gameObjects to the current selection. Objects which are already selected will be ignored. The last parameter allows you to specify if the operation can be undone/redone. |
RemoveObjects | Removes gameObjects from the current selection. Objects which are not seleted will be ignored. The last parameter allows you to specify if the operation can be undone/redone. |
SetSelectedObjects | Replaces the current selection with gameObjects. The last parameter allows you to specify if the operation can be undone/redone. |
ClearSelection | Clears the object selection. The parameter allows you to specify if the operation can be undone/redone. |
All functions discussed above will only have any effect if ALL following conditions are met:
- the selection module is enabled;
- the selected objects are not about to be deleted;
- the selection module is not currently handling a PreSelectCustomize or PreDeselectCustomize event;
- there is no object manipulation session active (object-to-object snapping, selection grab, selection grid snap);
- the selection module is not currently firing a selection changed event;
You can check if all these conditions are met by writing:
if (RTObjectSelection.Get.CanBeModifiedByAPI())
{
// Can change by code
}