@Harald,
Thanks I did try this, but now the gear stays on even after they should be hidden.
Do I need to check if the slot is disabled (if so how?) and then not attach? In my head it seems like if the slot is hidden, the gear attachment should be ignored since the parent is not active. But I guess the way it works is that when a slot is hidden during an animation its just a reference that still needs to be read and only if its active attach the gear?
Here was my initial attempt:
In my UnitAnimator script I set the callback:
public Action skeletonAnimationUpdateCompleteCallback;
public void Init(S_Unit unitState)
{
_animator.UpdateComplete += delegate (ISkeletonAnimation animated)
{
skeletonAnimationUpdateCompleteCallback?.Invoke();
};
}
Then in my main unit class I call update gear on this:
// Update gear on skeleton for animations which might hide it during the animation
unitAnimator.skeletonAnimationUpdateCompleteCallback = UpdateGear;
public void UpdateGear()
{
if (_spriteAttacher == null)
{
X_Logger.LogError("Missing sprite attacher on " + gameObject);
}
// Check if has gear
if (_unitState.trinketCardGO != null)
{
_spriteAttacher.Attach(_unitState.trinketState.gearSkinModel.spineSprite, T_EquipSlots.TRINKET);
}
if (_unitState.weaponCardGO != null)
{
_spriteAttacher.Attach(_unitState.weaponState.gearSkinModel.spineSprite, T_EquipSlots.WEAPON);
}
if (_unitState.armorCardGO != null)
{
M_GearSkin armor = _unitState.armorState.gearSkinModel;
_spriteAttacher.Attach(armor.spineSprite, T_EquipSlots.ARMOR);
_spriteAttacher.Attach(armor.frontLowerArmSprite, T_EquipSlots.FRONT_LOWER_ARM);
_spriteAttacher.Attach(armor.frontUpperArmSprite, T_EquipSlots.FRONT_UPPER_ARM);
_spriteAttacher.Attach(armor.backLowerArmSprite, T_EquipSlots.BACK_LOWER_ARM);
_spriteAttacher.Attach(armor.backUpperArmSprite, T_EquipSlots.BACK_UPPER_ARM);
_spriteAttacher.Attach(armor.frontArmorSprite, T_EquipSlots.BACK_UPPER_ARM);
}
if (_unitState.helmetCardGO != null)
{
if (_unitState.helmetState == null)
{
X_Logger.LogError("Null helmet state but non null helmet card go");
}
_spriteAttacher.Attach(_unitState.helmetState.gearSkinModel.spineSprite, T_EquipSlots.HELMET);
if (_unitState.helmetState.gearSkinModel.helmetBackSprite)
{
_spriteAttacher.Attach(_unitState.helmetState.gearSkinModel.helmetBackSprite, T_EquipSlots.HELMET_BACK);
}
else
{
var helmetBackSlot = _skeletonAnimation.skeleton.FindSlot("helmetBack");
helmetBackSlot.Attachment = null;
}
if (_unitState.helmetState.gearSkinModel.hideEars)
{
var frontEarSlot = _skeletonAnimation.skeleton.FindSlot("frontEar");
frontEarSlot.Attachment = null;
var backEarSlot = _skeletonAnimation.skeleton.FindSlot("backEar");
backEarSlot.Attachment = null;
}
}
}
In my UpdateGear code, do I need to check if the slot is active and if so attach null?
Also performing this is extremely expensive its dropping my fps from like 300 to 30 so I dont think this approach I took is correct.