Ejemplo n.º 1
0
        public BoneElement GetBoneElement(string boneName)
        {
            BoneElement element = null;

            dicBones.TryGetValue(boneName, out element);
            return(element);
        }
Ejemplo n.º 2
0
        public string GetFullPathBone(string boneName)
        {
            Dictionary <string, BoneElement> dic = dicBones;
            string      path = "";
            BoneElement bone = null;

            if (dic.TryGetValue(boneName, out bone))
            {
                while (true)
                {
                    if (bone.parent == null)
                    {
                        path += "";
                        break;
                    }
                    else
                    {
                        if (path.Length < 1)
                        {
                            path = bone.name;
                        }
                        else
                        {
                            path = bone.name + "/" + path;
                        }
                        if (!dic.TryGetValue(bone.parent, out bone))
                        {
                            break;
                        }
                    }
                }
            }
            return(path);
        }
Ejemplo n.º 3
0
        public AEPJsonFinal(RawAEPJson raw)
        {
            #region Generate Bones Info
            this.bones = raw.bones;
            dicBones   = new Dictionary <string, BoneElement>();
            for (int i = 0; i < bones.Count; i++)
            {
                //bones[i].index=i;
                dicBones[bones[i].name] = bones[i];
            }
            #endregion

            #region attactment
            Dictionary <string, bool> dicAttact = new Dictionary <string, bool> ();
            if (raw.animations != null && raw.animations.animation != null)
            {
                foreach (KeyValuePair <string, object> pair1 in raw.animations.animation)
                {
                    if (pair1.Key == "bones")                 // tam thoi chi su ly cho bone
                    {
                        Dictionary <string, object> temp1 = (Dictionary <string, object>)pair1.Value;

                        foreach (KeyValuePair <string, object> pair2 in temp1)
                        {
                            //Debug.LogError(Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(pair2.Value));
                            AEPBoneAnimationElement full = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize(
                                Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(pair2.Value), typeof(AEPBoneAnimationElement)) as AEPBoneAnimationElement;
                            full.name = pair2.Key;
                            dicAnimation[full.name] = full;
                        }
                        //Debug.LogError(Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(dicAnimation));
                    }
                    else if (pair1.Key == "slots")                 // attachment object
                    {
                        Dictionary <string, object> temp1 = (Dictionary <string, object>)pair1.Value;

                        foreach (KeyValuePair <string, object> pair2 in temp1)
                        {
                            AEPSlotAnimationElement slotAnim = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize(
                                Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(pair2.Value), typeof(AEPSlotAnimationElement)) as AEPSlotAnimationElement;
                            slotAnim.name = pair2.Key;
                            if (slotAnim.attachment != null)
                            {
                                for (int yy = 0; yy < slotAnim.attachment.Count; yy++)
                                {
                                    string finalName = slotAnim.attachment[yy].name;
                                    if (!string.IsNullOrEmpty(finalName))
                                    {
                                        int index = finalName.LastIndexOf("/");
                                        finalName = finalName.Substring(index + 1, finalName.Length - index - 1);
                                    }
                                    slotAnim.attachment[yy].name = finalName;
                                }
                                dicAttact[slotAnim.name] = true;
                            }
                            dicSlotAttactment[slotAnim.name] = slotAnim;
                        }
                        //Debug.LogError(Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(dicSlotAttactment));
                    }
                }
            }
            #endregion

            #region generate Slots Info
            this.slots = raw.slots;
            if (this.slots == null)
            {
                this.slots = new List <SlotElelement>();
            }
            dicSlots = new Dictionary <string, SlotElelement>();
            for (int i = 0; i < slots.Count; i++)
            {
                string slotAttachmentName = slots[i].attachment;
                if (slotAttachmentName == null)
                {
                    if (dicAttact.ContainsKey(slots[i].name))
                    {
                        slotAttachmentName = "";
                    }
                }
                if (slotAttachmentName != null)
                {
                    //Debug.LogError(slotAttachmentName);
                    int index = slotAttachmentName.LastIndexOf("/");
                    slotAttachmentName           = slotAttachmentName.Substring(index + 1, slotAttachmentName.Length - index - 1);
                    slots[i].attachment          = slotAttachmentName;
                    slots[i].index               = slots.Count - i;
                    this.dicSlots[slots[i].name] = slots[i];

                    BoneElement boneTemp = null;
                    dicBones.TryGetValue(slots[i].bone, out boneTemp);
                    if (boneTemp != null)
                    {
                        boneTemp.index = slots[i].index;
                    }
                }
            }
            #endregion

            #region skin
            Dictionary <string, object> skins = raw.skins;
            foreach (KeyValuePair <string, object> pair1 in skins)
            {
                Dictionary <string, object> temp1 = (Dictionary <string, object>)pair1.Value;
                int count = 0;
                foreach (KeyValuePair <string, object> pair2 in temp1)
                {
                    string        slotsName = pair2.Key;
                    SlotElelement slot      = null;
                    dicSlots.TryGetValue(slotsName, out slot);


                    Dictionary <string, object> temp2 = (Dictionary <string, object>)pair2.Value;
                    foreach (KeyValuePair <string, object> pair3 in temp2)
                    {
                        int depth = -count;
                        //Debug.LogError(pair3.Key);
                        string attachmentName = pair3.Key;
                        int    index          = attachmentName.LastIndexOf("/");
                        attachmentName = attachmentName.Substring(index + 1, attachmentName.Length - index - 1);
                        float x = 0;
                        float y = 0;

                        RawAEPJsonAttachment rawPivot = Pathfinding.Serialization.JsonFx.JsonReader.Deserialize(
                            Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(pair3.Value), typeof(RawAEPJsonAttachment)) as RawAEPJsonAttachment;
                        x = (rawPivot.width / 2 - rawPivot.x) / rawPivot.width;
                        y = (rawPivot.height / 2 - rawPivot.y) / rawPivot.height;
                        if (slot != null)
                        {
                            depth = -slot.index;
                        }
                        if (string.IsNullOrEmpty(rawPivot.name))
                        {
                            rawPivot.name = attachmentName;
                        }
                        //Debug.LogError(Pathfinding.Serialization.JsonFx.JsonWriter.Serialize(rawPivot));
                        EAPInfoAttachment pivot = new EAPInfoAttachment(attachmentName, slotsName, depth, x, y, rawPivot.x, rawPivot.y);

                        count++;
                        //Debug.LogError(pivot.name);
                        pivot.spriteName           = pivot.spriteName.Trim();
                        dicPivot[pivot.spriteName] = pivot;
                        if (slot != null && !slot.listAcceptAttachment.Contains(pivot.spriteName))
                        {
                            slot.listAcceptAttachment.Add(pivot.spriteName);
                            slot.listAcceptObj.Add(pivot);
                        }
                    }
                }
            }
            #endregion
        }