my spine version is :3.6.53
this two picture is my role in Spine editor,one is setup mode,another is in animate mode:
int the setup mode,the shield scale is 3.0
I want change the shield in runtime
this is default role in unity:
this is first code:
Attachment baseAttachment = targetSlot.Attachment;//获得初始的Attachment
//baseAttachment = baseAttachment.GetClone(true); // gets a clone of the original
//baseAttachment=sprAvatar.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));// completely ignores the original and makes a new attachment
Attachment newAttachment = baseAttachment.GetRemappedClone(sprAvatar, sourceMaterial);//复制初始的Attachment,并加载上新的图片
this.customSkin.SetAttachment(visorSlotIndex, baseAttachment.Name, newAttachment);//把复制并替换好资源的Attachment添加到目标slot上
this.skeleton.SetAttachment(strTargetSlot, baseAttachment.Name);//设置显示新的服装
and the effect in unity:
the shield size is too big,don't know why.
I change code like this,second code:
Attachment baseAttachment = targetSlot.Attachment;//获得初始的Attachment
baseAttachment = baseAttachment.GetClone(true); // gets a clone of the original
baseAttachment=sprAvatar.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));// completely ignores the original and makes a new attachment
Attachment newAttachment = baseAttachment.GetRemappedClone(sprAvatar, sourceMaterial);//复制初始的Attachment,并加载上新的图片
this.customSkin.SetAttachment(visorSlotIndex, baseAttachment.Name, newAttachment);//把复制并替换好资源的Attachment添加到目标slot上
this.skeleton.SetAttachment(strTargetSlot, baseAttachment.Name);//设置显示新的服装
and the effect is:
the shild is too small! and this code lead to another issue,
other equip change is wrong,any other equip is Horizontal, it looks like rotate 90°:
I read this two topic,and can't find final solution:
换装后尺寸不对怎么设置呢?
Difficulties with Mix n Match "From Sprite"
this is my whole code:
public class AvatarManager
{
private Material sourceMaterial;
private Skin customSkin;
private Skeleton skeleton;
public AvatarManager(SkeletonAnimation skeletonAnimation)
{
this.sourceMaterial = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].materials[0];
this.skeleton = skeletonAnimation.Skeleton;
this.customSkin = new Skin("custom skin");
this.skeleton.SetSkin(customSkin);
}
/// <summary>
/// 切换部件
/// </summary>
/// <param name="sprAvatar">要切换至的部件精灵</param>
/// <param name="strTargetSlot">要切换的骨骼插槽</param>
public void changeAvatar(Sprite sprAvatar, string strTargetSlot)
{
Slot targetSlot = skeleton.FindSlot(strTargetSlot);//查找到slot的数据
if (targetSlot != null)
{
int visorSlotIndex = targetSlot.Data.Index;//slot的编号
if (targetSlot.Attachment == null)
{
targetSlot.Skeleton.SetAttachment(strTargetSlot, strTargetSlot);
}
Attachment baseAttachment = targetSlot.Attachment;//获得初始的Attachment
baseAttachment = baseAttachment.GetClone(true); // gets a clone of the original
baseAttachment=sprAvatar.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton"));// completely ignores the original and makes a new attachment
Attachment newAttachment = baseAttachment.GetRemappedClone(sprAvatar, sourceMaterial);//复制初始的Attachment,并加载上新的图片
this.customSkin.SetAttachment(visorSlotIndex, baseAttachment.Name, newAttachment);//把复制并替换好资源的Attachment添加到目标slot上
this.skeleton.SetAttachment(strTargetSlot, baseAttachment.Name);//设置显示新的服装
}
}
}
Thanks 😃 😃 😃