- Modifié
Spine Attachment Color changed at Unity' Runtime
Hello!,
I've tried to find info about this topic and read the API but I don't understand how could and should change an attachment's color. I know the slot color is the way to go, but I use the slot color for another purpose.
In the current project I'm using a Skeleton Mecanim.
Thanks for your attention!
EDIT: I got it working by doing this:
[SerializeField] private SkeletonMecanim _skelAnim;
[SerializeField] private Spine.RegionAttachment[] bladeAttachments = new Spine.RegionAttachment[28];
[SerializeField] private Color bootColor;
private void Start()
{
bladeAttachments[0] = (Spine.RegionAttachment)_skelAnim.skeleton.GetAttachment("Blade_R_Side_Boot", "Blade_R_Side_Boot_1");
bladeAttachments[1] = (Spine.RegionAttachment)_skelAnim.skeleton.GetAttachment("Blade_L_Side_Boot", "Blade_L_Side_Boot_1");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
bladeAttachments[0].SetColor(bootColor);
bladeAttachments[1].SetColor(bootColor);
}
}
Even though it works, I still want to know the best practices!
Thanks for your attention!
The reason you don't see the .R .G .B .A
color properties is that not all attachment subtypes have a color property. You would need to cast the type of the attachment slot.Attachment
to either MeshAttachment or RegionAttachment with respective result != null
checks; or alternatively you can cast it to the IHasTextureRegion
interface which is common for both RegionAttachment and MeshAttachment.