void Start() { var skeletonAnimation = GetComponent <SkeletonAnimation>(); var skeleton = skeletonAnimation.Skeleton; // All attachment changes will be applied to the skin. We use a clone so other instances will not be affected. var newSkin = skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // Case 1: Create an attachment from an atlas. RegionAttachment newHand = handSource.GetAtlas().FindRegion(handRegion).ToRegionAttachment("new hand"); newHand.SetPositionOffset(newHandOffset); newHand.Rotation = newHandRotation; newHand.UpdateOffset(); int handSlotIndex = skeleton.FindSlotIndex(handSlot); handTexture = newHand.GetRegion().ToTexture(); newSkin.AddAttachment(handSlotIndex, handAttachmentName, newHand); // Case 2: Create an attachment from a Unity Sprite (Sprite texture needs to be Read/Write Enabled in the inspector. RegionAttachment newWeapon = dagger.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton")); newWeapon.SetScale(1.5f, 1.5f); newWeapon.UpdateOffset(); int weaponSlotIndex = skeleton.FindSlotIndex(weaponSlot); newSkin.AddAttachment(weaponSlotIndex, daggerName, newWeapon); // Case 3: Change an existing attachment's backing region. if (applyHeadRegion) { AtlasRegion spineBoyHead = headSource.GetAtlas().FindRegion(headRegion); int headSlotIndex = skeleton.FindSlotIndex(headSlot); var newHead = newSkin.GetAttachment(headSlotIndex, headAttachmentName).GetClone(true); newHead.SetRegion(spineBoyHead); newSkin.AddAttachment(headSlotIndex, headAttachmentName, newHead); } // Case 4: Repacking a mixed-and-matched skin to minimize draw calls. // Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector. if (repack) { newSkin = newSkin.GetRepackedSkin("repacked", repackedShader, out runtimeMaterial, out runtimeAtlas); } skeleton.SetSkin(newSkin); skeleton.SetToSetupPose(); skeleton.SetAttachment(weaponSlot, daggerName); Resources.UnloadUnusedAssets(); }
// // Use this for initialization void Start() { SkeletonAnimation _ani = this.GetComponent <SkeletonAnimation>(); Skeleton _skeleton = _ani.skeleton; Skin _newSkin = _skeleton.UnshareSkin(true, false, _ani.AnimationState); //HeadFront Setting RegionAttachment _newHeadFront = headFront.ToRegionAttachmentPMAClone(Shader.Find("Spine/Skeleton")); _newHeadFront.SetScale(1f, 1f); _newHeadFront.UpdateOffset(); int headFrontSlotIndex = _skeleton.FindSlotIndex(headFrontSlot); _newSkin.AddAttachment(headFrontSlotIndex, headFront.name, _newHeadFront); //repack _newSkin = _newSkin.GetRepackedSkin("repacked", repackedShader, out runtimeMaterial, out runtimeAtlas); _skeleton.SetSkin(_newSkin); _skeleton.SetToSetupPose(); //_skeleton.SetToSetupPose(); _skeleton.SetAttachment(headFrontSlot, headFront.name); }