public void OptimizeSkin()
        {
            // 1. Collect all the attachments of all active skins.
            collectedSkin = collectedSkin ?? new Skin("Collected skin");
            collectedSkin.Clear();
            collectedSkin.AddSkin(skeletonAnimation.Skeleton.Data.DefaultSkin);
            collectedSkin.AddSkin(equipsSkin);

            // 2. Create a repacked skin.
            // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed
            if (runtimeMaterial)
            {
                Destroy(runtimeMaterial);
            }
            if (runtimeAtlas)
            {
                Destroy(runtimeAtlas);
            }
            var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial,
                                                             out runtimeMaterial, out runtimeAtlas, maxAtlasSize: 1024, clearCache: false);

            collectedSkin.Clear();

            // You can optionally clear the textures cache after each ore multiple repack operations are done.
            //AtlasUtilities.ClearCache();
            //Resources.UnloadUnusedAssets();

            // 3. Use the repacked skin.
            skeletonAnimation.Skeleton.Skin = repackedSkin;
            RefreshSkeletonAttachments();
        }
 public void SetSkin(Spine.Skin newSkin)
 {
     if (newSkin != null)
     {
         if (this.skin != null)
         {
             newSkin.AttachAll(this, this.skin);
         }
         else
         {
             ExposedList <Slot> slots = this.slots;
             int index = 0;
             int count = slots.Count;
             while (index < count)
             {
                 Slot   slot           = slots.Items[index];
                 string attachmentName = slot.data.attachmentName;
                 if (attachmentName != null)
                 {
                     Attachment attachment = newSkin.GetAttachment(index, attachmentName);
                     if (attachment != null)
                     {
                         slot.Attachment = attachment;
                     }
                 }
                 index++;
             }
         }
     }
     this.skin = newSkin;
 }
        public void OptimizeSkin()
        {
            // 1. Collect all the attachments of all active skins.
            collectedSkin = collectedSkin ?? new Skin("Collected skin");
            collectedSkin.Clear();
            collectedSkin.AddAttachments(skeletonAnimation.Skeleton.Data.DefaultSkin);
            collectedSkin.AddAttachments(equipsSkin);

            // 2. Create a repacked skin.
            // Note: materials and textures returned by GetRepackedSkin() behave like 'new Texture2D()' and need to be destroyed
            if (runtimeMaterial)
            {
                Destroy(runtimeMaterial);
            }
            if (runtimeAtlas)
            {
                Destroy(runtimeAtlas);
            }
            var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas);

            collectedSkin.Clear();

            // 3. Use the repacked skin.
            skeletonAnimation.Skeleton.Skin = repackedSkin;
            RefreshSkeletonAttachments();
        }
 public void SetSkin(string skinName)
 {
     Spine.Skin newSkin = this.data.FindSkin(skinName);
     if (newSkin == null)
     {
         throw new ArgumentException("Skin not found: " + skinName, "skinName");
     }
     this.SetSkin(newSkin);
 }
 private void SortPathConstraintAttachment(Spine.Skin skin, int slotIndex, Bone slotBone)
 {
     foreach (KeyValuePair <Spine.Skin.AttachmentKeyTuple, Attachment> pair in skin.Attachments)
     {
         if (pair.Key.slotIndex == slotIndex)
         {
             this.SortPathConstraintAttachment(pair.Value, slotBone);
         }
     }
 }
        void Start()
        {
            equipsSkin = new Skin("Equips");

            // OPTIONAL: Add all the attachments from the template skin.
            var templateSkin = skeletonAnimation.Skeleton.Data.FindSkin(templateSkinName);

            if (templateSkin != null)
            {
                equipsSkin.AddSkin(templateSkin);
            }

            skeletonAnimation.Skeleton.Skin = equipsSkin;
            RefreshSkeletonAttachments();
        }
Exemple #7
0
        public void OptimizeSkin()
        {
            // 1. Collect all the attachments of all active skins.
            collectedSkin = collectedSkin ?? new Skin("Collected skin");
            collectedSkin.Clear();
            collectedSkin.AddAttachments(skeletonAnimation.Skeleton.Data.DefaultSkin);
            collectedSkin.AddAttachments(equipsSkin);

            // 2. Create a repacked skin.
            var repackedSkin = collectedSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas);

            collectedSkin.Clear();

            // 3. Use the repacked skin.
            skeletonAnimation.Skeleton.Skin = repackedSkin;
            RefreshSkeletonAttachments();
        }
Exemple #8
0
        public MixAndMatchScreen(Example game) : base(game)
        {
            atlas = new Atlas("data/mix-and-match.atlas", new XnaTextureLoader(game.GraphicsDevice));

            SkeletonJson json = new SkeletonJson(atlas);

            json.Scale = 0.5f;
            SkeletonData skeletonData = json.ReadSkeletonData("data/mix-and-match-pro.json");

            skeleton = new Skeleton(skeletonData);
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            skeleton.X = game.GraphicsDevice.Viewport.Width / 2;
            skeleton.Y = game.GraphicsDevice.Viewport.Height;

            state.SetAnimation(0, "dance", true);

            // Create a new skin, by mixing and matching other skins
            // that fit together. Items making up the girl are individual
            // skins. Using the skin API, a new skin is created which is
            // a combination of all these individual item skins.
            var mixAndMatchSkin = new Spine.Skin("custom-girl");

            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("skin-base"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("nose/short"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyelids/girly"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyes/violet"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("hair/brown"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("legs/pants-jeans"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/bag"));
            mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow"));
            skeleton.SetSkin(mixAndMatchSkin);
        }