コード例 #1
0
        public static Attachment GetAttachment(string attachmentPath, SkeletonData skeletonData)
        {
            Hierarchy hierarchy = GetHierarchy(attachmentPath);

            return((!string.IsNullOrEmpty(hierarchy.name)) ? skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name) : null);
        }
コード例 #2
0
    void Apply()
    {
        SkeletonAnimation skeletonAnimation = GetComponent <SkeletonAnimation>();
        Skeleton          skeleton          = skeletonAnimation.skeleton;
        SkeletonData      skeletonData      = skeleton.Data;

        // Get the template skin. Prepare the custom skin.
        Skin templateSkin      = skeletonData.FindSkin(templateSkinName);
        Skin currentEquipsSkin = new Skin("my custom skin");

//		BODY SETUP
        if (bodySprite)
        {
            int        bodySlotIndex = skeleton.FindSlotIndex(bodySlot);
            Attachment templateBody  = templateSkin.GetAttachment(bodySlotIndex, bodyKey);
            Attachment newBody       = templateBody.GetRemappedClone(bodySprite, sourceMaterial);
            if (newBody != null)
            {
                currentEquipsSkin.SetAttachment(bodySlotIndex, bodyKey, newBody);
            }
        }

//		HAIR SETUP
        if (hairSprite)
        {
            int        hairSlotIndex = skeleton.FindSlotIndex(hairSlot);
            Attachment templateHair  = templateSkin.GetAttachment(hairSlotIndex, hairKey);
            Attachment newHair       = templateHair.GetRemappedClone(hairSprite, sourceMaterial);
            if (newHair != null)
            {
                currentEquipsSkin.SetAttachment(hairSlotIndex, hairKey, newHair);
            }
        }

//		EYE SETUP
        if (eyeSprite)
        {
            int        eyeSlotIndex = skeleton.FindSlotIndex(eyeSlot);
            Attachment templateEye  = templateSkin.GetAttachment(eyeSlotIndex, eyeKey);
            Attachment newEye       = templateEye.GetRemappedClone(eyeSprite, sourceMaterial);
            if (newEye != null)
            {
                currentEquipsSkin.SetAttachment(eyeSlotIndex, eyeKey, newEye);
            }
        }

//		MOUTH SETUP
        if (mouthSprite)
        {
            int        mouthSlotsIndex = skeleton.FindSlotIndex(mouthSlot);
            Attachment templateMouth   = templateSkin.GetAttachment(mouthSlotsIndex, mouthKey);
            Attachment newMouth        = templateMouth.GetRemappedClone(mouthSprite, sourceMaterial);
            if (newMouth != null)
            {
                currentEquipsSkin.SetAttachment(mouthSlotsIndex, mouthKey, newMouth);
            }
        }


//		ACC SETUP
        if (accSprite)
        {
            int        accSlotsIndex = skeleton.FindSlotIndex(accSlot);
            Attachment templateAcc   = templateSkin.GetAttachment(accSlotsIndex, accKey);
            Attachment newAcc        = templateAcc.GetRemappedClone(accSprite, sourceMaterial);
            if (newAcc != null)
            {
                currentEquipsSkin.SetAttachment(accSlotsIndex, accKey, newAcc);
            }
        }

//		SHIRT SETUP
        if (shirtSprite)
        {
            int        shirtSlotsIndex = skeleton.FindSlotIndex(shirtSlot);
            Attachment templateShirt   = templateSkin.GetAttachment(shirtSlotsIndex, shirtKey);
            Attachment newShirt        = templateShirt.GetRemappedClone(shirtSprite, sourceMaterial);
            if (newShirt != null)
            {
                currentEquipsSkin.SetAttachment(shirtSlotsIndex, shirtKey, newShirt);
            }
        }

//		//PANTS SETUP
        if (pantsSprite)
        {
            int        pantsSlotIndex = skeleton.FindSlotIndex(pantsSlot);
            Attachment templatePants  = templateSkin.GetAttachment(pantsSlotIndex, pantsKey);
            Attachment newPants       = templatePants.GetRemappedClone(pantsSprite, sourceMaterial);
            if (newPants != null)
            {
                currentEquipsSkin.SetAttachment(pantsSlotIndex, pantsKey, newPants);
            }
        }

//		SHOE SETUP
        if (shoeSprite)
        {
            int        shoeSlotsIndex = skeleton.FindSlotIndex(shoeSlot);
            Attachment templateShoe   = templateSkin.GetAttachment(shoeSlotsIndex, showKey);
            Attachment newShoe        = templateShoe.GetRemappedClone(shoeSprite, sourceMaterial);
            if (newShoe != null)
            {
                currentEquipsSkin.SetAttachment(shoeSlotsIndex, showKey, newShoe);
            }
        }



        // Set and apply the Skin to the skeleton.
        skeleton.SetSkin(currentEquipsSkin);
        skeleton.SetSlotsToSetupPose();
        skeletonAnimation.Update(0);

        Resources.UnloadUnusedAssets();
    }