Ejemplo n.º 1
0
        void Start()
        {
            var skeletonComponent = GetComponent <ISkeletonComponent>();

            if (skeletonComponent == null)
            {
                return;
            }
            var skeleton = skeletonComponent.Skeleton;

            if (skeleton == null)
            {
                return;
            }

            combinedSkin = combinedSkin ?? new Skin("combined");
            combinedSkin.Clear();
            foreach (var skinName in skinsToCombine)
            {
                var skin = skeleton.Data.FindSkin(skinName);
                if (skin != null)
                {
                    combinedSkin.AddAttachments(skin);
                }
            }

            skeleton.SetSkin(combinedSkin);
            skeleton.SetToSetupPose();
            var animationStateComponent = skeletonComponent as IAnimationStateComponent;

            if (animationStateComponent != null)
            {
                animationStateComponent.AnimationState.Apply(skeleton);
            }
        }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    private void Awake()
    {
        instance = this;
        skeleton = skeletonAnimation.Skeleton;                               // 스켈레톤 클래스
        baseSkin = skeleton.Data.FindSkin("base");                           // 기존에 있는 스킨 가져오기
        baseSkin.AddAttachments(skeleton.Data.FindSkin("weapon/weapon001")); // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("body/body001"));     // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("face/face001"));     // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("cape/cape001"));     // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("hand/hand001"));     // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("hat/hat001"));       // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("hip/hip001"));       // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가
        baseSkin.AddAttachments(skeleton.Data.FindSkin("shoes/shoes001"));   // 기존에 있는 스킨에 정의된 값을 새로운 스킨에 추가

        skeleton.SetSkin(baseSkin);
        skeleton.SetSlotsToSetupPose();
    }
        void Apply()
        {
            var skeletonGraphic = GetComponent <SkeletonGraphic>();
            var skeleton        = skeletonGraphic.Skeleton;

            // STEP 0: PREPARE SKINS
            // Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
            customSkin = customSkin ?? new Skin("custom skin");             // This requires that all customizations are done with skin placeholders defined in Spine.
            //customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin and don't plan to remove
            // Next let's get the skin that contains our source attachments. These are the attachments that
            var baseSkin = skeleton.Data.FindSkin(baseSkinName);

            // STEP 1: "EQUIP" ITEMS USING SPRITES
            // STEP 1.1 Find the original attachment.
            // Step 1.2 Get a clone of the original attachment.
            // Step 1.3 Apply the Sprite image to it.
            // Step 1.4 Add the remapped clone to the new custom skin.

            // Let's do this for the visor.
            int        visorSlotIndex = skeleton.FindSlotIndex(visorSlot);                            // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
            Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey);             // STEP 1.1
            Attachment newAttachment  = baseAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3

            customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment);                        // STEP 1.4

            // And now for the gun.
            int        gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
            Attachment baseGun      = baseSkin.GetAttachment(gunSlotIndex, gunKey);        // STEP 1.1
            Attachment newGun       = baseGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3

            if (newGun != null)
            {
                customSkin.SetAttachment(gunSlotIndex, gunKey, newGun);                             // STEP 1.4
            }
            // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item.
            // customSkin.Clear()
            // Use skin.Clear() To remove all customizations.
            // Customizations will fall back to the value in the default skin if it was defined there.
            // To prevent fallback from happening, make sure the key is not defined in the default skin.

            // STEP 3: APPLY AND CLEAN UP.
            // Recommended: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
            //              Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
            //              Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
            //              call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.
            if (repack)
            {
                var repackedSkin = new Skin("repacked skin");
                repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);
                repackedSkin.AddAttachments(customSkin);
                repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
                skeleton.SetSkin(repackedSkin);
            }
            else
            {
                skeleton.SetSkin(customSkin);
            }

            //skeleton.SetSlotsToSetupPose();
            skeleton.SetToSetupPose();
            skeletonGraphic.Update(0);
            skeletonGraphic.OverrideTexture = runtimeAtlas;

            Resources.UnloadUnusedAssets();
        }
Ejemplo n.º 4
0
    void Apply()
    {
        var skeletonAnimation = GetComponent <SkeletonAnimation>();
        var skeleton          = skeletonAnimation.Skeleton;

        // STEP 0: PREPARE SKINS
        // Let's prepare a new skin to be our custom skin with equips/customizations.
        //We get a clone so our original skins are unaffected.
        customSkin = customSkin ?? new Skin("custom skin");
        // This requires that all customizations are done with skin placeholders defined in Spine.
        //customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin.
        var templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin);

        // STEP 1: "EQUIP" ITEMS USING SPRITES
        // STEP 1.1 Find the original/template attachment.
        // Step 1.2 Get a clone of the original/template attachment.
        // Step 1.3 Apply the Sprite image to the clone.
        // Step 1.4 Add the remapped clone to the new custom skin.

        for (int i = 0; i < AllReplacePairs.Count; i++)
        {
            SlotRegionPair Pair      = AllReplacePairs[i];
            int            slotIndex = skeleton.FindSlotIndex(Pair.Slot);
            // You can access GetAttachment and SetAttachment via string
            //, but caching the slotIndex is faster.
            Attachment templateAttachment = templateSkin.GetAttachment(slotIndex, Pair.Key); // STEP 1.1
            Attachment newAttachment      = templateAttachment.GetRemappedClone
                                                (Pair.newSprite, sourceMaterial);            // STEP 1.2 - 1.3

            if (newAttachment != null)
            {
                RegionAttachment ra = newAttachment as RegionAttachment;
                ra = (RegionAttachment)ra.Copy();
                float scale = 1f / Pair.newSprite.pixelsPerUnit;
                ra.Width  = ra.RegionWidth * scale;
                ra.Height = ra.RegionHeight * scale;

                customSkin.SetAttachment(slotIndex, Pair.Key, newAttachment);//STEP 1.4
            }
        }

        if (repack)
        {
            var repackedSkin = new Skin("repacked skin");
            repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);                                                              // Include the "default" skin. (everything outside of skin placeholders)
            repackedSkin.AddAttachments(customSkin);                                                                             // Include your new custom skin.
            repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin.
            skeleton.SetSkin(repackedSkin);                                                                                      // Assign the repacked skin to your Skeleton.
            if (bbFollower != null)
            {
                bbFollower.Initialize(true);
            }
        }
        else
        {
            skeleton.SetSkin(customSkin); // Just use the custom skin directly.
        }

        skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose.
        skeletonAnimation.Update(0);    // Use the pose in the currently active animation.

        Resources.UnloadUnusedAssets();
    }
Ejemplo n.º 5
0
        void Apply()
        {
            var skeletonAnimation = GetComponent <SkeletonAnimation>();
            var skeleton          = skeletonAnimation.Skeleton;

            // STEP 0: PREPARE SKINS
            // Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
            customSkin = customSkin ?? new Skin("custom skin");             // This requires that all customizations are done with skin placeholders defined in Spine.
            //customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin.
            var templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin);

            // STEP 1: "EQUIP" ITEMS USING SPRITES
            // STEP 1.1 Find the original/template attachment.
            // Step 1.2 Get a clone of the original/template attachment.
            // Step 1.3 Apply the Sprite image to the clone.
            // Step 1.4 Add the remapped clone to the new custom skin.

            // Let's do this for the visor.
            int        visorSlotIndex     = skeleton.FindSlotIndex(visorSlot);                                // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
            Attachment templateAttachment = templateSkin.GetAttachment(visorSlotIndex, visorKey);             // STEP 1.1
            Attachment newAttachment      = templateAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3

            customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment);                                // STEP 1.4

            // And now for the gun.
            int        gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
            Attachment templateGun  = templateSkin.GetAttachment(gunSlotIndex, gunKey);            // STEP 1.1
            Attachment newGun       = templateGun.GetRemappedClone(gunSprite, sourceMaterial);     // STEP 1.2 - 1.3

            if (newGun != null)
            {
                customSkin.SetAttachment(gunSlotIndex, gunKey, newGun);                             // STEP 1.4
            }
            // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item.
            // customSkin.Clear()
            // Use skin.Clear() To remove all customizations.
            // Customizations will fall back to the value in the default skin if it was defined there.
            // To prevent fallback from happening, make sure the key is not defined in the default skin.

            // STEP 3: APPLY AND CLEAN UP.
            // Recommended, preferably at level-load-time: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
            //              IMPORTANT NOTE: the GetRepackedSkin() operation is expensive - if multiple characters
            //              need to call it every few seconds the overhead will outweigh the draw call benefits.
            //
            //              Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
            //              Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
            //              call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.
            if (repack)
            {
                var repackedSkin = new Skin("repacked skin");
                repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);                                                              // Include the "default" skin. (everything outside of skin placeholders)
                repackedSkin.AddAttachments(customSkin);                                                                             // Include your new custom skin.
                repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas); // Pack all the items in the skin.
                skeleton.SetSkin(repackedSkin);                                                                                      // Assign the repacked skin to your Skeleton.
                if (bbFollower != null)
                {
                    bbFollower.Initialize(true);
                }
            }
            else
            {
                skeleton.SetSkin(customSkin);                 // Just use the custom skin directly.
            }

            skeleton.SetSlotsToSetupPose();          // Use the pose from setup pose.
            skeletonAnimation.Update(0);             // Use the pose in the currently active animation.

            Resources.UnloadUnusedAssets();
        }
Ejemplo n.º 6
0
        void Apply()
        {
            var skeletonGraphic = GetComponent <SkeletonGraphic>();
            var skeleton        = skeletonGraphic.Skeleton;

            // STEP 0: PREPARE SKINS
            // Let's prepare a new skin to be our custom skin with equips/customizations. We get a clone so our original skins are unaffected.
            customSkin = customSkin ?? new Skin("custom skin");             // This requires that all customizations are done with skin placeholders defined in Spine.
            //customSkin = customSkin ?? skeleton.UnshareSkin(true, false, skeletonAnimation.AnimationState); // use this if you are not customizing on the default skin and don't plan to remove
            // Next let's get the skin that contains our source attachments. These are the attachments that
            var baseSkin = skeleton.Data.FindSkin(baseSkinName);

            // STEP 1: "EQUIP" ITEMS USING SPRITES
            // STEP 1.1 Find the original attachment.
            // Step 1.2 Get a clone of the original attachment.
            // Step 1.3 Apply the Sprite image to it.
            // Step 1.4 Add the remapped clone to the new custom skin.

            // Let's do this for the visor.
            int        visorSlotIndex = skeleton.FindSlotIndex(visorSlot);                            // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster.
            Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey);             // STEP 1.1
            Attachment newAttachment  = baseAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3

            // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates
            // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as done below.
            customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment);             // STEP 1.4

            // And now for the gun.
            int        gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
            Attachment baseGun      = baseSkin.GetAttachment(gunSlotIndex, gunKey);        // STEP 1.1
            Attachment newGun       = baseGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3

            if (newGun != null)
            {
                customSkin.SetAttachment(gunSlotIndex, gunKey, newGun);                             // STEP 1.4
            }
            // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item.
            // customSkin.Clear()
            // Use skin.Clear() To remove all customizations.
            // Customizations will fall back to the value in the default skin if it was defined there.
            // To prevent fallback from happening, make sure the key is not defined in the default skin.

            // STEP 3: APPLY AND CLEAN UP.
            // Recommended: REPACK THE CUSTOM SKIN TO MINIMIZE DRAW CALLS
            //              Repacking requires that you set all source textures/sprites/atlases to be Read/Write enabled in the inspector.
            //              Combine all the attachment sources into one skin. Usually this means the default skin and the custom skin.
            //              call Skin.GetRepackedSkin to get a cloned skin with cloned attachments that all use one texture.
            if (repack)
            {
                var repackedSkin = new Skin("repacked skin");
                repackedSkin.AddAttachments(skeleton.Data.DefaultSkin);
                repackedSkin.AddAttachments(customSkin);
                // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed
                if (runtimeMaterial)
                {
                    Destroy(runtimeMaterial);
                }
                if (runtimeAtlas)
                {
                    Destroy(runtimeAtlas);
                }
                repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
                skeleton.SetSkin(repackedSkin);
            }
            else
            {
                skeleton.SetSkin(customSkin);
            }

            //skeleton.SetSlotsToSetupPose();
            skeleton.SetToSetupPose();
            skeletonGraphic.Update(0);
            skeletonGraphic.OverrideTexture = runtimeAtlas;

            // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true`
            // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache().
            // You can optionally clear the textures cache after multiple repack operations.
            // Just be aware that while this cleanup frees up memory, it is also a costly operation
            // and will likely cause a spike in the framerate.
            AtlasUtilities.ClearCache();
            Resources.UnloadUnusedAssets();
        }
Ejemplo n.º 7
0
    public void ChracterEquipSetting(bool isStart, int equipIndex, int equipNumber)
    {
        switch (equipIndex)
        {
        case 0:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("weapon/weapon{0}", string.Format("{0:D3}", equipNumber))));
            characterWEaponEffect.ChangeWeaponEffect(equipNumber - 1);
            break;

        case 1:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("hat/hat{0}", string.Format("{0:D3}", equipNumber))));
            if (equipNumber != 24 &&
                equipNumber != 19 &&
                equipNumber != 25)
            {
                baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("hatback"), "hatback");
            }
            break;

        case 2:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("body/body{0}", string.Format("{0:D3}", equipNumber))));
            break;

        case 3:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("hand/hand{0}", string.Format("{0:D3}", equipNumber))));
            break;

        case 4:
            //Slot slot = skeletonAnimation.Skeleton.FindSlot("hip");
            baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("hip"), "hip");
            baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("hip_front1"), "hip_front1");
            baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("hip_front2"), "hip_front2");
            baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("hip_front3"), "hip_front3");
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("hip/hip{0}", string.Format("{0:D3}", equipNumber))));
            //skeletonAnimation.Skeleton.SetAttachment(slot.ToString(), string.Format("skin/skin{0}/hip_front3", string.Format("{0:D3}", equipNumber + 1)));
            //baseSkin.SetAttachment(0, string.Format("hip/hip{0}", string.Format("{0:D3}", equipNumber + 1)), baseSkin.GetAttachment(0, "hip"));
            break;

        case 5:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("shoes/shoes{0}", string.Format("{0:D3}", equipNumber))));
            break;

        case 6:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("cape/cape{0}", string.Format("{0:D3}", equipNumber))));
            if (equipNumber != 21)
            {
                baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("wing1"), "wing1");
                baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("wing2"), "wing2");
            }
            else
            {
                baseSkin.RemoveAttachment(skeletonAnimation.Skeleton.FindSlotIndex("cape_back"), "cape_back");
            }

            break;

        case 7:
            baseSkin.AddAttachments(skeleton.Data.FindSkin(string.Format("face/face{0}", string.Format("{0:D3}", equipNumber))));

            break;

        default:
            break;
        }
        skeleton.SetSkin(baseSkin);
        skeleton.SetSlotsToSetupPose();
        skeletonAnimation.AnimationState.Apply(skeleton);
        //나중에 여기서 저장.
    }