Exemplo n.º 1
0
 private static void ParseEvents(SpineArmatureEditor armatureEditor, Bones2D.JSONClass armtureObj)
 {
     if (armtureObj.ContainKey("events"))
     {
         Bones2D.JSONClass eventsObj = armtureObj["events"].AsObject;
         foreach (string name in eventsObj.GetKeys())
         {
             Bones2D.JSONClass evtObj  = eventsObj[name].AsObject;
             EventData         evtData = new EventData();
             if (evtObj.ContainKey("string"))
             {
                 evtData.stringParam = evtObj["string"].ToString();
             }
             if (evtObj.ContainKey("int"))
             {
                 evtData.intParam = evtObj["int"].AsInt;
             }
             if (evtObj.ContainKey("float"))
             {
                 evtData.floatParam = evtObj["float"].AsFloat;
             }
             eventPoseKV[name] = evtData;
         }
     }
 }
Exemplo n.º 2
0
        private static List <SpineData.AnimationBoneData> ParseAnimBones(SpineArmatureEditor armatureEditor, Bones2D.JSONClass bonesObj)
        {
            List <SpineData.AnimationBoneData> animationBoneDatas = new List <SpineData.AnimationBoneData>();

            foreach (string boneName in bonesObj.GetKeys())
            {
                Bones2D.JSONClass bonesAnimObj = bonesObj[boneName].AsObject;
                if (bonesAnimObj.ContainKey("rotate"))
                {
                    animationBoneDatas.Add(ParseBoneAnimTimeline(armatureEditor, boneName, bonesAnimObj, "rotate"));
                }
                if (bonesAnimObj.ContainKey("translate"))
                {
                    animationBoneDatas.Add(ParseBoneAnimTimeline(armatureEditor, boneName, bonesAnimObj, "translate"));
                }
                if (bonesAnimObj.ContainKey("scale"))
                {
                    animationBoneDatas.Add(ParseBoneAnimTimeline(armatureEditor, boneName, bonesAnimObj, "scale"));
                }
                if (bonesAnimObj.ContainKey("shear"))
                {
                    animationBoneDatas.Add(ParseBoneAnimTimeline(armatureEditor, boneName, bonesAnimObj, "shear"));
                }
            }
            return(animationBoneDatas);
        }
Exemplo n.º 3
0
        private static void ParseAnimations(SpineArmatureEditor armatureEditor, Bones2D.JSONClass armtureObj)
        {
            if (armtureObj.ContainKey("animations"))
            {
                Bones2D.JSONClass anims = armtureObj["animations"].AsObject;
                List <SpineData.AnimationData> animList = new List <SpineData.AnimationData>();
                foreach (string animName in anims.GetKeys())
                {
                    SpineData.AnimationData animData = new SpineData.AnimationData();
                    animData.name = animName;
                    animList.Add(animData);

                    Bones2D.JSONClass animObj = anims[animName].AsObject;
                    if (animObj.ContainKey("bones"))
                    {
                        Bones2D.JSONClass bonesObj = animObj["bones"].AsObject;
                        animData.boneAnims = ParseAnimBones(armatureEditor, bonesObj).ToArray();
                    }
                    if (animObj.ContainKey("slots"))
                    {
                        Bones2D.JSONClass slotsObj = animObj["slots"].AsObject;
                        animData.slotAnims = ParseAnimSlots(slotsObj).ToArray();
                    }
                    if (animObj.ContainKey("ik"))
                    {
                    }
                    if (animObj.ContainKey("deform"))
                    {
                        Bones2D.JSONClass deformObj = animObj["deform"].AsObject;
                        animData.deforms = ParseAnimDeform(armatureEditor, deformObj).ToArray();
                    }
                    else if (animObj.ContainKey("ffd"))
                    {
                        Bones2D.JSONClass deformObj = animObj["ffd"].AsObject;
                        animData.deforms = ParseAnimDeform(armatureEditor, deformObj).ToArray();
                    }
                    if (animObj.ContainKey("events"))
                    {
                        Bones2D.JSONArray eventsArray = animObj["events"].AsArray;
                        animData.events = ParseAnimEvents(eventsArray).ToArray();
                    }
                    if (animObj.ContainKey("drawOrder"))
                    {
                        Bones2D.JSONArray drawOrderArray = animObj["drawOrder"].AsArray;
                        animData.drawOrders = ParseDrawOrders(armatureEditor, drawOrderArray).ToArray();
                    }
                    else if (animObj.ContainKey("draworder"))
                    {
                        Bones2D.JSONArray drawOrderArray = animObj["draworder"].AsArray;
                        animData.drawOrders = ParseDrawOrders(armatureEditor, drawOrderArray).ToArray();
                    }
                }
                armatureEditor.armatureData.animations = animList.ToArray();
            }
        }
Exemplo n.º 4
0
        private static List <SpineData.AnimationSlotData> ParseAnimSlots(Bones2D.JSONClass slotsObj)
        {
            List <SpineData.AnimationSlotData> animationSlotDatas = new List <SpineData.AnimationSlotData>();

            foreach (string slotName in slotsObj.GetKeys())
            {
                Bones2D.JSONClass slotAnimObj = slotsObj[slotName].AsObject;
                if (slotAnimObj.ContainKey("attachment"))
                {
                    animationSlotDatas.Add(ParseSlotAnimTimeline(slotName, slotAnimObj, "attachment"));
                }
                if (slotAnimObj.ContainKey("color"))
                {
                    animationSlotDatas.Add(ParseSlotAnimTimeline(slotName, slotAnimObj, "color"));
                }
            }
            return(animationSlotDatas);
        }
Exemplo n.º 5
0
        private static List <SpineData.AnimationDeformData> ParseAnimDeform(SpineArmatureEditor armatureEditor, Bones2D.JSONClass deformObj)
        {
            List <SpineData.AnimationDeformData> animationDeformDatas = new List <SpineData.AnimationDeformData>();

            foreach (string skinName in deformObj.GetKeys())
            {
                Bones2D.JSONClass skinObj = deformObj[skinName].AsObject;
                foreach (string slotName in skinObj.GetKeys())
                {
                    Bones2D.JSONClass slotObj = skinObj[slotName].AsObject;
                    foreach (string attachmentName in slotObj.GetKeys())
                    {
                        animationDeformDatas.Add(ParseDeformAnimTimeline(armatureEditor, skinName, slotName, attachmentName, slotObj[attachmentName].AsArray));
                    }
                }
            }
            return(animationDeformDatas);
        }
Exemplo n.º 6
0
 private static void ParseSkins(SpineArmatureEditor armatureEditor, Bones2D.JSONClass armtureObj)
 {
     if (armtureObj.ContainKey("skins"))
     {
         Bones2D.JSONClass    skins     = armtureObj["skins"].AsObject;
         SpineData.SkinData[] skinDatas = new SpineData.SkinData[skins.Count];
         armatureEditor.armatureData.skins = skinDatas;
         int      skinDataCount = 0;
         string[] skinNames     = new string[skins.Count];
         foreach (string skinName in skins.GetKeys())
         {
             Bones2D.JSONClass  skinSlots = skins[skinName].AsObject;
             SpineData.SkinData skinData  = new SpineData.SkinData();
             skinDatas[skinDataCount] = skinData;
             skinData.skinName        = skinName;
             skinNames[skinDataCount] = skinName;
             skinData.slots           = new Dictionary <string, List <SpineData.SkinAttachment> >();
             foreach (string slotName in skinSlots.GetKeys())
             {
                 Bones2D.JSONClass skinAttments = skinSlots[slotName].AsObject;
                 skinData.slots[slotName] = new List <SpineData.SkinAttachment>();
                 foreach (string attachmentName in skinAttments.GetKeys())
                 {
                     Bones2D.JSONClass        attachmentObj = skinAttments[attachmentName].AsObject;
                     SpineData.SkinAttachment attachment    = new SpineData.SkinAttachment();
                     attachment.name = attachmentName;
                     if (attachmentObj.ContainKey("name"))
                     {
                         attachment.realName = attachmentObj["name"].ToString();
                     }
                     else
                     {
                         attachment.realName = attachmentName;
                     }
                     if (attachmentObj.ContainKey("path"))
                     {
                         attachment.textureName = attachmentObj["path"].ToString();
                     }
                     else
                     {
                         attachment.textureName = attachment.realName;
                     }
                     if (attachmentObj.ContainKey("type"))
                     {
                         attachment.type = attachmentObj["type"].ToString();                                                             //region,mesh,linkedmesh,boundingbox,path
                     }
                     if (attachment.type == "path" || attachment.type == "linkedmesh")
                     {
                         continue;
                     }
                     skinData.slots[slotName].Add(attachment);
                     if (attachmentObj.ContainKey("x"))
                     {
                         attachment.x = attachmentObj["x"].AsFloat * armatureEditor.unit;
                     }
                     if (attachmentObj.ContainKey("y"))
                     {
                         attachment.y = attachmentObj["y"].AsFloat * armatureEditor.unit;
                     }
                     if (attachmentObj.ContainKey("scaleX"))
                     {
                         attachment.scaleX = attachmentObj["scaleX"].AsFloat;
                     }
                     if (attachmentObj.ContainKey("scaleY"))
                     {
                         attachment.scaleY = attachmentObj["scaleY"].AsFloat;
                     }
                     if (attachmentObj.ContainKey("width"))
                     {
                         attachment.width = attachmentObj["width"].AsFloat;
                     }
                     if (attachmentObj.ContainKey("height"))
                     {
                         attachment.height = attachmentObj["height"].AsFloat;
                     }
                     if (attachmentObj.ContainKey("rotation"))
                     {
                         attachment.rotation = attachmentObj["rotation"].AsFloat;
                     }
                     if (attachmentObj.ContainKey("color"))
                     {
                         attachment.color = SpineArmatureEditor.HexToColor(attachmentObj["color"].ToString());
                     }
                     if (attachmentObj.ContainKey("hull"))
                     {
                         attachment.hull = attachmentObj["hull"].AsInt;
                     }
                     if (attachmentObj.ContainKey("uvs"))
                     {
                         Bones2D.JSONArray uvsObj = attachmentObj["uvs"].AsArray;
                         attachment.uvs = new Vector2[uvsObj.Count / 2];
                         for (int z = 0; z < uvsObj.Count; z += 2)
                         {
                             Vector2 uv = new Vector2(uvsObj[z].AsFloat, 1 - uvsObj[z + 1].AsFloat);
                             attachment.uvs[z / 2] = uv;
                         }
                     }
                     //triangles
                     if (attachmentObj.ContainKey("triangles"))
                     {
                         Bones2D.JSONArray trianglesObj = attachmentObj["triangles"].AsArray;
                         attachment.triangles = new int[trianglesObj.Count];
                         for (int z = 0; z < trianglesObj.Count; z++)
                         {
                             attachment.triangles[z] = trianglesObj[z].AsInt;
                         }
                     }
                     //vertex
                     if (attachmentObj.ContainKey("vertices"))
                     {
                         Bones2D.JSONArray verticesObj = attachmentObj["vertices"].AsArray;
                         if (attachment.uvs != null && verticesObj.Count > attachment.uvs.Length * 2)
                         {
                             //have weighted
                             List <float> weights = new List <float>();
                             for (int i = 0; i < verticesObj.Count; ++i)
                             {
                                 int boneCount = verticesObj[i].AsInt;
                                 weights.Add(boneCount);
                                 for (int j = 0; j < boneCount * 4; j += 4)
                                 {
                                     weights.Add(verticesObj[i + j + 1].AsInt);                                        //bone index
                                     weights.Add(verticesObj[i + j + 2].AsFloat * armatureEditor.unit);                //relativeBoneX
                                     weights.Add(verticesObj[i + j + 3].AsFloat * armatureEditor.unit);                //relativeBoneY
                                     weights.Add(verticesObj[i + j + 4].AsFloat);                                      //weight
                                 }
                                 i += boneCount * 4;
                             }
                             attachment.weights = weights;
                         }
                         else
                         {
                             //only vertices
                             attachment.vertices = new Vector3[verticesObj.Count / 2];
                             for (int i = 0; i < verticesObj.Count; i += 2)
                             {
                                 Vector3 vertex = new Vector3(verticesObj[i].AsFloat, verticesObj[i + 1].AsFloat, 0f);
                                 vertex.x *= armatureEditor.unit;
                                 vertex.y *= armatureEditor.unit;
                                 attachment.vertices[i / 2] = vertex;
                             }
                         }
                     }
                     //edges
                     if (armatureEditor.genMeshCollider && attachmentObj.ContainKey("edges"))
                     {
                         Bones2D.JSONArray edgesObj = attachmentObj["edges"].AsArray;
                         int        len             = edgesObj.Count;
                         List <int> edges           = new List <int>();
                         for (int z = 0; z < len; ++z)
                         {
                             int value = edgesObj[z].AsInt / 2;
                             if (edges.Count > 0)
                             {
                                 if (edges[edges.Count - 1] != value)
                                 {
                                     edges.Add(value);
                                 }
                             }
                             else
                             {
                                 edges.Add(value);
                             }
                         }
                         if (edges.Count > 2 && edges[0] == edges[edges.Count - 1])
                         {
                             edges.RemoveAt(edges.Count - 1);
                         }
                         if (edges.Count > 2)
                         {
                             attachment.edges = edges.ToArray();
                         }
                     }
                 }
             }
             ++skinDataCount;
         }
         armatureEditor.armature.GetComponent <Armature>().skins = skinNames;
     }
 }