/// <summary> /// Gets a clone of the attachment remapped with an atlasRegion image.</summary> /// <returns>The remapped clone.</returns> /// <param name="o">The original attachment.</param> /// <param name="atlasRegion">Atlas region.</param> /// <param name="cloneMeshAsLinked">If <c>true</c> MeshAttachments will be cloned as linked meshes and will inherit animation from the original attachment.</param> /// <param name="useOriginalRegionSize">If <c>true</c> the size of the original attachment will be followed, instead of using the Sprite size.</param> /// <param name="scale">Unity units per pixel scale used to scale the atlas region size when not using the original region size.</param> public static Attachment GetRemappedClone(this Attachment o, AtlasRegion atlasRegion, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, float scale = 0.01f) { var regionAttachment = o as RegionAttachment; if (regionAttachment != null) { RegionAttachment newAttachment = (RegionAttachment)regionAttachment.Copy(); newAttachment.SetRegion(atlasRegion, false); if (!useOriginalRegionSize) { newAttachment.Width = atlasRegion.width * scale; newAttachment.Height = atlasRegion.height * scale; } newAttachment.UpdateOffset(); return(newAttachment); } else { var meshAttachment = o as MeshAttachment; if (meshAttachment != null) { MeshAttachment newAttachment = cloneMeshAsLinked ? meshAttachment.NewLinkedMesh() : (MeshAttachment)meshAttachment.Copy(); newAttachment.SetRegion(atlasRegion); return(newAttachment); } } return(o.Copy()); }
/// <summary> /// Clones the attachment.</summary> public static Attachment GetCopy(this Attachment o, bool cloneMeshesAsLinked) { var meshAttachment = o as MeshAttachment; if (meshAttachment != null && cloneMeshesAsLinked) { return(meshAttachment.NewLinkedMesh()); } return(o.Copy()); }
public async Task <IActionResult> RemoveAttachment(Guid attachmentId, [FromServices] IMongoCollection <Attachment> mongoCollection) { Attachment result = await(await mongoCollection.FindAsync(x => x.ID == attachmentId)).FirstOrDefaultAsync(); if (result == null) { return(this.Error(HttpStatusCode.NotFound, $"There's no such attachment with Id={attachmentId}")); } Attachment newValue = result.Copy(); newValue.OldVersionID = result.PostID; newValue.PostID = Guid.Empty; UpdateResult temp = await mongoCollection.UpdateOneAsync(x => x.ID == attachmentId, Extensions.GenerateUpdateDefinition(result, newValue)); if (temp.IsAcknowledged) { return(this.Success(null)); } else { return(this.Error(HttpStatusCode.InternalServerError, "Removing attachment failed!")); } }
private void EditSelectedItem() { ListView.SelectedListViewItemCollection items = AttachmentsListView.SelectedItems; if (items.Count > 1) { MessageBox.Show("You can only edit one item at the same time."); return; } ObjectListViewItem lvi = items[0] as ObjectListViewItem; Attachment underlyingObject = lvi?.UnderlyingObject as Attachment; if (underlyingObject != null) { Attachment copy = underlyingObject.Copy(); EditAttachmentForm form = new EditAttachmentForm(copy); if (form.ShowDialog() == DialogResult.OK) { copy.CopyTo(underlyingObject); lvi.SubItems[0].Text = underlyingObject.Name; } } }