Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        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 void LateUpdate () {
			#if UNITY_EDITOR
			if (!Application.isPlaying) skeletonTransformIsParent = Transform.ReferenceEquals(skeletonTransform, transform.parent);
			#endif

			if (point == null) {
				if (string.IsNullOrEmpty(pointAttachmentName)) return;
				UpdateReferences();
				if (point == null) return;
			}

			Vector2 worldPos;
			point.ComputeWorldPosition(bone, out worldPos.x, out worldPos.y);
			float rotation = point.ComputeWorldRotation(bone);

			Transform thisTransform = this.transform;
			if (skeletonTransformIsParent) {
				// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
				thisTransform.localPosition = new Vector3(worldPos.x, worldPos.y, followSkeletonZPosition ? 0f : thisTransform.localPosition.z);
				if (followRotation) {
					float halfRotation = rotation * 0.5f * Mathf.Deg2Rad;

					var q = default(Quaternion);
					q.z = Mathf.Sin(halfRotation);
					q.w = Mathf.Cos(halfRotation);
					thisTransform.localRotation = q;
				}
			} else {
				// For special cases: Use transform world properties if transform relationship is complicated
				Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(worldPos.x, worldPos.y, 0f));
				if (!followSkeletonZPosition)
					targetWorldPosition.z = thisTransform.position.z;

				Transform transformParent = thisTransform.parent;
				if (transformParent != null) {
					Matrix4x4 m = transformParent.localToWorldMatrix;
					if (m.m00 * m.m11 - m.m01 * m.m10 < 0) // Determinant2D is negative
						rotation = -rotation;
				}

				if (followRotation) {
					Vector3 transformWorldRotation = skeletonTransform.rotation.eulerAngles;
					thisTransform.SetPositionAndRotation(targetWorldPosition, Quaternion.Euler(transformWorldRotation.x, transformWorldRotation.y, transformWorldRotation.z + rotation));
				} else {
					thisTransform.position = targetWorldPosition;
				}
			}

			if (followSkeletonFlip) {
				Vector3 localScale = thisTransform.localScale;
				localScale.y = Mathf.Abs(localScale.y) * Mathf.Sign(bone.skeleton.scaleX * bone.skeleton.scaleY);
				thisTransform.localScale = localScale;
			}
		}
Esempio n. 5
0
        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);
        }