mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Separate auto-adding Rigidbody2D for following bones.
This commit is contained in:
parent
9ea81260eb
commit
6a8e1df108
@ -362,19 +362,25 @@ namespace Spine.Unity.Modules {
|
||||
var skin = skeleton.Skin ?? skeleton.Data.DefaultSkin;
|
||||
|
||||
var attachments = new List<Attachment>();
|
||||
foreach (Slot s in skeleton.Slots) {
|
||||
if (s.bone == b) {
|
||||
skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(s), attachments);
|
||||
foreach (Slot slot in skeleton.Slots) {
|
||||
if (slot.bone == b) {
|
||||
skin.FindAttachmentsForSlot(skeleton.Slots.IndexOf(slot), attachments);
|
||||
|
||||
bool bbAttachmentAdded = false;
|
||||
foreach (var a in attachments) {
|
||||
var bbAttachment = a as BoundingBoxAttachment;
|
||||
if (bbAttachment != null) {
|
||||
if (!a.Name.ToLower().Contains(AttachmentNameMarker))
|
||||
continue;
|
||||
|
||||
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(bbAttachment, s, go, isTrigger: false, isKinematic: false, gravityScale: gravityScale);
|
||||
bbAttachmentAdded = true;
|
||||
var bbCollider = SkeletonUtility.AddBoundingBoxAsComponent(bbAttachment, slot, go, isTrigger: false);
|
||||
colliders.Add(bbCollider);
|
||||
}
|
||||
}
|
||||
|
||||
if (bbAttachmentAdded)
|
||||
SkeletonUtility.AddBoneRigidbody2D(go, isKinematic: false, gravityScale: gravityScale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -73,18 +73,8 @@ namespace Spine.Unity {
|
||||
return AddBoundingBoxAsComponent(box, slot, go, isTrigger);
|
||||
}
|
||||
|
||||
public static PolygonCollider2D AddBoundingBoxAsComponent (BoundingBoxAttachment box, Slot slot, GameObject gameObject, bool isTrigger = true, bool isKinematic = true, float gravityScale = 0f) {
|
||||
public static PolygonCollider2D AddBoundingBoxAsComponent (BoundingBoxAttachment box, Slot slot, GameObject gameObject, bool isTrigger = true) {
|
||||
if (box == null) return null;
|
||||
|
||||
if (slot.bone != slot.Skeleton.RootBone) {
|
||||
var rb = gameObject.GetComponent<Rigidbody2D>();
|
||||
if (rb == null) {
|
||||
rb = gameObject.AddComponent<Rigidbody2D>();
|
||||
rb.isKinematic = isKinematic;
|
||||
rb.gravityScale = gravityScale;
|
||||
}
|
||||
}
|
||||
|
||||
var collider = gameObject.AddComponent<PolygonCollider2D>();
|
||||
collider.isTrigger = isTrigger;
|
||||
SetColliderPointsLocal(collider, slot, box);
|
||||
@ -114,6 +104,16 @@ namespace Spine.Unity {
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public static Rigidbody2D AddBoneRigidbody2D (GameObject gameObject, bool isKinematic = true, float gravityScale = 0f) {
|
||||
var rb = gameObject.GetComponent<Rigidbody2D>();
|
||||
if (rb == null) {
|
||||
rb = gameObject.AddComponent<Rigidbody2D>();
|
||||
rb.isKinematic = isKinematic;
|
||||
rb.gravityScale = gravityScale;
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public delegate void SkeletonUtilityDelegate ();
|
||||
|
||||
@ -222,6 +222,7 @@ namespace Spine.Unity {
|
||||
}
|
||||
|
||||
public void AddBoundingBox (string skinName, string slotName, string attachmentName) {
|
||||
SkeletonUtility.AddBoneRigidbody2D(transform.gameObject);
|
||||
SkeletonUtility.AddBoundingBoxGameObject(bone.skeleton, skinName, slotName, attachmentName, transform);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user