public static PointAttachment GetClone(this PointAttachment o) => new PointAttachment(o.Name) { rotation = o.rotation, x = o.x, y = o.y };
static void DrawPointAttachmentWithLabel(PointAttachment point, Bone bone, Transform transform) { Vector3 labelOffset = new Vector3(0f, -0.2f, 0f); SpineHandles.DrawPointAttachment(bone, point, transform); Handles.Label(labelOffset + point.GetWorldPosition(bone, transform), point.Name, SpineHandles.PointNameStyle); }
public static Attachment GetClone(this Attachment o, bool cloneMeshesAsLinked) { RegionAttachment regionAttachment = o as RegionAttachment; if (regionAttachment != null) { return(regionAttachment.GetClone()); } MeshAttachment meshAttachment = o as MeshAttachment; if (meshAttachment != null) { return((!cloneMeshesAsLinked) ? meshAttachment.GetClone() : meshAttachment.GetLinkedClone()); } BoundingBoxAttachment boundingBoxAttachment = o as BoundingBoxAttachment; if (boundingBoxAttachment != null) { return(boundingBoxAttachment.GetClone()); } PathAttachment pathAttachment = o as PathAttachment; if (pathAttachment != null) { return(pathAttachment.GetClone()); } PointAttachment pointAttachment = o as PointAttachment; if (pointAttachment != null) { return(pointAttachment.GetClone()); } return((o as ClippingAttachment)?.GetClone()); }
/// <summary>Gets the PointAttachment's Unity World position using its Spine GameObject Transform.</summary> public static Vector3 GetWorldPosition(this PointAttachment attachment, Bone bone, Transform spineGameObjectTransform) { Vector3 skeletonSpacePosition; skeletonSpacePosition.z = 0; attachment.ComputeWorldPosition(bone, out skeletonSpacePosition.x, out skeletonSpacePosition.y); return(spineGameObjectTransform.TransformPoint(skeletonSpacePosition)); }
public static Vector3 GetWorldPosition(this PointAttachment attachment, Bone bone, Transform spineGameObjectTransform) { Vector3 position = default(Vector3); position.z = 0f; attachment.ComputeWorldPosition(bone, out position.x, out position.y); return(spineGameObjectTransform.TransformPoint(position)); }
public static Vector3 GetWorldPosition(this PointAttachment attachment, Slot slot, Transform spineGameObjectTransform) { Vector3 vector; vector.z = 0f; attachment.ComputeWorldPosition(slot.bone, out vector.x, out vector.y); return(spineGameObjectTransform.TransformPoint(vector)); }
public override Attachment Copy() { PointAttachment copy = new PointAttachment(this.Name); copy.x = x; copy.y = y; copy.rotation = rotation; return(copy); }
public static PointAttachment GetClone(this PointAttachment o) { PointAttachment pointAttachment = new PointAttachment(o.Name); pointAttachment.rotation = o.rotation; pointAttachment.x = o.x; pointAttachment.y = o.y; return(pointAttachment); }
void UpdateReferences () { skeletonTransform = skeletonRenderer.transform; skeletonRenderer.OnRebuild -= HandleRebuildRenderer; skeletonRenderer.OnRebuild += HandleRebuildRenderer; skeletonTransformIsParent = Transform.ReferenceEquals(skeletonTransform, transform.parent); bone = null; point = null; if (!string.IsNullOrEmpty(pointAttachmentName)) { var skeleton = skeletonRenderer.Skeleton; int slotIndex = skeleton.FindSlotIndex(slotName); if (slotIndex >= 0) { var slot = skeleton.slots.Items[slotIndex]; bone = slot.bone; point = skeleton.GetAttachment(slotIndex, pointAttachmentName) as PointAttachment; } } }
public static void DrawPointAttachment(Bone bone, PointAttachment pointAttachment, Transform skeletonTransform) { if (bone == null) { return; } if (pointAttachment == null) { return; } Vector2 localPos; pointAttachment.ComputeWorldPosition(bone, out localPos.x, out localPos.y); float localRotation = pointAttachment.ComputeWorldRotation(bone); Matrix4x4 m = Matrix4x4.TRS(localPos, Quaternion.Euler(0, 0, localRotation), Vector3.one) * Matrix4x4.TRS(Vector3.right * 0.25f, Quaternion.identity, Vector3.one); DrawBoneCircle(skeletonTransform.TransformPoint(localPos), SpineHandles.PointColor, Vector3.back, 1.3f); DrawArrowhead(skeletonTransform.localToWorldMatrix * m); }
private void UpdateReferences() { this.skeletonTransform = this.skeletonRenderer.transform; this.skeletonRenderer.OnRebuild -= new Spine.Unity.SkeletonRenderer.SkeletonRendererDelegate(this.HandleRebuildRenderer); this.skeletonRenderer.OnRebuild += new Spine.Unity.SkeletonRenderer.SkeletonRendererDelegate(this.HandleRebuildRenderer); this.skeletonTransformIsParent = object.ReferenceEquals(this.skeletonTransform, base.transform.parent); this.bone = null; this.point = null; if (!string.IsNullOrEmpty(this.pointAttachmentName)) { Skeleton skeleton = this.skeletonRenderer.skeleton; int index = skeleton.FindSlotIndex(this.slotName); if (index >= 0) { Slot slot = skeleton.slots.Items[index]; this.bone = slot.bone; this.point = skeleton.GetAttachment(index, this.pointAttachmentName) as PointAttachment; } } }
public static Attachment GetClone(this Attachment o, bool cloneMeshesAsLinked) { RegionAttachment attachment = o as RegionAttachment; if (attachment != null) { return(attachment.GetClone()); } MeshAttachment attachment2 = o as MeshAttachment; if (attachment2 != null) { return(!cloneMeshesAsLinked ? attachment2.GetClone() : attachment2.GetLinkedClone(true)); } BoundingBoxAttachment attachment3 = o as BoundingBoxAttachment; if (attachment3 != null) { return(attachment3.GetClone()); } PathAttachment attachment4 = o as PathAttachment; if (attachment4 != null) { return(attachment4.GetClone()); } PointAttachment attachment5 = o as PointAttachment; if (attachment5 != null) { return(attachment5.GetClone()); } ClippingAttachment attachment6 = o as ClippingAttachment; if (attachment6 != null) { return(attachment6.GetClone()); } return(null); }
/// <summary> /// 主要逻辑copy SkeletonJson.ReadAttachment /// </summary> /// <param name="sdEX"></param> /// <param name="atlasArray"></param> /// <returns></returns> public Skin GenSkinBySkniDataAsset(SkinDataEx sdEX, Atlas[] atlasArray) { #if SPINE_TK2D throw new NotImplementedException("GenSkinBySkniDataAsset Not Implemented"); #endif float scale = this.skeletonDataAsset.scale; var attachmentLoader = new AtlasAttachmentLoader(atlasArray); var skin = new Skin(sdEX.SkinName); var linkedMeshes = new List <SkeletonJson.LinkedMesh>(); Attachment attachment = null; foreach (var slot in sdEX.AllSlots) { var slotIndex = skeleton.Data.FindSlotIndex(slot.SlotName); foreach (var entry in slot.AllAttachments) { switch (entry.type) { case AttachmentType.Region: { RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, entry.AttachmentName, entry.PathName); if (region == null) { Debug.LogError("RegionAttachment New Fail:" + entry.AttachmentName + "," + entry.PathName); continue; } region.Path = entry.PathName; #region Region数据的填充 CheckRegionData(entry.FloatValues); Single w = 32, h = 32; foreach (var f in entry.FloatValues) { switch (f.Key) { case "x": region.x = f.FloatValue * scale; break; case "y": region.y = f.FloatValue * scale; break; case "scaleX": region.scaleX = f.FloatValue; break; case "scaleY": region.scaleY = f.FloatValue; break; case "rotation": region.rotation = f.FloatValue; break; case "width": w = f.FloatValue; break; case "height": h = f.FloatValue; break; } } region.width = w * scale; region.height = h * scale; if (entry.ColorValues != null && entry.ColorValues.Count > 0) { foreach (var c in entry.ColorValues) { switch (c.Key) { case "color": region.r = c.ColorValue.r; region.g = c.ColorValue.g; region.b = c.ColorValue.b; region.a = c.ColorValue.a; break; } } } #endregion region.UpdateOffset(); attachment = region; } break; case AttachmentType.Boundingbox: { BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, entry.AttachmentName); if (box == null) { Debug.LogError("BoundingBoxAttachment New Fail:" + entry.AttachmentName); continue; } #region Box数据填充 Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { if (fs.Key.Equals("vertices")) { ReadVertices(fs, box, vertexCount << 1, scale); break; } } #endregion attachment = box; } break; case AttachmentType.Mesh: case AttachmentType.Linkedmesh: { MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, entry.AttachmentName, entry.PathName); if (mesh == null) { Debug.LogError("MeshAttachment New Fail:" + entry.AttachmentName + "," + entry.PathName); continue; } #region Mesh数据填充 mesh.Path = entry.PathName; if (entry.ColorValues != null && entry.ColorValues.Count > 0) { foreach (var c in entry.ColorValues) { if (c.Key.Equals("color")) { mesh.r = c.ColorValue.r; mesh.g = c.ColorValue.g; mesh.b = c.ColorValue.b; mesh.a = c.ColorValue.a; break; } } } Single w = 0, h = 0; foreach (var f in entry.FloatValues) { switch (f.Key) { case "width": w = f.FloatValue * scale; break; case "height": h = f.FloatValue * scale; break; } } mesh.Width = w; mesh.Height = h; String parentStr = null, skinStr = null; Boolean deform = true; if (entry.StringValues != null && entry.StringValues.Count > 0) { foreach (var ss in entry.StringValues) { switch (ss.Key) { case "parent": parentStr = ss.StringValue; break; case "skin": skinStr = ss.StringValue; break; } } } if (entry.BoolValues != null && entry.BoolValues.Count > 0) { foreach (var b in entry.BoolValues) { if (b.Key.Equals("deform")) { deform = b.BooleanValue; break; } } } if (parentStr != null) { mesh.InheritDeform = deform; linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinStr, slotIndex, parentStr)); } KeyFloatArrayPair kfap_Vs = new KeyFloatArrayPair(); Single[] uvs = null; foreach (var fs in entry.FloatArrayValues) { switch (fs.Key) { case "vertices": kfap_Vs = fs; break; case "uvs": uvs = fs.FloatArrayValue.ToArray(); break; } } ReadVertices(kfap_Vs, mesh, uvs.Length, scale); Int32[] triangles = null, edges = null; if (entry.IntArrayValues != null && entry.IntArrayValues.Count > 0) { foreach (var i32s in entry.IntArrayValues) { switch (i32s.Key) { case "triangles": triangles = i32s.IntArrayValue.ToArray(); break; case "edges": edges = i32s.IntArrayValue.ToArray(); break; } } } mesh.triangles = triangles; mesh.regionUVs = uvs; mesh.UpdateUVs(); Int32 hull = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("hull")) { hull = i.IntValue * 2; break; } } } if (hull != 0) { mesh.HullLength = hull; } if (edges != null) { mesh.Edges = edges; } #endregion attachment = mesh; } break; case AttachmentType.Path: { PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, entry.AttachmentName); if (pathAttachment == null) { Debug.LogError("PathAttachment New Fail:" + entry.AttachmentName); continue; } #region Path填充数据 Boolean closed = false, constantSpeed = false; if (entry.BoolValues != null && entry.BoolValues.Count > 0) { foreach (var b in entry.BoolValues) { switch (b.Key) { case "closed": closed = b.BooleanValue; break; case "constantSpeed": constantSpeed = b.BooleanValue; break; } } } pathAttachment.closed = closed; pathAttachment.constantSpeed = constantSpeed; Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { switch (fs.Key) { case "vertices": ReadVertices(fs, pathAttachment, vertexCount << 1, scale); break; case "lengths": var count = fs.FloatArrayValue.Count; pathAttachment.lengths = new Single[count]; for (var idx = 0; idx < count; idx++) { pathAttachment.lengths[idx] = fs.FloatArrayValue[idx] * scale; } break; } } #endregion attachment = pathAttachment; } break; case AttachmentType.Point: { PointAttachment point = attachmentLoader.NewPointAttachment(skin, entry.AttachmentName); if (point == null) { Debug.LogError("PointAttachment New Fail:" + entry.AttachmentName); continue; } #region Point填充数据 Single x = 0, y = 0, r = 0; if (entry.FloatValues != null && entry.FloatValues.Count > 0) { foreach (var f in entry.FloatValues) { switch (f.Key) { case "x": x = f.FloatValue * scale; break; case "y": y = f.FloatValue * scale; break; case "rotation": r = f.FloatValue; break; } } } point.x = x; point.y = y; point.rotation = r; #endregion attachment = point; } break; case AttachmentType.Clipping: { ClippingAttachment clip = attachmentLoader.NewClippingAttachment(skin, entry.AttachmentName); if (clip == null) { Debug.LogError("ClippingAttachment New Fail:" + entry.AttachmentName); continue; } #region Clipping填充数据 String end = null; if (entry.StringValues != null && entry.StringValues.Count > 0) { foreach (var s in entry.StringValues) { if (s.Key.Equals("end")) { end = s.StringValue; break; } } } if (end != null) { SlotData sd = skeleton.Data.FindSlot(end); if (sd == null) { throw new Exception("Clipping end slot not found: " + end); } clip.EndSlot = sd; } Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { if (fs.Key.Equals("vertices")) { ReadVertices(fs, clip, vertexCount << 1, scale); break; } } #endregion attachment = clip; } break; default: break; } skin.SetAttachment(slot.SlotName, entry.AttachmentName, attachment, skeleton); } } // Linked meshes. for (int i = 0, n = linkedMeshes.Count; i < n; i++) { var linkedMesh = linkedMeshes[i]; Skin sk = linkedMesh.skin == null ? skeleton.Data.defaultSkin : skeleton.Data.FindSkin(linkedMesh.skin); if (sk == null) { throw new Exception("Slot not found: " + linkedMesh.skin); } Attachment parent = sk.GetAttachment(linkedMesh.slotIndex, linkedMesh.parent); if (parent == null) { throw new Exception("Parent mesh not found: " + linkedMesh.parent); } linkedMesh.mesh.ParentMesh = (MeshAttachment)parent; linkedMesh.mesh.UpdateUVs(); } skeleton.Data.Skins.Add(skin); return(skin); }