public static Attachment GetAttachment(string attachmentPath, SkeletonData skeletonData)
 {
     SpineAttachment.Hierarchy hierarchy = SpineAttachment.GetHierarchy(attachmentPath);
     if (hierarchy.name == string.Empty)
     {
         return(null);
     }
     return(skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name));
 }
        public static Attachment AddUnitySprite(this SkeletonData skeletonData, string slotName, UnityEngine.Sprite sprite, string skinName, Shader shader, bool applyPMA)
        {
            RegionAttachment regionAttachment = sprite.ToRegionAttachment(shader, applyPMA);
            int  slotIndex = skeletonData.FindSlotIndex(slotName);
            Skin skin      = skeletonData.defaultSkin;

            if (skinName != string.Empty)
            {
                skin = skeletonData.FindSkin(skinName);
            }
            skin.AddAttachment(slotIndex, regionAttachment.Name, regionAttachment);
            return(regionAttachment);
        }
    public static Attachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName = "", string shaderName = "Spine/Skeleton")
    {
        RegionAttachment regionAttachment = sprite.ToRegionAttachment(shaderName);
        int  slotIndex = skeletonData.FindSlotIndex(slotName);
        Skin skin      = skeletonData.defaultSkin;

        if (skinName != string.Empty)
        {
            skin = skeletonData.FindSkin(skinName);
        }
        skin.AddAttachment(slotIndex, regionAttachment.Name, regionAttachment);
        return(regionAttachment);
    }
Beispiel #4
0
        public static RegionAttachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName, Shader shader, bool applyPMA, float rotation = 0f)
        {
            RegionAttachment attachment = !applyPMA?sprite.ToRegionAttachment(new Material(shader), rotation) : sprite.ToRegionAttachmentPMAClone(shader, TextureFormat.RGBA32, false, null, rotation);

            int  slotIndex   = skeletonData.FindSlotIndex(slotName);
            Skin defaultSkin = skeletonData.DefaultSkin;

            if (skinName != string.Empty)
            {
                defaultSkin = skeletonData.FindSkin(skinName);
            }
            defaultSkin.AddAttachment(slotIndex, attachment.Name, attachment);
            return(attachment);
        }
Beispiel #5
0
        public static void RemoveAttachment(this Skin skin, string slotName, string keyName, SkeletonData skeletonData)
        {
            int slotIndex = skeletonData.FindSlotIndex(slotName);

            if (skeletonData == null)
            {
                throw new System.ArgumentNullException("skeletonData", "skeletonData cannot be null.");
            }
            if (slotIndex == -1)
            {
                throw new System.ArgumentException(string.Format("Slot '{0}' does not exist in skeleton.", slotName), "slotName");
            }
            skin.RemoveAttachment(slotIndex, keyName);
        }
    public static Attachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName = "", string shaderName = "Spine/Skeleton")
    {
        var att = sprite.ToRegionAttachment(shaderName);

        var  slotIndex = skeletonData.FindSlotIndex(slotName);
        Skin skin      = skeletonData.defaultSkin;

        if (skinName != "")
        {
            skin = skeletonData.FindSkin(skinName);
        }

        skin.AddAttachment(slotIndex, att.Name, att);

        return(att);
    }
Beispiel #7
0
        public static RegionAttachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName, Shader shader, bool applyPMA)
        {
            RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentPMAClone(shader) : sprite.ToRegionAttachment(new Material(shader));

            var  slotIndex = skeletonData.FindSlotIndex(slotName);
            Skin skin      = skeletonData.DefaultSkin;

            if (skinName != "")
            {
                skin = skeletonData.FindSkin(skinName);
            }

            skin.AddAttachment(slotIndex, att.Name, att);

            return(att);
        }
Beispiel #8
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);
        }
        private void ReadSkeletonSkins(SkeletonData skeletonData, JObject data, float scale)
        {
            foreach (JProperty skin in data["skins"])
            {
                var skeletonSkin = new Skin(skin.Name);

                foreach (JProperty slot in skin.Value)
                {
                    int slotIndex = skeletonData.FindSlotIndex(slot.Name);

                    foreach (JProperty attachment in slot.Value)
                    {
                        Attachment skeletonAttachment = ReadSkeletonAttachment(attachment.Name, attachment.Value, scale);
                        if (attachment != null)
                        {
                            skeletonSkin.AddAttachment(slotIndex, attachment.Name, skeletonAttachment);
                        }
                    }
                }

                skeletonData.AddSkin(skeletonSkin);
                if (skeletonSkin.Name.Equals("default"))
                {
                    skeletonData.DefaultSkin = skeletonSkin;
                }
            }
        }
        private List<ITimeline> ReadAnimationSlots(SkeletonData skeletonData, JObject data)
        {
            var timelines = new List<ITimeline>();

            JToken dataSlots = data["slots"];

            if (dataSlots != null)
            {
                foreach (JProperty jsonSlot in dataSlots)
                {
                    int slotIndex = skeletonData.FindSlotIndex(jsonSlot.Name);

                    foreach (JProperty jsonTimelineType in jsonSlot.Value)
                    {
                        var jsonTimelineList = (JArray) jsonTimelineType.Value;

                        ITimeline timeline;

                        switch (jsonTimelineType.Name)
                        {
                            case TIMELINE_COLOR:

                                timeline = ReadAnimationColorTimeline(jsonTimelineList, slotIndex);
                                break;

                            case TIMELINE_ATTACHMENT:
                                timeline = ReadAnimationAttachmentTimeline(jsonTimelineList, slotIndex);
                                break;

                            default:
                                throw new Exception("Invalid timeline type for a slot: " + jsonTimelineType.Name + " (" + jsonSlot.Name + ")");
                        }

                        timelines.Add(timeline);
                    }
                }
            }

            return timelines;
        }