Ejemplo n.º 1
0
    public SkeletonData LoadSkeletonBinary(byte[] binaryTemp)
    {
        SkeletonData skeletonData = new SkeletonData();

        skeletonData.name = null;

        m_temp = binaryTemp;

        //Version
        ReadString();
        //Hash
        ReadString();
        //Width
        ReadFloat();
        //Height
        ReadFloat();
        //Nonessential
        m_nonessential = ReadBoolean();

        //BoneNum
        int boneNum = ReadInt();

        for (int i = 0; i < boneNum; i++)
        {
            //Bone
            string   name   = ReadString();
            BoneData parent = null;
            //index
            int parentIndex = ReadInt() - 1;
            if (parentIndex != -1)
            {
                parent = skeletonData.bones[parentIndex];
            }

            BoneData boneData = new BoneData(name, parent);
            //X
            boneData.x = ReadFloat();
            //Y
            boneData.y = ReadFloat();
            //scaleX
            boneData.ScaleX = ReadFloat();
            //scaleY
            boneData.ScaleY = ReadFloat();
            //rotation
            boneData.Rotation = ReadFloat();
            //length
            boneData.Length = ReadFloat();
            //inheritScale
            boneData.InheritScale = ReadBoolean();
            //inheritRotation
            boneData.InheritRotation = ReadBoolean();
            //Color
            if (m_nonessential)
            {
                ReadColor();
            }
            skeletonData.AddBone(boneData);
        }

        //SlotsNum
        int slotsNum = ReadInt();

        for (int i = 0; i < slotsNum; i++)
        {
            string   slotName  = ReadString();
            int      boneIndex = ReadInt();
            BoneData boneData  = skeletonData.bones[boneIndex];
            SlotData slotData  = new SlotData(slotName, boneData);

            Color color = ReadColor();                //Color
            slotData.R = color.r;
            slotData.G = color.g;
            slotData.B = color.b;
            slotData.A = color.a;

            slotData.AttachmentName   = ReadString();
            slotData.AdditiveBlending = ReadBoolean();

            skeletonData.AddSlot(slotData);
        }

        //Default skin
        Skin defaultSkin = readSkin("default", m_nonessential);

        if (defaultSkin != null)
        {
            skeletonData.defaultSkin = defaultSkin;
            skeletonData.AddSkin(defaultSkin);
        }

        //Skin
        for (int i = 0, n = ReadInt(); i < n; i++)
        {
            skeletonData.AddSkin(readSkin(ReadString(), m_nonessential));
        }

        //Events
        for (int i = 0, n = ReadInt(); i < n; i++)
        {
            EventData eventData = new EventData(ReadString());
            eventData.Int    = ReadInt(false);
            eventData.Float  = ReadFloat();
            eventData.String = ReadString();
            skeletonData.AddEvent(eventData);
        }

        //Animations
        for (int i = 0, n = ReadInt(); i < n; i++)
        {
            readAnimation(ReadString(), skeletonData);
        }

        skeletonData.bones.TrimExcess();
        skeletonData.slots.TrimExcess();
        skeletonData.skins.TrimExcess();
        skeletonData.animations.TrimExcess();
        return(skeletonData);
    }