Ejemplo n.º 1
0
 public static Quaternion getAttachmentRotation(SpineSkinAttachment spineSkinAttachment, bool rotated = false)
 {
     if (rotated)
     {
         return(Quaternion.Euler(0.0f, 0.0f, (float)spineSkinAttachment.rotation - 90.0f));
     }
     else
     {
         return(Quaternion.Euler(0.0f, 0.0f, (float)spineSkinAttachment.rotation));
     }
 }
Ejemplo n.º 2
0
 static void fixeAttachmentNamesIfOmited(SpineData data)
 {
     foreach (KeyValuePair <string, SpineSkinSlots> kvp in data.skins)
     {
         string skinName = kvp.Key;
         foreach (KeyValuePair <string, SpineSkinSlotAttachments> kvp2 in  data.skins[skinName])
         {
             string slotName = kvp2.Key;
             foreach (KeyValuePair <string, SpineSkinAttachment> kvp3 in data.skins[skinName][slotName])
             {
                 string attachmentName          = kvp3.Key;
                 SpineSkinAttachment attachment = kvp3.Value;
                 if (string.IsNullOrEmpty(attachment.name))
                 {
                     attachment.name = attachmentName;                             // we set actualAttachment(sprite name) here in case if it empty it equal to attachment name
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public static void addAllAttahcmentsSlots(SpineData spineData, SpritesByName spriteByName, Dictionary <string, Slot> slotByName, float zStep, int pixelsPerUnit, out List <Skin> skins, out AttachmentGOByNameBySlot attachmentGOByNameBySlot)
        {
            float ratio = 1.0f / (float)pixelsPerUnit;

            skins = new List <Skin>();
            attachmentGOByNameBySlot = new AttachmentGOByNameBySlot();
            foreach (KeyValuePair <string, SpineSkinSlots> kvp in spineData.skins)
            {
                string skinName = kvp.Key;
                Skin   skin     = new Skin();
                skin.name = skinName;
                List <SkinSlot> slotList = new List <SkinSlot>();

                bool isDefault = skinName.Equals("default");
                foreach (KeyValuePair <string, SpineSkinSlotAttachments> kvp2 in  spineData.skins[skinName])
                {
                    string     slotName = kvp2.Key;
                    GameObject slotGO   = slotByName[slotName].gameObject;

                    Slot slot = slotByName[slotName];



                    SkinSlot skinSlot = new SkinSlot();
                    skinSlot.name       = slotName;
                    skinSlot.gameObject = slotGO;
                    List <SkinSlotAttachment> attachmentList = new List <SkinSlotAttachment>();
                    foreach (KeyValuePair <string, SpineSkinAttachment> kvp3 in spineData.skins[skinName][slotName])
                    {
                        string             attachmenName = kvp3.Key;
                        SkinSlotAttachment attachment    = new SkinSlotAttachment();
                        attachment.name = attachmenName;

                        SpineSkinAttachment spineAttachment = kvp3.Value;

                        // - create skined object or direct GO for default skin
                        Sprite sprite;
                        spriteByName.TryGetValue(spineAttachment.name, out sprite);
                        int drawOrder = spineData.slotOrder[slotName];

                        GameObject parentGO;
                        GameObject spriteGO;
                        string     fixedName = attachmenName.Replace("/", SLASH_REPLACEMENT);
                        if (isDefault)
                        {
                            parentGO = slotGO;
                            spriteGO = new GameObject(fixedName);
                            Attachment a = new Attachment(attachmenName, AttachmentType.SINGLE_SPRITE, spriteGO);
                            slot.addAttachment(a);
                        }
                        else
                        {
                            spriteGO = new GameObject(skinName);
                            Attachment a;
                            slot.attachmentByName.TryGetValue(attachmenName, out a);
                            if (a == null)
                            {
                                GameObject attachmentGO = new GameObject(fixedName);
                                attachmentGO.transform.parent = slotGO.transform;
                                resetLocalTRS(attachmentGO);
                                a = new Attachment(attachmenName, AttachmentType.SKINED_SPRITE, attachmentGO);
                                slot.addAttachment(a);
                            }

                            parentGO = a.gameObject;
                        }

                        attachment.gameObject     = spriteGO;
                        spriteGO.transform.parent = parentGO.gameObject.transform;
                        // -
                        if (spineAttachment.type.Equals("region"))
                        {
                            SpriteRenderer sr = spriteGO.AddComponent <SpriteRenderer>();
                            sr.sprite = sprite;
                            spriteGO.transform.localPosition = getAttachmentPosition(spineAttachment, ratio, -(drawOrder * zStep));
                            spriteGO.transform.localRotation = getAttachmentRotation(spineAttachment, spriteByName.rotatedSprites.Contains(sprite));
                            spriteGO.transform.localScale    = getAttachmentScale(spineAttachment);
                        }
                        else if (spineAttachment.type.Equals("boundingbox"))
                        {
                            PolygonCollider2D collider = spriteGO.AddComponent <PolygonCollider2D>();
                            resetLocalTRS(spriteGO);
                            Vector2[] vertices = new Vector2[spineAttachment.vertices.Length / 2];
                            for (int i = 0; i < spineAttachment.vertices.Length; i += 2)
                            {
                                float x = (float)spineAttachment.vertices[i] * ratio;
                                float y = (float)spineAttachment.vertices[i + 1] * ratio;
                                vertices[i / 2] = new Vector2(x, y);
                            }
                            collider.points = vertices;
                            collider.SetPath(0, vertices);
                        }
                        else
                        {
                            Debug.LogWarning("Attachment type " + spineAttachment.type + " is not supported yiet FIX MEEE");
                        }
                        attachmentList.Add(attachment);
                    }
                    skinSlot.attachments = attachmentList.ToArray();
                    slotList.Add(skinSlot);
                }
                skin.slots = slotList.ToArray();
                skins.Add(skin);
            }
        }
Ejemplo n.º 4
0
 public static Vector3 getAttachmentScale(SpineSkinAttachment spineSkinAttachment)
 {
     return(new Vector3((float)spineSkinAttachment.scaleX, (float)spineSkinAttachment.scaleY, 1.0f));
 }
Ejemplo n.º 5
0
 public static Vector3 getAttachmentPosition(SpineSkinAttachment spineSkinAttachment, float ratio, float z)
 {
     return(new Vector3((float)spineSkinAttachment.x * ratio, (float)spineSkinAttachment.y * ratio, z));
 }
Ejemplo n.º 6
0
 public static Vector3 getAttachmentScale(SpineSkinAttachment spineSkinAttachment)
 {
     return new Vector3((float)spineSkinAttachment.scaleX, (float)spineSkinAttachment.scaleY, 1.0f);
 }
Ejemplo n.º 7
0
 public static Quaternion getAttachmentRotation(SpineSkinAttachment spineSkinAttachment, bool rotated = false)
 {
     if (rotated)
         return Quaternion.Euler(0.0f, 0.0f, (float)spineSkinAttachment.rotation - 90.0f);
     else
         return Quaternion.Euler(0.0f, 0.0f, (float)spineSkinAttachment.rotation);
 }
Ejemplo n.º 8
0
 public static Vector3 getAttachmentPosition(SpineSkinAttachment spineSkinAttachment, float ratio, float z)
 {
     return new Vector3((float)spineSkinAttachment.x * ratio, (float)spineSkinAttachment.y * ratio, z);
 }