/// <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()); }
public static Attachment GetRemappedClone(this Attachment o, AtlasRegion atlasRegion, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, float scale = 0.01f) { RegionAttachment attachment = o as RegionAttachment; if (attachment != null) { RegionAttachment clone = attachment.GetClone(); clone.SetRegion(atlasRegion, false); if (!useOriginalRegionSize) { clone.width = atlasRegion.width * scale; clone.height = atlasRegion.height * scale; } clone.UpdateOffset(); return(clone); } MeshAttachment attachment3 = o as MeshAttachment; if (attachment3 != null) { MeshAttachment attachment4 = !cloneMeshAsLinked?attachment3.GetClone() : attachment3.GetLinkedClone(cloneMeshAsLinked); attachment4.SetRegion(atlasRegion, true); return(attachment4); } return(o.GetClone(true)); }
public static Attachment GetRemappedClone(this Attachment o, AtlasRegion atlasRegion, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, float scale = 0.01f) { RegionAttachment regionAttachment = o as RegionAttachment; if (regionAttachment != null) { RegionAttachment clone = regionAttachment.GetClone(); clone.SetRegion(atlasRegion, updateOffset: false); if (!useOriginalRegionSize) { clone.width = (float)atlasRegion.width * scale; clone.height = (float)atlasRegion.height * scale; } clone.UpdateOffset(); return(clone); } MeshAttachment meshAttachment = o as MeshAttachment; if (meshAttachment != null) { MeshAttachment meshAttachment2 = (!cloneMeshAsLinked) ? meshAttachment.GetClone() : meshAttachment.GetLinkedClone(cloneMeshAsLinked); meshAttachment2.SetRegion(atlasRegion); return(meshAttachment2); } return(o.GetClone(cloneMeshesAsLinked: true)); }
public static void SetRegion(this Attachment attachment, AtlasRegion region, bool updateOffset = true) { RegionAttachment attachment2 = attachment as RegionAttachment; if (attachment2 != null) { attachment2.SetRegion(region, updateOffset); } MeshAttachment attachment3 = attachment as MeshAttachment; if (attachment3 != null) { attachment3.SetRegion(region, updateOffset); } }