- Đã chỉnh sửa
How to acquire the Slot that a Skin is located in?
We are attempting to recolor Slots in our game, and in most cases our setup is working, however in a few cases the setup fails to find a slot. We are attempting to find the Slot that a Skin is located in. Our current method of doing that looks like this:
SlotName = animControl.skeleton.Data.Slots.Find(s => s.AttachmentName == SkinName).Name;
This however does not seem to be an accurate way of acquiring the slot data. What is the correct way to get the Slot that a Skin is located in?
Thank you!
You can use
animControl.skeleton.FindSlot(slotName)
or
animControl.FindSlotIndex(slotName)
However, if your above code sometimes works and sometimes not, I assume that you have another problem that prevents this logic from working as expected.
The code you posted above assumes I know the slot name, however that is what I am attempting to acquire. I have the skeleton, and I know the skin name, and I want to find the name of the slot that the skin is inside of.
Sorry, misunderstood your question and thought you had a special naming scheme set up.
If I understood you correctly now, you could do something like this:
Skin skin = <assign your skin here, however you want to access it>;
var attachmentsInSkin = skin.GetAttachments();
string slotName = attachmentsInSkin.Count > 0 ? skeleton.Slots.Items[attachmentsInSkin[0].SlotIndex].data.name : "no slots in skin";
DCalabrese đã viếtthe Slot that a Skin is located in.
What you are trying to do seems against the normal way how you would organize stuff. A skin contains attachments that are assigned to slots, it is not skins that are part of a slot.
I don't know your setup well enough, but it is in general considered good design to have the application logic manage it's state of assignment at a specialized module (at e.g. a graphics module) instead of performing manipulations and then querying what it just has done.