- Düzenlendi
Remove Attached Sprite
Greetings!
We are using a slightly modified legacy SpriteAttacher and I have a question about how to unattach a sprite. I tried adding a null setter if the sprite is null, but that didn't seem to work. Here is my attach code with a comment above where i am trying to clear the slot:
public void Attach(Sprite sprite, T_EquipSlots equipSlot)
{
var skeletonComponent = GetComponent<ISkeletonComponent>();
Shader attachmentShader = Shader.Find(DefaultStraightAlphaShader);
var slot = skeletonComponent.Skeleton.FindSlot(_SLOT_TYPE_TO_NAME[equipSlot]);
if (sprite == null)
{
// If sprite is null unattach [NOT WORKING]
slot.Attachment = null;
return;
}
// This is required to prevent the arms getting distorted with the wrong rotation
RegionAttachment attachment;
if (slot.Attachment != null)
{
float rotation = ((RegionAttachment)slot.Attachment).Rotation;
attachment = sprite.ToRegionAttachmentPMAClone(attachmentShader, rotation: rotation);
} else
{
attachment = sprite.ToRegionAttachmentPMAClone(attachmentShader);
}
slot.Attachment = attachment;
}
Do you know what I need to do in order to properly remove an attachment?
slot.Attachment =null;
is the proper way to clean an attachment.
I modified the SpriteAttacher.cs
file accordingly as well, it works as expected on my machine, please find it attached below. An updated version will also be included in the upcoming unitypackages.
Interesting...I will dig deeper and try to find what going on.
Basically I have an armor piece that attaches to the arm slot (which sits above the arm). And some armor has no arm armor parts so Im trying to set those slots the null. However when I do, nothing seems to happen, the legacy part of the arm attachment remains when I switch from armor with arms to armor with no arms. I can verify that the sprite is set to null and slot.attachment = null is being called. Is there a refresher call I need to make?
As you can see the arm above has a black chunk from the previous armor even though I set the attachment to null.
Aggressor yazdıI can verify that the sprite is set to null and slot.attachment = null is being called. Is there a refresher call I need to make?
You can call
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
skeletonAnimation.AnimationState.Apply(skeletonAnimation.Skeleton);
but this should only be necessary when you are not playing any animations.