/// <summary>
        /// Executes the action.
        /// </summary>
        public void Execute()
        {
            if (_gameObjects.Count != 0)
            {
                // Take a snapshot to allow for undo
                _preChangeMaskSnapshot = new ObjectSelectionMaskSnapshot();
                _preChangeMaskSnapshot.TakeSnapshot();

                // Assign the objects to the selection mask.
                // Note: We will also perform a snapshot of the current object selection just in case
                //       the object selection changes after the objects are assigned to the mask.
                _preChangeSelectionSnapshot = new ObjectSelectionSnapshot();
                _preChangeSelectionSnapshot.TakeSnapshot();
                EditorObjectSelection editorObjectSelection = EditorObjectSelection.Instance;
                _selectionWasChanged = editorObjectSelection.AddGameObjectCollectionToSelectionMask(_gameObjects);

                // If the selection was changed, we will perform a snapshot post change to make sure that we
                // can undo and redo the action accordingly. For example, if assigning the objects to the mask
                // caused a selection change, when the operation is undone, we want to restore both the mask
                // and the state that the selection was in before the mask was updated.
                if (_selectionWasChanged)
                {
                    _postChangeSelectionSnapshot = new ObjectSelectionSnapshot();
                    _postChangeSelectionSnapshot.TakeSnapshot();
                }

                // Take a snapshot to allow for redo
                _postChangeMaskSnapshot = new ObjectSelectionMaskSnapshot();
                _postChangeMaskSnapshot.TakeSnapshot();

                ObjectsAddedToSelectionMaskMessage.SendToInterestedListeners(_gameObjects);
                EditorUndoRedoSystem.Instance.RegisterAction(this);
            }
        }
        /// <summary>
        /// Executes the action.
        /// </summary>
        public void Execute()
        {
            // Only delete if we didn't delete already and if we are allowed to delete
            if (_postDeleteSnapshot == null)
            {
                // Take a pre delete selection snapshot which will allow us to undo
                _preDeleteSnapshot = new ObjectSelectionSnapshot();
                _preDeleteSnapshot.TakeSnapshot();

                // Store the currently selected objects (we'll need them later) and clear the selection
                List <GameObject> allSelectedObjects = new List <GameObject>(EditorObjectSelection.Instance.SelectedGameObjects);

                // Loop through each selected object
                _deletedObjects = new List <GameObject>(allSelectedObjects.Count);
                foreach (var selectedObject in allSelectedObjects)
                {
                    // Add the object to the deleted list and make it inactive
                    _deletedObjects.Add(selectedObject);
                    selectedObject.SetActive(false);
                }

                // Take a post delete snapshot to allow us to redo
                _postDeleteSnapshot = new ObjectSelectionSnapshot();
                _postDeleteSnapshot.TakeSnapshot();

                // Inform the selection module that the objects were deleted
                EditorObjectSelection.Instance.OnDeleted();

                // Record th action with the Undo/Redo system
                EditorUndoRedoSystem.Instance.RegisterAction(this);
            }
        }
        public static ObjectSelectionChangedEventArgs FromSnapshots(ObjectSelectActionType selectActionType, ObjectDeselectActionType deselectActionType,
                                                                    ObjectSelectionSnapshot preChangeSnapshot, ObjectSelectionSnapshot postChangeSnapshot)
        {
            List <GameObject> preDiff  = preChangeSnapshot.GetDiff(postChangeSnapshot);
            List <GameObject> postDiff = postChangeSnapshot.GetDiff(preChangeSnapshot);

            return(new ObjectSelectionChangedEventArgs(selectActionType, postDiff, deselectActionType, preDiff));
        }
Beispiel #4
0
        /// <summary>
        /// Returns a list of all objects which reside in 'this' snapshot, but not in 'other'.
        /// </summary>
        public List <GameObject> GetDiff(ObjectSelectionSnapshot other)
        {
            if (NumberOfSelectedObjects == 0)
            {
                return(new List <GameObject>());
            }

            var diffObjects = new List <GameObject>();

            foreach (var obj in _selectedGameObjects)
            {
                if (!other.Contains(obj))
                {
                    diffObjects.Add(obj);
                }
            }

            return(diffObjects);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="preChangeSelectionSnapshot">
 /// The object selection snapshot taken before the selection was changed.
 /// </param>
 /// <param name="postChangeSelectionSnapshot">
 /// The object selection snapshot taken after the selection was changed.
 /// </param>
 public PostObjectSelectionChangedAction(ObjectSelectionSnapshot preChangeSelectionSnapshot,
                                         ObjectSelectionSnapshot postChangeSelectionSnapshot)
 {
     _preChangeSelectionSnapshot  = preChangeSelectionSnapshot;
     _postChangeSelectionSnapshot = postChangeSelectionSnapshot;
 }