private void ClearSelectionAndSelectObject(GameObject gameObject) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; if (selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); objectSelection.AddEntireGameObjectHierarchyToSelection(gameObject); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingMouseClick(); } else { // Note: We only continue if the picked object is not the only currently selected object. If it is, it means // we would be registering an Undo operation for nothing. if (!ObjectSelection.Get().IsSameAs(gameObject)) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); objectSelection.AddGameObjectToSelection(gameObject); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingMouseClick(); } } }
private void UpdateSelectionForNoAppendAndNoDeselect(List <GameObject> gameObjectsOverlappedBySelectionShape) { ObjectSelection objectSelection = ObjectSelection.Get(); ObjectSelectionUpdateMode _selectionUpdateMode = ObjectSelectionSettings.Get().SelectionUpdateMode; // If no object was overlapped by the selection shape, we can clear the selection. // Note: We only clear the selection if the current number of selected objects is not 0. This // allows us to avoid registering an Undo for nothing. if (gameObjectsOverlappedBySelectionShape.Count == 0 && objectSelection.NumberOfSelectedObjects != 0) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); } else // When the selection shape has overlapped objects, we must reset the selection by clearing it and selecting only // the objects which were overlapped. if (gameObjectsOverlappedBySelectionShape.Count != 0) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); if (_selectionUpdateMode == ObjectSelectionUpdateMode.EntireHierarchy) { objectSelection.AddEntireGameObjectHierarchyToSelection(gameObjectsOverlappedBySelectionShape); } else { objectSelection.AddGameObjectCollectionToSelection(gameObjectsOverlappedBySelectionShape); } objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdatedUsingSelectionShape(); } }
public static void SelectAllObjectsInLayer(int objectLayer) { List <GameObject> allObjectsInLayer = ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer); ObjectSelection objectSelection = ObjectSelection.Get(); objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(allObjectsInLayer); ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated(); }
public static void DuplicateSelection() { if (ObjectSelection.Get().NumberOfSelectedObjects == 0) { return; } ObjectSelection objectSelection = ObjectSelection.Get(); List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetParents(allSelectedObjects); var clonedObjects = new List <GameObject>(); var clonedParents = new List <GameObject>(); foreach (GameObject parent in selectedParents) { GameObject prefab = parent.GetSourcePrefab(); Transform parentTransform = parent.transform; if (prefab == null) { GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent); //clonedParent.transform.parent = parent.transform.parent; clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); Octave3DScene.Get().RegisterObjectHierarchy(clonedParent); clonedParents.Add(clonedParent); } else { GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale); clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); Octave3DScene.Get().RegisterObjectHierarchy(clonedParent); clonedParents.Add(clonedParent); } } if (clonedObjects.Count != 0) { objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(clonedObjects); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated(); } if (clonedParents.Count != 0) { ObjectHierarchyRootsWerePlacedInSceneMessage.SendToInterestedListeners(clonedParents, ObjectHierarchyRootsWerePlacedInSceneMessage.PlacementType.Selection); } SceneViewCamera.Instance.SetObjectVisibilityDirty(); }
public static void SelectAllObjectsInAllLayers() { ObjectSelection objectSelection = ObjectSelection.Get(); objectSelection.Clear(); List <int> allLayers = ObjectLayerDatabase.Get().GetAllObjectLayers(); foreach (int objectLayer in allLayers) { objectSelection.AddGameObjectCollectionToSelection(ObjectLayerDatabase.Get().GetAllGameObjectsInLayer(objectLayer)); } ObjectSelection.Get().ObjectSelectionGizmos.OnObjectSelectionUpdated(); }
public static void InvertSelection() { List <GameObject> allWorkingObjects = Octave3DWorldBuilder.ActiveInstance.GetAllWorkingObjects(); List <GameObject> objectsToSelect = new List <GameObject>(); ObjectSelection objectSelection = ObjectSelection.Get(); foreach (var gameObject in allWorkingObjects) { if (!objectSelection.IsGameObjectSelected(gameObject)) { objectsToSelect.Add(gameObject); } } objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(objectsToSelect); objectSelection.ObjectSelectionGizmos.OnObjectSelectionUpdated(); }
public static void DuplicateSelection() { if (ObjectSelection.Get().NumberOfSelectedObjects == 0) { return; } ObjectSelection objectSelection = ObjectSelection.Get(); List <GameObject> allSelectedObjects = objectSelection.GetAllSelectedGameObjects(); List <GameObject> selectedParents = GameObjectExtensions.GetTopParentsFromGameObjectCollection(allSelectedObjects); var clonedObjects = new List <GameObject>(); foreach (GameObject parent in selectedParents) { GameObject prefab = parent.GetSourcePrefab(); Transform parentTransform = parent.transform; if (prefab == null) { GameObject clonedParent = parent.CloneAsWorkingObject(parentTransform.parent); //clonedParent.transform.parent = parent.transform.parent; clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); } else { GameObject clonedParent = ObjectInstantiation.InstantiateObjectHierarchyFromPrefab(prefab, parentTransform.position, parentTransform.rotation, parentTransform.lossyScale); clonedObjects.AddRange(clonedParent.GetAllChildrenIncludingSelf()); } } if (clonedObjects.Count != 0) { objectSelection.Clear(); objectSelection.AddGameObjectCollectionToSelection(clonedObjects); objectSelection.ObjectSelectionTransformGizmoSystem.OnObjectSelectionUpdated(); } }
private void ClearSelectionWhenNoObjectPicked() { ObjectSelection objectSelection = ObjectSelection.Get(); // When no object is picked, we will clear the selection. // Note: We only clear the selection if: // -the current number of selected objects is not 0. This allows us to avoid registering // an Undo operation for nothing; // -append mode is not active. If it is, the user may have clicked an empty area in order // to start selecting multiple objects with the selection shape. In this case we don't // want to clear the selection because otherwise, there would be no way for the user to // append objects to the selection using the selection shape; // -deselect objects with selection shape mode is not active. If it is, clearing the object // selection would not allow the user to deselect only the objects they desire because when // they click in an empty space all objects would already be deselected. if (objectSelection.NumberOfSelectedObjects != 0 && !AllShortcutCombos.Instance.EnableAppendObjectsToSelection.IsActive() && !AllShortcutCombos.Instance.EnableDeselectObjectsWithSelectionShape.IsActive()) { UndoEx.RecordForToolAction(objectSelection); objectSelection.Clear(); } }