public SetUVs ( float u, float v, float u2, float v2, bool rotate ) : void | ||
u | float | |
v | float | |
u2 | float | |
v2 | float | |
rotate | bool | |
Résultat | void |
public RegionAttachment NewRegionAttachment(Skin skin, String name, String path) { FAtlasElement element = Futile.atlasManager.GetElementWithName(name); RegionAttachment attachment = new RegionAttachment(name); if(element != null){ attachment.RendererObject = element; attachment.SetUVs(element.uvBottomLeft.x, element.uvBottomLeft.y, element.uvTopRight.x, element.uvTopRight.y, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = element.sourceSize.x; attachment.RegionHeight = element.sourceSize.y; attachment.RegionOriginalWidth = element.sourceSize.x; attachment.RegionOriginalHeight = element.sourceSize.y; }else{ attachment.RendererObject = null; attachment.SetUVs(0.0f, 0.0f, 0.0f, 0.0f, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = 0.0f; attachment.RegionHeight = 0.0f; attachment.RegionOriginalWidth = 0.0f; attachment.RegionOriginalHeight = 0.0f; Debug.Log("Element [" + name + "] not found in Futile.AtlasManager"); } return attachment; }
// this is the attachment loader which will hook into Futile's AtlasManager for the attachment/element data public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { switch(type){ case AttachmentType.region: FAtlasElement element = Futile.atlasManager.GetElementWithName(name); RegionAttachment attachment = new RegionAttachment(name); if(element != null){ attachment.Texture = element; attachment.SetUVs(element.uvBottomLeft.x, element.uvBottomLeft.y, element.uvTopRight.x, element.uvTopRight.y, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = element.sourceSize.x; attachment.RegionHeight = element.sourceSize.y; attachment.RegionOriginalWidth = element.sourceSize.x; attachment.RegionOriginalHeight = element.sourceSize.y; }else{ attachment.Texture = null; attachment.SetUVs(0.0f, 0.0f, 0.0f, 0.0f, false); attachment.RegionOffsetX = 0.0f; attachment.RegionOffsetY = 0.0f; attachment.RegionWidth = 0.0f; attachment.RegionHeight = 0.0f; attachment.RegionOriginalWidth = 0.0f; attachment.RegionOriginalHeight = 0.0f; Debug.Log("Element [" + name + "] not found in Futile.AtlasManager"); } return attachment; } throw new Exception("Unknown attachment type: " + type); }
public RegionAttachment NewRegionAttachment(Skin skin, string name, string path) { AtlasRegion atlasRegion = this.FindRegion(path); if (atlasRegion == null) { throw new Exception(string.Concat(new string[] { "Region not found in atlas: ", path, " (region attachment: ", name, ")" })); } RegionAttachment regionAttachment = new RegionAttachment(name); regionAttachment.RendererObject = atlasRegion; regionAttachment.SetUVs(atlasRegion.u, atlasRegion.v, atlasRegion.u2, atlasRegion.v2, atlasRegion.rotate); regionAttachment.regionOffsetX = atlasRegion.offsetX; regionAttachment.regionOffsetY = atlasRegion.offsetY; regionAttachment.regionWidth = (float)atlasRegion.width; regionAttachment.regionHeight = (float)atlasRegion.height; regionAttachment.regionOriginalWidth = (float)atlasRegion.originalWidth; regionAttachment.regionOriginalHeight = (float)atlasRegion.originalHeight; return(regionAttachment); }
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { switch (type) { case AttachmentType.region: AtlasRegion region = atlas.FindRegion(name); if (region == null) { throw new Exception("Region not found in atlas: " + name + " (" + type + ")"); } RegionAttachment attachment = new RegionAttachment(name); attachment.RendererObject = region; attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); attachment.regionOffsetX = region.offsetX; attachment.regionOffsetY = region.offsetY; attachment.regionWidth = region.width; attachment.regionHeight = region.height; attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; return(attachment); case AttachmentType.boundingbox: return(new BoundingBoxAttachment(name)); } throw new Exception("Unknown attachment type: " + type); }
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type); // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); if (index != -1) name = name.Substring(index + 1); tk2dSpriteDefinition def = sprites.GetSpriteDefinition(name); if (def == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")"); if (def.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")"); if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")"); RegionAttachment attachment = new RegionAttachment(name); Vector2 minTexCoords = Vector2.one; Vector2 maxTexCoords = Vector2.zero; for (int i = 0; i < def.uvs.Length; ++i) { Vector2 uv = def.uvs[i]; minTexCoords = Vector2.Min(minTexCoords, uv); maxTexCoords = Vector2.Max(maxTexCoords, uv); } bool rotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d; if (rotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } attachment.SetUVs( minTexCoords.x, maxTexCoords.y, maxTexCoords.x, minTexCoords.y, rotated ); attachment.RegionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x); attachment.RegionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y); attachment.RegionWidth = (int)(def.boundsData[1].x / def.texelSize.x); attachment.RegionHeight = (int)(def.boundsData[1].y / def.texelSize.y); float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2; float x1 = def.boundsData[0].x - def.boundsData[1].x / 2; attachment.RegionOffsetX = (int)((x1 - x0) / def.texelSize.x); float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2; float y1 = def.boundsData[0].y - def.boundsData[1].y / 2; attachment.RegionOffsetY = (int)((y1 - y0) / def.texelSize.y); attachment.RendererObject = def.material; return attachment; }
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type); // Strip folder names. int index = name.LastIndexOfAny(new char[] {'/', '\\'}); if (index != -1) name = name.Substring(index + 1); tk2dSpriteDefinition attachmentParameters = null; for (int i = 0; i < sprites.inst.spriteDefinitions.Length; ++i) { tk2dSpriteDefinition def = sprites.inst.spriteDefinitions[i]; if (def.name == name) { attachmentParameters = def; break; } } if (attachmentParameters == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")"); if (attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")"); if (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")"); Vector2 minTexCoords = Vector2.one; Vector2 maxTexCoords = Vector2.zero; for (int i = 0; i < attachmentParameters.uvs.Length; ++i) { Vector2 uv = attachmentParameters.uvs[i]; minTexCoords = Vector2.Min(minTexCoords, uv); maxTexCoords = Vector2.Max(maxTexCoords, uv); } Texture texture = attachmentParameters.material.mainTexture; int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * texture.width); int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * texture.height); bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d); if (rotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } RegionAttachment attachment = new RegionAttachment(name); attachment.SetUVs( minTexCoords.x, maxTexCoords.y, maxTexCoords.x, minTexCoords.y, rotated ); // TODO - Set attachment.RegionOffsetX/Y. What units does attachmentParameters.untrimmedBoundsData use?! attachment.RegionWidth = width; attachment.RegionHeight = height; attachment.RegionOriginalWidth = width; attachment.RegionOriginalHeight = height; return attachment; }
public Attachment NewAttachment(Skin skin,AttachmentType type,String name) { if(type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type); tk2dSpriteDefinition attachmentParameters = null; for(int i = 0; i < sprites.spriteDefinitions.Length; ++i) { tk2dSpriteDefinition def = sprites.spriteDefinitions[i]; if(def.name == name) { attachmentParameters = def; break; } } if(attachmentParameters == null ) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")"); if(attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")"); if(attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2d toolkit atlases are supported: " + name + " (" + type + ")"); Texture tex = attachmentParameters.material.mainTexture; Vector2 minTexCoords = Vector2.one; Vector2 maxTexCoords = Vector2.zero; for(int i = 0; i < attachmentParameters.uvs.Length; ++i) { Vector2 uv = attachmentParameters.uvs[i]; minTexCoords = Vector2.Min(minTexCoords,uv); maxTexCoords = Vector2.Max(maxTexCoords,uv); } int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * tex.width); int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * tex.height); bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d); if(rotated) { float temp = minTexCoords.x; minTexCoords.x = maxTexCoords.x; maxTexCoords.x = temp; } RegionAttachment attachment = new RegionAttachment(name); attachment.SetUVs( minTexCoords.x, maxTexCoords.y, maxTexCoords.x, minTexCoords.y, rotated ); attachment.RegionWidth = width; attachment.RegionHeight = height; attachment.RegionOriginalWidth = width; attachment.RegionOriginalHeight = height; return attachment; }
public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) { AtlasRegion region = atlas.FindRegion(path); if (region == null) throw new Exception("Region not found in atlas: " + path + " (region attachment: " + name + ")"); RegionAttachment attachment = new RegionAttachment(name); attachment.RendererObject = region; attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); attachment.regionOffsetX = region.offsetX; attachment.regionOffsetY = region.offsetY; attachment.regionWidth = region.width; attachment.regionHeight = region.height; attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; return attachment; }
public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) { AtlasRegion region = atlas.FindRegion(path); if (region == null) throw new Exception("Region not found in atlas: " + path + " (region attachment: " + name + ")"); RegionAttachment attachment = new RegionAttachment(name); attachment.RendererObject = region; attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); attachment.regionOffsetX = region.offsetX; attachment.regionOffsetY = region.offsetY; attachment.regionWidth = region.width; attachment.regionHeight = region.height; attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; return attachment; }
public Attachment NewAttachment(Skin skin, AttachmentType type, String name) { switch (type) { case AttachmentType.region: AtlasRegion region = atlas.FindRegion(name); if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")"); RegionAttachment attachment = new RegionAttachment(name); attachment.RendererObject = region.page.rendererObject; attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); attachment.RegionOffsetX = region.offsetX; attachment.RegionOffsetY = region.offsetY; attachment.RegionWidth = region.width; attachment.RegionHeight = region.height; attachment.RegionOriginalWidth = region.originalWidth; attachment.RegionOriginalHeight = region.originalHeight; return attachment; } throw new Exception("Unknown attachment type: " + type); }
/// <summary> /// Creates the region attachment by texture. /// </summary> /// <returns>The region attachment by texture.</returns> /// <param name="slot">Slot.</param> /// <param name="texture">Texture.</param> private Attachment CreateRegionAttachmentByTexture(Spine.Slot slot, Texture2D texture) { if (slot == null) { return(null); } Spine.RegionAttachment oldAtt = slot.Attachment as Spine.RegionAttachment; if (oldAtt == null || texture == null) { return(null); } Spine.RegionAttachment att = new Spine.RegionAttachment(oldAtt.Name); att.RendererObject = CreateRegion(texture); att.Width = oldAtt.Width; att.Height = oldAtt.Height; att.offset = oldAtt.offset; att.Path = oldAtt.Path; att.R = oldAtt.R; att.G = oldAtt.G; att.B = oldAtt.B; att.A = oldAtt.A; att.X = oldAtt.X; att.y = oldAtt.Y; att.Rotation = oldAtt.Rotation; att.ScaleX = oldAtt.ScaleX; att.ScaleY = oldAtt.ScaleY; att.SetUVs(0f, 1f, 1f, 0f, false); Material mat = new Material(Shader.Find("Sprites/Default")); mat.mainTexture = texture; (att.RendererObject as Spine.AtlasRegion).page.rendererObject = mat; slot.Attachment = att; return(slot.Attachment); }
public RegionAttachment NewRegionAttachment(Skin skin, string name, string path) { AtlasRegion region = FindRegion(path); if (region == null) { throw new ArgumentException(string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name)); } RegionAttachment attachment = new RegionAttachment(name); attachment.RendererObject = region; attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate); attachment.regionOffsetX = region.offsetX; attachment.regionOffsetY = region.offsetY; attachment.regionWidth = region.width; attachment.regionHeight = region.height; attachment.regionOriginalWidth = region.originalWidth; attachment.regionOriginalHeight = region.originalHeight; return(attachment); }
public RegionAttachment NewRegionAttachment(Skin skin, string name, string path) { AtlasRegion atlasRegion = FindRegion(path); if (atlasRegion == null) { throw new ArgumentException($"Region not found in atlas: {path} (region attachment: {name})"); } RegionAttachment regionAttachment = new RegionAttachment(name); regionAttachment.RendererObject = atlasRegion; regionAttachment.SetUVs(atlasRegion.u, atlasRegion.v, atlasRegion.u2, atlasRegion.v2, atlasRegion.rotate); regionAttachment.regionOffsetX = atlasRegion.offsetX; regionAttachment.regionOffsetY = atlasRegion.offsetY; regionAttachment.regionWidth = atlasRegion.width; regionAttachment.regionHeight = atlasRegion.height; regionAttachment.regionOriginalWidth = atlasRegion.originalWidth; regionAttachment.regionOriginalHeight = atlasRegion.originalHeight; return(regionAttachment); }
public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) { ProcessSpriteDefinition(path); RegionAttachment region = new RegionAttachment(name); region.Path = path; region.RendererObject = material; region.SetUVs(u, v, u2, v2, regionRotated); region.RegionOriginalWidth = regionOriginalWidth; region.RegionOriginalHeight = regionOriginalHeight; region.RegionWidth = regionWidth; region.RegionHeight = regionHeight; region.RegionOffsetX = regionOffsetX; region.RegionOffsetY = regionOffsetY; return region; }
private void addSkeletonAttachment(string slotName, string attachmentName, TextureData textureData) { RegionAttachment regionAttachment = new RegionAttachment(attachmentName); regionAttachment.RendererObject = textureData.Texture; regionAttachment.Width = regionAttachment.RegionWidth = regionAttachment.RegionOriginalWidth = textureData.Texture.Width; regionAttachment.Height = regionAttachment.RegionHeight = regionAttachment.RegionOriginalHeight = textureData.Texture.Height; regionAttachment.RegionOffsetX = textureData.OriginX; regionAttachment.RegionOffsetY = textureData.OriginY; regionAttachment.Rotation = textureData.Rotation; regionAttachment.SetUVs(0, 0, 1, 1, false); regionAttachment.UpdateOffset(); Skeleton.Data.FindSkin("default").AddAttachment(Skeleton.FindSlotIndex(slotName), attachmentName, regionAttachment); }
public RegionAttachment NewRegionAttachment(Skin skin, string name, string path) { RegionAttachment attachment = new RegionAttachment(name); Texture2D tex = sprite.texture; int instanceId = tex.GetInstanceID(); AtlasRegion atlasRegion; //check cache first if (atlasTable.ContainsKey(instanceId)) { atlasRegion = atlasTable[instanceId]; } else { //Setup new material Material mat = new Material(shader); if (sprite.packed) mat.name = "Unity Packed Sprite Material"; else mat.name = sprite.name + " Sprite Material"; mat.mainTexture = tex; //create faux-region to play nice with SkeletonRenderer atlasRegion = new AtlasRegion(); AtlasPage page = new AtlasPage(); page.rendererObject = mat; atlasRegion.page = page; //cache it atlasTable[instanceId] = atlasRegion; } Rect texRect = sprite.textureRect; //normalize rect to UV space of packed atlas texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x); texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y); texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width); texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height); Bounds bounds = sprite.bounds; Vector3 size = bounds.size; //TODO: make sure this rotation thing actually works bool rotated = false; if (sprite.packed) rotated = sprite.packingRotation == SpritePackingRotation.Any; //do some math and assign UVs and sizes attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated); attachment.RendererObject = atlasRegion; attachment.SetColor(Color.white); attachment.ScaleX = 1; attachment.ScaleY = 1; attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit; attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit; attachment.Width = size.x; attachment.Height = size.y; attachment.RegionWidth = size.x; attachment.RegionHeight = size.y; attachment.RegionOriginalWidth = size.x; attachment.RegionOriginalHeight = size.y; attachment.UpdateOffset(); return attachment; }
public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) { RegionAttachment attachment = new RegionAttachment(name); Texture2D tex = sprite.texture; int instanceId = tex.GetInstanceID(); AtlasRegion atlasRegion; bool cachedMaterialExists = atlasTable.TryGetValue(instanceId, out atlasRegion); if (!cachedMaterialExists) { // Setup new material. var material = new Material(shader); if (sprite.packed) material.name = "Unity Packed Sprite Material"; else material.name = sprite.name + " Sprite Material"; material.mainTexture = tex; // Create faux-region to play nice with SkeletonRenderer. atlasRegion = new AtlasRegion(); var page = new AtlasPage(); page.rendererObject = material; atlasRegion.page = page; // Cache it. atlasTable[instanceId] = atlasRegion; } Rect texRect = sprite.textureRect; // Normalize rect to UV space of packed atlas texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x); texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y); texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width); texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height); Bounds bounds = sprite.bounds; Vector2 boundsMin = bounds.min, boundsMax = bounds.max; Vector2 size = bounds.size; float spriteUnitsPerPixel = 1f / sprite.pixelsPerUnit; bool rotated = false; if (sprite.packed) rotated = sprite.packingRotation == SpritePackingRotation.Any; attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated); attachment.RendererObject = atlasRegion; attachment.SetColor(Color.white); attachment.ScaleX = 1; attachment.ScaleY = 1; attachment.RegionOffsetX = sprite.rect.width * (0.5f - InverseLerp(boundsMin.x, boundsMax.x, 0)) * spriteUnitsPerPixel; attachment.RegionOffsetY = sprite.rect.height * (0.5f - InverseLerp(boundsMin.y, boundsMax.y, 0)) * spriteUnitsPerPixel; attachment.Width = size.x; attachment.Height = size.y; attachment.RegionWidth = size.x; attachment.RegionHeight = size.y; attachment.RegionOriginalWidth = size.x; attachment.RegionOriginalHeight = size.y; attachment.UpdateOffset(); return attachment; }