Hi there!
I'm sorry, I know this is asked frequently, but I can't seem to find some solid information on what is actually happening in the included examples. I basically just want to clarify that what I'm doing is correct, and that I'm not misunderstanding and/or causing unnecessary overhead. Here is my code:
public SkeletonAnimation SkeletonAnimation;
AnimationState _spineAnimationState;
Skeleton _spineSkeleton;
Skin _loadoutSkin;
public override void Init(AgentLoadout loadout) {
_spineAnimationState = SkeletonAnimation.AnimationState;
_spineSkeleton = SkeletonAnimation.Skeleton;
UpdateSkin(loadout.PrimaryWeaponName, loadout.SecondaryWeaponName);
}
void UpdateSkin(int primaryName, int secondaryName) {
Skin primary = _spineSkeleton.Data.FindSkin(primaryName);
Skin secondary = _spineSkeleton.Data.FindSkin(secondaryName);
_loadoutSkin = _loadoutSkin ?? (_loadoutSkin = new Skin("Loadout"));
_loadoutSkin.Append(primary);
_loadoutSkin.Append(secondary);
_spineSkeleton.SetSkin(_loadoutSkin);
_spineSkeleton.SetSlotsToSetupPose();
_spineAnimationState.Update(0);
}
primaryName and secondaryName can change during play. We have one 'swap' animation, to change between the current primary and secondary weapons. Is it fine to call UpdateSkin each time the player's primary or secondary weapon change?
If I'm reusing the same skin over and over, is it a problem calling Skin.Append? Am I adding to an ever-increasing skin, or will the old skins be removed? For example, if a new primary weapon doesn't have an attachment that an old one did, will the old one's attachment be removed? Or should I be calling a different function? Or should I be creating a new skin? There are multiple characters, all with different loadouts, in case that's relevant.
Finally Skeleton.SetSlotsToSetupPose and AnimationState.Update(float) - these are used in most examples, though sometimes Apply is used instead of Update. What are these doing exactly? Simple ensuring the new skin is actually applied? If so, is there a reason this couldn't be called automatically by Skeleton.SetSkin? (Actual question, not smarmy observation.)