/// <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>
        /// Convenience function for sending an objects added to selection mask message to
        /// all interested listeners.
        /// </summary>
        /// <param name="gameObjects">
        /// The game objects which were added to the selection mask.
        /// </param>
        public static void SendToInterestedListeners(List <GameObject> gameObjects)
        {
            var message = new ObjectsAddedToSelectionMaskMessage(gameObjects);

            MessageListenerDatabase.Instance.SendMessageToInterestedListeners(message);
        }